我昭了个例子写的一个动态链接库,为什么会出现这问题,而他的可以编译,???
代码如下:
// dllDemo.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "dllDemo.h"
#include <stdio.h>
HMODULE g_hModule;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
g_hMoudle=(HMODULE)hModule;
break;
}
return TRUE;// 09DllDemo.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "dllDemo.h"
#include <stdio.h>
HMODULE g_hModule;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
g_hModule = (HMODULE)hModule; // 保存模块句柄
break;
}
return TRUE;
}
// 自定义导出函数
void ExportFunc(LPCTSTR pszContent)
{
char sz[MAX_PATH];
::GetModuleFileName(g_hModule, sz, MAX_PATH);
::MessageBox(NULL, pszContent, strrchr(sz, '\\') + 1, MB_OK);
}
}
DLLDEMO_API void ExportFun(LPCTSTR pszContent)
{
char sz[Max_PATH];
GetModuleFileName(g_hMoudle,sz,MAX_PATH);
MessageBox(NULL,pszContent,strrchr(sz,'\\')+1,MB_OK);
}
编译后问题如下:
--------------------Configuration: dllDemo - Win32 Debug--------------------
Compiling...
dllDemo.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(16) : error C2065: 'g_hMoudle' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(16) : error C2440: '=' : cannot convert from 'struct HINSTANCE__ *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\program files\microsoft visual studio\myprojects\dlldemo\dlldemo.h(17) : error C2599: 'CDllDemo::CDllDemo' : local class member functions must be defined within the class
c:\program files\microsoft visual studio\myprojects\dlldemo\dlldemo.h(17) : see declaration of 'CDllDemo::CDllDemo'
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(33) : error C2601: 'DllMain' : local function definitions are illegal
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(45) : error C2601: 'ExportFunc' : local function definitions are illegal
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(59) : error C2065: 'Max_PATH' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(59) : error C2057: expected constant expression
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(59) : error C2466: cannot allocate an array of constant size 0
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(59) : error C2133: 'sz' : unknown size
Error executing cl.exe.
Creating browse info file...
dllDemo.dll - 9 error(s), 0 warning(s)