我在我的程序中获取当前系统所有的窗口的所属模块的名称:
void CTestWndsDlg::OnGetwnd() 
{
m_listCtrl.DeleteAllItems();
::EnumWindows(EnumProc, (LPARAM)&m_listCtrl);}BOOL CALLBACK CTestWndsDlg::EnumProc(HWND hwnd, LPARAM lpMsg)
{
....
TCHAR ModuleName[255];
::GetWindowModuleFileName(m_hwnd, ModuleName,255 );
....
}
编译出现错误:
E:\relative\TestWnds\TestWndsDlg.cpp(198) : error C2039: 'GetWindowModuleFileName' : is not a member of '`global namespace''
E:\relative\TestWnds\TestWndsDlg.cpp(198) : error C2065: 'GetWindowModuleFileName' : undeclared identifier
一看msdn知道GetWindowModuleFileName运行需要
Function InformationHeader Declared in Winuser.h, include Windows.h 
Import library User32.lib 
Minimum operating systems Windows 95, Windows NT 4.0 SP3 
Unicode Implemented as Unicode and ANSI versions on Windows NT, Windows 2000, Windows XP 
应该是没有问题啊!难道是winuser.h被我改了,一看文件修改时间并没有!
没办法include<winuser.h>还是说未定义。
再看一下GetWindowModuleFileName的定义:
WINUSERAPI UINT WINAPI
GetWindowModuleFileNameA(
    HWND   hwnd,
    LPSTR pszFileName,
    UINT   cchFileNameMax);
WINUSERAPI UINT WINAPI
GetWindowModuleFileNameW(
    HWND   hwnd,
    LPWSTR pszFileName,
    UINT   cchFileNameMax);
#ifdef UNICODE
#define GetWindowModuleFileName  GetWindowModuleFileNameW
#else
#define GetWindowModuleFileName  GetWindowModuleFileNameA
#endif // !UNICODE
将他拷贝到我的工程中,这次编译没错,链接出错了:
Linking...
TestWndsDlg.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) unsigned int __stdcall GetWindowModuleFileNameA(struct HWND__ *,char *,unsigned int)" (__imp_?GetWindowModuleFileNameA@@YGIPAUHWND__@@PADI@Z)
Debug/TestWnds.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
TestWnds.exe - 2 error(s), 0 warning(s)
费解!!!
附:我在不同的vc6。0,2000/98上测试过!