问题:
手头有一个 delphi 编写的 dll, 由于项目协作关系, 需要为使用 vc 的客户提供一个 头文件和导入库文件.
dll 中导出函数的调用约定为 stdcall.一句话概述:
对于一个使用 stdcall 调用约定的 dll, 在没有源码的情况下, 如何生成供 VC 使用头文件和导入库文件,
使得 linker 和 loader 都爽.详细陈述:
1.
导出函数(使用 dumpbin /exports): Section contains the following exports for DllForEncDec.dll 00000000 characteristics
0 time date stamp Thu Jan 01 08:00:00 1970
0.00 version
1 ordinal base
3 number of functions
3 number of names ordinal hint RVA name 1 0 00035510 _DecryptStr
2 1 000354AC _EncryptStr
3 2 00035448 _MD5Base64Hash 只提供此函数
2.
我写的头文件:#ifndef DLLFORENCDEC_H
#define DLLFORENCDEC_H#ifdef __cplusplus
extern "C"
{
#endif
LPTSTR __stdcall _MD5Base64Hash(LPTSTR lptstrPassword);#ifdef __cplusplus
}
#endif#endif //
3.
def 文件:
[code=BatchFile]
LIBRARY dllforencdecEXPORTS
_MD5Base64Hash@4=_MD5Base64Hash[/code]
使用 lib 命令用这个 def 文件生成导入库.
注: _MD5Base64Hash@4 这个名称是编译试错法得来.4.
客户调用示例: CString sPass = "1234";
LPTSTR encrypted = _MD5Base64Hash(sPass.GetBuffer(sPass.GetLength()));
AfxMessageBox(encrypted);
sPass.ReleaseBuffer();
这样可以满足 linker 的要求, 可以连接成功.
但是在运行时, 提示在 dll 中找不到 _MD5Base64Hash@4 入口.一时想不出办法, 特求助大家.
手头有一个 delphi 编写的 dll, 由于项目协作关系, 需要为使用 vc 的客户提供一个 头文件和导入库文件.
dll 中导出函数的调用约定为 stdcall.一句话概述:
对于一个使用 stdcall 调用约定的 dll, 在没有源码的情况下, 如何生成供 VC 使用头文件和导入库文件,
使得 linker 和 loader 都爽.详细陈述:
1.
导出函数(使用 dumpbin /exports): Section contains the following exports for DllForEncDec.dll 00000000 characteristics
0 time date stamp Thu Jan 01 08:00:00 1970
0.00 version
1 ordinal base
3 number of functions
3 number of names ordinal hint RVA name 1 0 00035510 _DecryptStr
2 1 000354AC _EncryptStr
3 2 00035448 _MD5Base64Hash 只提供此函数
2.
我写的头文件:#ifndef DLLFORENCDEC_H
#define DLLFORENCDEC_H#ifdef __cplusplus
extern "C"
{
#endif
LPTSTR __stdcall _MD5Base64Hash(LPTSTR lptstrPassword);#ifdef __cplusplus
}
#endif#endif //
3.
def 文件:
[code=BatchFile]
LIBRARY dllforencdecEXPORTS
_MD5Base64Hash@4=_MD5Base64Hash[/code]
使用 lib 命令用这个 def 文件生成导入库.
注: _MD5Base64Hash@4 这个名称是编译试错法得来.4.
客户调用示例: CString sPass = "1234";
LPTSTR encrypted = _MD5Base64Hash(sPass.GetBuffer(sPass.GetLength()));
AfxMessageBox(encrypted);
sPass.ReleaseBuffer();
这样可以满足 linker 的要求, 可以连接成功.
但是在运行时, 提示在 dll 中找不到 _MD5Base64Hash@4 入口.一时想不出办法, 特求助大家.
对于一个使用 stdcall 调用约定的 dll, 在没有源码的情况下, 如何生成供 VC 使用头文件和导入库文件,
使得 linker 和 loader 都爽.
一句话:不可能因为拿不到函数的参数信息
参数和返回值都知道, 都是 LPTSTR. 谢谢
LPTSTR MD5Base64Hash(LPCTSTR lpsz)
{
LPTSTR (__stdcall* pfunc)(LPCTSTR) = (LPTSTR (__stdcall*)(LPCTSTR))GetProcAddress(Loadbrary("DllForEncDec.dll"), "MD5Base64Hash");return pfunc(lpsz);
}
PROC pFuc = (PROC)GetProcAddress(hIst, MAKEINTRESOURCE(4));根据序号取函数地址