gpt4 book ai didi

c++ - 如何获取 DLL 的版本?

转载 作者:搜寻专家 更新时间:2023-10-31 01:51:45 24 4
gpt4 key购买 nike

我正在从 system32 (shell32.dll) 打开一个 DLL我想收到它的版本。我该怎么做?我开始写它,但不知道如何继续:

我还看到有像 GetFileVersionSize 这样的函数,有没有办法使用它们?

这是代码,如果有人可以帮助我继续它并提供线索,我会很感激

谢谢!

#define PATH    "C:\\Users\\rachel\\Desktop\\shell32.dll"

PVERSION dll_getVersion(PCHAR pDllPath)
{
PVERSION version = NULL;
HINSTANCE dllLoad = NULL;
HRSRC resourceHandle = NULL;
HGLOBAL loadResourceHandle = NULL;
LPVOID lockResourceHande = NULL;
DWORD sizeOfResource = 0;

//LPCTSTR lptstrFilename = NULL;
//DWORD dfHandle = 0;
//DWORD dwLen = 0;
//LPVOID lpData = NULL;
//BOOL test = FALSE;

//DWORD fileVersionSize = 0;
//unsigned long u = 0;
//fileVersionSize = GetFileVersionInfoSize(PATH , &u);

//test = GetFileVersionInfo(PATH, dfHandle , dwLen ,lpData);



if (NULL == pDllPath)
{
printf("error #1 : dllPath is invalid \n");
return version;
}

version = (PVERSION)calloc(1,sizeof(VERSION));
if (NULL == version)
{
printf("the allocation failed \n");
return version;
}

//opening the dll using the path */
dllLoad = LoadLibrary(pDllPath);
if (NULL == dllLoad)
{
printf("failed to load the dll ! \n");
printf("the last error is : %d\n" , GetLastError());
free(version);
version = NULL;
return version;
}

resourceHandle = FindResource(dllLoad ,MAKEINTRESOURCE(16) , RT_VERSION);
if (NULL == resourceHandle)
{
printf("problem with find resource!!!! \n");
return NULL;
}
loadResourceHandle = LoadResource(dllLoad , resourceHandle);

if (NULL == loadResourceHandle)
{
printf("problem with load resource function! \n");
return NULL;
}

lockResourceHande = LockResource(loadResourceHandle);
if (NULL == lockResourceHande)
{
printf("error in lock resource function \n");
return NULL;
}

sizeOfResource = SizeofResource(dllLoad, resourceHandle);

最佳答案

Here ,给你举个例子,希望对你有帮助。调用 GetFileInfoSize,分配该大小的缓冲区,然后将您分配的缓冲区传递给 GetFileInfo,然后在 VerQueryValue 中使用您传递给 GetFileInfo 的初始化缓冲区。

关于c++ - 如何获取 DLL 的版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13552498/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com