我需要调用C++写的一个DLL如下:
BOOL __stdcall GetCamList(DWORD dwAddr);
dwAddr 为目前系统注册的IPCam数组。数组大小为目前注册的IPCam数目
在C++中的代码如下:
************************************
STRUCTDEVSHOW_* pDevice = new STRUCTDEVSHOW_[lCount];
GetCamList((DWORD)pDevice);其中STRUCTDEVSHOW_定义如下:
struct STRUCTDEVSHOW_ 
{
  char strDevName[128];
  char strDevIP[32];
  char strMAC[32];
};
************************************我在delphi中的定义和声明依次如下:
  TStructDevShow = record
    strDevName:array [1..128] of char;
    strDevIP:array [1..32] of char;
    strMAC:array [1..32] of char;
  end;
  type TStructDevShowS=array of TStructDevShow;
  ……
  ……
  function GetCamList(dwAddr:DWORD):LongBool;stdcall;external 'CreatePlatform.dll';下面是执行这个调用的实现,请大家帮我看看,应该怎么做,才能完成这个函数调用!!!
procedure TForm1.Button3Click(Sender: TObject);
var
  lcount:Integer;
  structDevShowS:TStructDevShowS;
  dwAddr:DWORD;
begin
  lcount:=0;
  GetCamListCount(lcount);
  if (lcount>0) then begin
    setLength(structDevShowS,lcount);
    dwAddr:=Cardinal(@structDevShowS);
    GetCamList(dwAddr);  //执行到这里的时候,出现内存出错!!
    Memo1.Lines.Add(structDevShowS[0].strDevIP);
  end else begin  end;
end;
我对delphi中实现指针方面不是很懂,请大家帮忙看看!

解决方案 »

  1.   

    做过类似的调用。
    试一下PStructDevShow = ^TStructDevShow;
    TStructDevShow = record
        strDevName:array [1..128] of char;
        strDevIP:array [1..32] of char;
        strMAC:array [1..32] of char;
      end; PStructDevShowS = ^TStructDevShowS;
    TStructDevShowS = record
      aStructDevShowS: array[0..0] of TStructDevShow; 
    end;
      

  2.   

    type
      tagStructDevShow = record 
        strDevName:array [1..128] of char; 
        strDevIP:array [1..32] of char; 
        strMAC:array [1..32] of char; 
      end;  //此类型只为逃避编译器对于下标溢出的检查,请勿直接使用
      TStructDevShowArray = array [0..(MaxLongint div sizeof(tagStructDevShow))-1 ] of tagStructDevShow;
      PStructDevShowArray = ^TStructDevShowArray;
    var
      MyData: PStructDevShowArray ;
    begin
      GetMem(MyData,lCount * sizeof(tagStructDevShow));
      GetCamList(LongWord(MyData));
    end;