我试图获取某些 C++ 代码中模块的版本信息(基本上是 this ),但遇到编译时错误。代码如下:
WCHAR fileName[MAX_PATH];
HMODULE module = GetModuleHandle(L"some-module");
DWORD size = GetModuleFileName(module, fileName, MAX_PATH);
编译器正在返回:
error C2664: 'GetModuleFileNameW' : cannot convert parameter 1 from 'WHANDLE' to 'HMODULE' Conversion from 'void*' to pointer to non-'void' requires an explicit cast
这是怎么回事? GetModuleHandle
返回 HMODULE
,这是 GetModuleFileName
记录的第一个参数。
以下是其值(value)的编译器版本:
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved.
谢谢!
最佳答案
您的包含或库一定发生了一些奇怪的事情,因为它在这里编译和运行良好:
// Scratch.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "windows.h"
int _tmain(int argc, _TCHAR* argv[])
{
WCHAR fileName[MAX_PATH];
HMODULE module = GetModuleHandle(L"some-module");
DWORD size = GetModuleFileName(module, fileName, MAX_PATH);
return 0;
}
关于c++ - GetModuleFileNameW 的转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7897677/