A
Adnil
Unregistered / Unconfirmed
GUEST, unregistred user!
用VC建立一个动态链接库,只有一个导出函数
头文件如下:
#ifdef CHARSETEXP_EXPORTS
#define CHARSETEXP_API __declspec(dllexport)
#else
#define CHARSETEXP_API __declspec(dllimport)
#endif
// This class is exported from the CharsetExp.dll
/*class CHARSETEXP_API CCharsetExp {
public:
CCharsetExp(void);
// TODO: add your methods here.
};
extern CHARSETEXP_API int nCharsetExp;
*/
CHARSETEXP_API int fnCharsetExp(int a);
cpp如下:
// CharsetExp.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "CharsetExp.h"
BOOL APIENTRY DllMain( HANDLE 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;
}
// This is an example of an exported variable
//CHARSETEXP_API int nCharsetExp=0;
// This is an example of an exported function.
CHARSETEXP_API int fnCharsetExp(int a)
{
return ++a;
}
delphi调用如下:
type
Tc = function(a: integer): integer;
stdcall;
procedure TForm1.Button1Click(Sender: TObject);
var
h: thandle;
a: Tc;
begin
h := loadlibrary('C:/Temp/CharsetExp/Release/CharsetExp.dll');
a := Tc(GetProcAddress(h, 'fnCharsetExp'));
showmessage(inttostr(a(100)));
FreeLibrary(h);
end;
发现无法获取fnCharsetExp函数地址,请教大虾如何解决。
头文件如下:
#ifdef CHARSETEXP_EXPORTS
#define CHARSETEXP_API __declspec(dllexport)
#else
#define CHARSETEXP_API __declspec(dllimport)
#endif
// This class is exported from the CharsetExp.dll
/*class CHARSETEXP_API CCharsetExp {
public:
CCharsetExp(void);
// TODO: add your methods here.
};
extern CHARSETEXP_API int nCharsetExp;
*/
CHARSETEXP_API int fnCharsetExp(int a);
cpp如下:
// CharsetExp.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "CharsetExp.h"
BOOL APIENTRY DllMain( HANDLE 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;
}
// This is an example of an exported variable
//CHARSETEXP_API int nCharsetExp=0;
// This is an example of an exported function.
CHARSETEXP_API int fnCharsetExp(int a)
{
return ++a;
}
delphi调用如下:
type
Tc = function(a: integer): integer;
stdcall;
procedure TForm1.Button1Click(Sender: TObject);
var
h: thandle;
a: Tc;
begin
h := loadlibrary('C:/Temp/CharsetExp/Release/CharsetExp.dll');
a := Tc(GetProcAddress(h, 'fnCharsetExp'));
showmessage(inttostr(a(100)));
FreeLibrary(h);
end;
发现无法获取fnCharsetExp函数地址,请教大虾如何解决。