C++ 调用 delphi dll
2018-03-07 18:03
489 查看
说明:
delphi 导出请加stdcall
---------------------- Delphi --------------------------library DepDll;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes;
//加法测试
Function TestAdd(p1, p2 : Integer):Integer;stdcall;
begin
Result:=p1+p2;
end;
//字符串输入与输出测试
Function ShowString(s1, s2:PChar; pOut:PChar):Integer;stdcall;
var
strRes:String;
begin
strRes:='this is from delphi s1:'+ StrPas(s1) + ' s2:' + StrPas(s2);
Move(strRes[1], pOut^, Length(strRes));
end;
{$R *.res}
//函数导出
exports
TestAdd,ShowString;
begin
end.
---------------------- C++ ----------------------CString strPath = _T("D:\\Program Files (x86)\\Borland\\Delphi7\\Projects\\DepDll.dll");
HINSTANCE hUKey = LoadLibrary(strPath);
if (hUKey != NULL){
//参数为整型的加法测试
{
int nRes;
typedef int(__stdcall *TADD)(int, int);
TADD pAdd = (TADD)GetProcAddress(hUKey, "TestAdd");
if (pAdd != 0){
nRes = pAdd(100, 123);
}
}
//参数为字符串的字符串测试
{
int nRes;
typedef int(__stdcall *SHOWSTR)(char*, char*, char*);
SHOWSTR pShowStr = (SHOWSTR)GetProcAddress(hUKey, "ShowString");
char* pBuf = new char[512];
memset(pBuf, 0, 512);
if (pShowStr != 0){
nRes = pShowStr("2018 delphi", "param 2", pBuf);
}
delete[] pBuf;
}
FreeLibrary(hUKey);
}
delphi 导出请加stdcall
---------------------- Delphi --------------------------library DepDll;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes;
//加法测试
Function TestAdd(p1, p2 : Integer):Integer;stdcall;
begin
Result:=p1+p2;
end;
//字符串输入与输出测试
Function ShowString(s1, s2:PChar; pOut:PChar):Integer;stdcall;
var
strRes:String;
begin
strRes:='this is from delphi s1:'+ StrPas(s1) + ' s2:' + StrPas(s2);
Move(strRes[1], pOut^, Length(strRes));
end;
{$R *.res}
//函数导出
exports
TestAdd,ShowString;
begin
end.
---------------------- C++ ----------------------CString strPath = _T("D:\\Program Files (x86)\\Borland\\Delphi7\\Projects\\DepDll.dll");
HINSTANCE hUKey = LoadLibrary(strPath);
if (hUKey != NULL){
//参数为整型的加法测试
{
int nRes;
typedef int(__stdcall *TADD)(int, int);
TADD pAdd = (TADD)GetProcAddress(hUKey, "TestAdd");
if (pAdd != 0){
nRes = pAdd(100, 123);
}
}
//参数为字符串的字符串测试
{
int nRes;
typedef int(__stdcall *SHOWSTR)(char*, char*, char*);
SHOWSTR pShowStr = (SHOWSTR)GetProcAddress(hUKey, "ShowString");
char* pBuf = new char[512];
memset(pBuf, 0, 512);
if (pShowStr != 0){
nRes = pShowStr("2018 delphi", "param 2", pBuf);
}
delete[] pBuf;
}
FreeLibrary(hUKey);
}
相关文章推荐
- 使用Delphi调用C++编写的DLL
- C/C++调用Delphi制作的dll时发现的一些问题
- Java Native Interface(Java 调用Delphi、C、C++编写的DLL)
- Delphi调用C++编写的动态链接库dll的方法
- Delphi如何调用C++写的DLL
- Delphi如何调用C++写的DLL
- Delphi动态调用C++写的DLL
- Java调用Delphi DLL(通过C++调用和直接调用两种方式)
- Delphi 调用C/C++的DLL
- Silverlight实用窍门系列:22.Silverlight使用WebService调用C++,Delphi编写的DLL文件【实例源码下载】
- 在Delphi中动态调用C++的DLL
- 22.Silverlight使用WebService调用C++,Delphi编写的DLL文件
- Delphi中C++的DLL的调用
- 在Delphi中动态调用C++的DLL
- c++写dll文件,用delphi stdcall调用报地址000001错误,
- Delphi 调用C/C++的Dll
- 调用外部DLL,如:DelphiC++Java的DLL的调用方法,给出代码片段?
- Delphi如何调用C++写的DLL
- Delphi 调用C/C++的Dll(stdcall关键字, 会导致函数名分裂. 此时函数名变成_stdadd@8)
- C/C++调用Delphi制作的dll时发现的一些问题