2011-10-26 77 views
1

我想获取一些C++代码(基本上this)模块的版本信息,我得到编译时错误。下面的代码:与GetModuleFileNameW铸造错误

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记录的第一个参数。

这里是什么它的价值编译器的版本:

 
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86 
    Copyright (C) Microsoft Corporation. All rights reserved. 

谢谢!

+0

你确定这是正确的代码和右的错误? 'GetModuleFileName'调用中的'module'显然已经是'HMODULE'类型。 – jamesdlin

回答

4

必须有与包括或你的图书馆去上时髦的东西,因为这编译并运行此罚款:

// 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; 
} 
+0

嗯,这就是我所担心的。你使用的是哪个版本的编译器? –

+0

我正在使用Visual Studio 2010 SP1进行此实验。 –

+0

事实证明,这个问题是由Lotus Notes C-API头文件(global.h)造成的...... gurrr! –