// 下列 ifdef 块是创建使从 DLL 导出更简单的
// 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 DBPROXY1_EXPORTS
// 符号编译的。在使用此 DLL 的
// 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
// DBPROXY1_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
// 符号视为是被导出的。
#ifdef DBPROXY1_EXPORTS
#define DBPROXY1_API __declspec(dllexport)
#else
#define DBPROXY1_API __declspec(dllimport)
#endif
// 此类是从 DBProxy1.dll 导出的
class DBPROXY1_API CDBProxy1 {
public:
CDBProxy1(void);
// TODO: 在此添加您的方法。
};
extern DBPROXY1_API int nDBProxy1;
DBPROXY1_API int fnDBProxy1(void);
// DBProxy1.cpp : 定义 DLL 应用程序的入口点。
//
#include "stdafx.h"
#include "DBProxy1.h"
#ifdef _MANAGED
#pragma managed(push, off)
#endif
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#ifdef _MANAGED
#pragma managed(pop)
#endif
// 这是导出变量的一个示例
DBPROXY1_API int nDBProxy1=0;
// 这是导出函数的一个示例。
DBPROXY1_API int fnDBProxy1(void)
{
return 42;
}
// 这是已导出类的构造函数。
// 有关类定义的信息,请参阅 DBProxy1.h
CDBProxy1::CDBProxy1()
{
return;
}
注意:对一个类的导出,要么全部导出,要么一个也导不出。此时可以尝试着把类的成员包装下然后导出。如:
CDBProxy g_DBProxy ;
BOOL WINAPI Init (void)
{
return g_DBProxy.a_Init() ;
}
int WINAPI GetResult (int nType, char* key, char* value)
{
return g_DBProxy.a_GetResult(nType, key, value) ;
}
int WINAPI SetResult (int nType, char* key, char* value)
{
return g_DBProxy.a_SetResult(nType, key, value) ;
}
void WINAPI freemem (char* data)
{
g_DBProxy.a_freemem (data) ;
}