C
coolnerd
Unregistered / Unconfirmed
GUEST, unregistred user!
一个c++做的someName.dll中,有一个函数原型如下:
int GetRealData(int type, PRealData pRD, int num);
其中,第二个参数PRealData定义如下:
typedef struct tagRealData {
BYTE ID1;
BYTE ID2;
USHORT ID3;
union {
float YCValue
int YXValue;
double DDValue;
char unuse[8]
};
} RealData, *PRealData;
该函数的作用是通过传入3个ID(ID1,ID2,ID3),将需要的结果放在上述的联合体中,具体到我的实际中,只会用到YCValue.
我在Delphi中是调用过程如下,但不能取到正确的结果.请帮我诊断一下,谢谢!
unit Unit1;
interface
uses
...;
type
TYCData = packed record
ID1 : Byte;
ID2 : Byte;
ID3 : Word;
case Integer of
0YCValue : Single);
1YXValue : Integer);
2DDValue : Real);
3unuse : array[0..7] of char);
end;
type
TFrmMain = class(TForm)
...
private
procedure Button1Click(Sender: TObject);
public
{ Public declarations }
end;
var
FrmMain: TFrmMain;
function GetRealData(typeid:Integer;pRD:TYCData;num:Integer):Integer
Stdcall
external 'someName.dll';
implementation
{$R *.dfm}
procedure TFrmMain.Button1Click(Sender: TObject);
var
thisID1,thisID2:Byte;
thisID3:Integer;
t_Data:TYCData;
returnInt:Integer;
begin
thisID1:=1;
thisID2:=1;
thisID3:=1;
FillChar(t_Data, Sizeof(t_Data), 0);
try
t_Data.ID1 :=thisID1;
t_Data.ID2 :=thisID1;
t_Data.ID3 :=thisID1;
returnInt:=GetRealData(0,t_Data,1)
//前后两个参数是常量,没有问题
showmessage(format('%f',[t_Data.YCValue]))
//为什么不能返还正确的值?
except
on E: Exception do
showmessage('调用出错:'+E.Message);
end;
end;
...
end.
int GetRealData(int type, PRealData pRD, int num);
其中,第二个参数PRealData定义如下:
typedef struct tagRealData {
BYTE ID1;
BYTE ID2;
USHORT ID3;
union {
float YCValue
int YXValue;
double DDValue;
char unuse[8]
};
} RealData, *PRealData;
该函数的作用是通过传入3个ID(ID1,ID2,ID3),将需要的结果放在上述的联合体中,具体到我的实际中,只会用到YCValue.
我在Delphi中是调用过程如下,但不能取到正确的结果.请帮我诊断一下,谢谢!
unit Unit1;
interface
uses
...;
type
TYCData = packed record
ID1 : Byte;
ID2 : Byte;
ID3 : Word;
case Integer of
0YCValue : Single);
1YXValue : Integer);
2DDValue : Real);
3unuse : array[0..7] of char);
end;
type
TFrmMain = class(TForm)
...
private
procedure Button1Click(Sender: TObject);
public
{ Public declarations }
end;
var
FrmMain: TFrmMain;
function GetRealData(typeid:Integer;pRD:TYCData;num:Integer):Integer
Stdcall
external 'someName.dll';
implementation
{$R *.dfm}
procedure TFrmMain.Button1Click(Sender: TObject);
var
thisID1,thisID2:Byte;
thisID3:Integer;
t_Data:TYCData;
returnInt:Integer;
begin
thisID1:=1;
thisID2:=1;
thisID3:=1;
FillChar(t_Data, Sizeof(t_Data), 0);
try
t_Data.ID1 :=thisID1;
t_Data.ID2 :=thisID1;
t_Data.ID3 :=thisID1;
returnInt:=GetRealData(0,t_Data,1)
//前后两个参数是常量,没有问题
showmessage(format('%f',[t_Data.YCValue]))
//为什么不能返还正确的值?
except
on E: Exception do
showmessage('调用出错:'+E.Message);
end;
end;
...
end.