X
xucuiping
Unregistered / Unconfirmed
GUEST, unregistred user!
Delphi调用C++动态库问题,导出函数的参数为结构体。
动态库C++代码:
=========CTest.h==========
=========CTest.cpp==========
在Delphi中使用如下:
==========
哪位大侠指点一下?
动态库C++代码:
=========CTest.h==========
代码:
#ifdef DYNAMICDLL_EXPORTS
#define DLL_API _declspec(dllexport)
#else
#define DLL_API _declspec(dllimport)
#endif
#include <iostream>
#include <string>
struct STXCP
{
int ndevid;
std::string strdevName;
};
extern "C"
{
DLL_API void Test(STXCP &ostxcp);
}
=========CTest.cpp==========
代码:
#include "CTest.h"
void Test(STXCP &ostxcp)
{
ostxcp.ndevid = 10;
ostxcp.strdevName = "ma5600v3";
}
在Delphi中使用如下:
代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
//-----------------------
TXCP = record
ndevid: integer;
strdevName: string;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
procedure Test(var oxcp :TXCP);cdecl;external'E:/Delphi/C_Dll/dll/DynamicDLL.dll' name 'Test';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
oTest : TXCP;
begin
Test(oTest);
showmessage(oTest.strdevName); //运行到这出错
end;
end.
==========
哪位大侠指点一下?