用delphi写了一个dll,其中一个函数参数就是一个结构指针,在delphi中调用正常,可是在vc中如何调用?1、下面是dll中的声明
function fReadDomainList(pdomlist :pukeyDomainList):Integer;stdcall2、这个是delphi程序中调用
function TfrmGroup.fReadFromUkey:Boolean;
var
  pukey :pukeyDomainList;
  i,cnt :Integer;
  s :string;
begin
  Result := False;
  new(pukey);
  fReadDomainList(pukey);
  cnt := pukey^.ItemCnt;
  for i := 0 to cnt -1 do
  begin
    s := IntToStr(pukey^.Item[i].Domainid) +'-'+pukey^.Item[i].Domainname;
    ShowMessage(s);
  end;
  Dispose(pukey);
  Result := True;
end;不只,此函数如何在vc中调用?如何传结构指针?

解决方案 »

  1.   

    反正就是一个指针,不管是delphi还是VC,都是4个字节。你直接传过去就OK了,以前做过。只要注意的就是必须保证VC和Delphi的结构体的内存对齐方式要一样。// 翻译成VC函数原型
    int fReadDomainList(pukeyDomainList pdomlist); stdcall;// 声明函数指针
    typedef int (stdcall pfn_fReadDomainList*)(pukeyDomainList pdomlist);// 调用过程,先声明一个函数指针变量
    pfn_fReadDomainList pfnRead;  // 加载dll, 获取函数地址
      hLib = LoadLibrary("xx.dll");
      pfnRead = GetProcAddress(hLib, "fReadDomainList");  // 调用
      pfnRead(....);
      

  2.   

    注意调用方式:VC默认调用方式为cdecl 你的DLL显式调用方式为stdcall 所以在VC调用此DLL时要显式声明为stdcall
      

  3.   

    谢谢楼上两位,特别是1楼的,实践证明delphi的dll函数中声明为pointer类型兼容性比声明为结构指针要好很多。