VC++中怎样调用Delphi写的Dll?

victorzheng 2008-12-15 02:38:44
由于delphi操作数据比较方便,故想在VC++中调用delphi写的dll来进行数据处理,dll中数据处理界面是MDI子窗体,Exports出来的接口函数需要传入类TAppliction的实列,但VC++中没有TApplication类,咱办呢?
...全文
107 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fdsloading 2009-03-09
  • 打赏
  • 举报
回复
不知道现在你还需不需要:给你个例子:
Delphi 中的代码:
Unit Common;

Interface

Uses SysUtils, Ora, Windows, DM, Forms,Dialogs;

Function CheckSnExist(pSn: String): Integer; StdCall; export;

Implementation

Function CheckSnExist(pSn: String): Integer;
Var
ChkQry : TOraQuery;
Begin
ChkQry := TOraQuery.Create(Nil);
ChkQry.Session := Data.Orsn;

With ChkQry Do
Begin
Close;
SQL.Clear;
SQL.Add('select count(*) from sfism4.r_wip_tracking_t');
SQL.Add(' where serial_number = :sn');
ParamByName('sn').AsString := pSn;
Open;
Result := Fields[0].AsInteger;
Close;
End;
ChkQry.Free;
End;

Exports
CheckSnExist,


End.



VC中的代码:

typedef int (* pGetData)( char* P1) ;
pGetData GetData;
HINSTANCE hinst;
hinst=LoadLibrary(TEXT("TEST.dll")); //Load dll LPCTSTR strContent);
if(hinst==NULL)
{
AfxMessageBox("load dll Fail");
}
GetData=(pGetData)GetProcAddress(hinst,"CheckSnExist"); //get address of the function
if(GetData==NULL)
{
AfxMessageBox("get the address of the function Fail");
}
else
{
if(GetData("2GE02001")==0) //run the function in the delphi dll
{
AfxMessageBox("the number is not exist");
}
else
{
AfxMessageBox("the number is exist");
}
}
if(hinst!=NULL)
{
FreeLibrary(hinst); // unload hinst
hinst=NULL;
free(GetData);
}
VCRWX 2008-12-15
  • 打赏
  • 举报
回复
delphi采用的是标准调用约定,而C++默认采用C调用约定.如果想在VC++中调用delphi写的dll来进行数据处理,首先要保把调用约定设为相同
路人乙2019 2008-12-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ilovedrv 的回复:]
如果是标准c接口方式,没有问题,但这种导出类的方式,恐怕是不行的

建议把类再封一层,变成c接口方式
[/Quote].
oyljerry 2008-12-15
  • 打赏
  • 举报
回复
最好传递的接口参数用标准数据,TApplication类,在C++中没有对应的
ilovedrv 2008-12-15
  • 打赏
  • 举报
回复
如果是标准c接口方式,没有问题,但这种导出类的方式,恐怕是不行的

建议把类再封一层,变成c接口方式

15,466

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧