只要能解决问题,要多少分说就是了!我是这样实现dll(Regular MFC DLL)文件和调用文件的:
下面片断导出函数:...
//=========定义 _declspec(dllexport) 的宏名称==========
#ifdef _WINDLL
#define DLLEXT _declspec(dllexport) //加extern "C"就不行,为什么?
#else
#define DLLEXT
#endif
//=====================================================...class CDBMgrApp : public CWinApp
{
public:
CDBMgrApp();
...
public:
DLLEXT void NewDBConn(CString mdbPath);//此处导出函数
DLLEXT _RecordsetPtr GetRecordsetPtr();
DLLEXT _ConnectionPtr GetConnectionPtr();
...};在这里使用导出的函数:先定义:
typedef int ( __stdcall * pFunc)();
...然后:HINSTANCE hDllFunc ;
hDllFunc = LoadLibrary("DBMgr.dll") ;
if(hDllFunc != NULL)
{
pFunc p=(pFunc)::GetProcAddress(hDllFunc,"fnDBMgr");
FreeLibrary(hDllFunc) ;
}调试时,
前面一切正常,好像也能LoadLibrary,指针地址为0X10000000 然而到了下面
pFunc p=(pFunc)::GetProcAddress(hDllFunc,"fnDBMgr");返回的指针为NULL,好像没有能取得导出函数地址,真是郁闷,哪位高手知道原因呢?
请不吝赐教,只要有利于解决问题,坚决给分!!!
下面片断导出函数:...
//=========定义 _declspec(dllexport) 的宏名称==========
#ifdef _WINDLL
#define DLLEXT _declspec(dllexport) //加extern "C"就不行,为什么?
#else
#define DLLEXT
#endif
//=====================================================...class CDBMgrApp : public CWinApp
{
public:
CDBMgrApp();
...
public:
DLLEXT void NewDBConn(CString mdbPath);//此处导出函数
DLLEXT _RecordsetPtr GetRecordsetPtr();
DLLEXT _ConnectionPtr GetConnectionPtr();
...};在这里使用导出的函数:先定义:
typedef int ( __stdcall * pFunc)();
...然后:HINSTANCE hDllFunc ;
hDllFunc = LoadLibrary("DBMgr.dll") ;
if(hDllFunc != NULL)
{
pFunc p=(pFunc)::GetProcAddress(hDllFunc,"fnDBMgr");
FreeLibrary(hDllFunc) ;
}调试时,
前面一切正常,好像也能LoadLibrary,指针地址为0X10000000 然而到了下面
pFunc p=(pFunc)::GetProcAddress(hDllFunc,"fnDBMgr");返回的指针为NULL,好像没有能取得导出函数地址,真是郁闷,哪位高手知道原因呢?
请不吝赐教,只要有利于解决问题,坚决给分!!!
sample:
#include <stdio.h>
#include <windows.h>
typedef VOID (*MYPROC)(LPTSTR);
VOID main(VOID)
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary("myputs");
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts");
// If the function address is valid, call the function.
if (fRunTimeLinkSuccess = (ProcAdd != NULL))
(ProcAdd) ("message via DLL function\n");
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("message via alternative method\n");
}
typedef int ( __stdcall * pFunc)();这两个应该怎么写呢?
对于dll导出的类型,应该是类和单独的函数。如果单独的导出某个类结构中的函数,似乎是导不出的。如果对单独的函数进行导出,那么可以使用def文件来避免C++的导出函数的命名,而按照标准C的命名规范去导出。