读书人

vc代码转为delphi代码.解决办法

发布时间: 2012-02-20 21:18:23 作者: rapoo

vc代码转为delphi代码.

以下是一个vc的一个数组声明和函数的调用,在delphi如何写?

unsigned int Para[3]={0x01FF,0x0a,0x1}; //共12个字节
其中Parameter[0] 0x01FF为固定的命令字节

1. BOOL Device_Write_CPP(PVOID,DWORD)


if (!Device_Write_CPP(Para,12))
{
AfxMessageBox( "失败 ", "Write fail! ");
return false;
}


2. BOOL Device_Read_CPP(PVOID,DWORD)

if( !Device_Read_CPP(dataValue,4096) // dataValue为 unsigned short int类型的数组,不能为unsigned int类型
{
AfxMessageBox( "失败 ", "Read fail! ");
return false;
}

QQ:313527609

[解决办法]
type
TBuffer=array [0..11] of cardinal;
TReadBuffer=array [0..4096] of word;//word <==> unsigned short int

var
buff:pBuffer;
ReadBuff:TReadBuffer;

//接口函数的引入
function Device_Write_CPP(var pBuff:TBuffer,dwBufferLen:Cardinal):boolean;stdcall; external 'YourImportDllName.dll ';
function Device_Read_CPP(var pBuff:TReadBuffer,dwBufferLen:Cardinal):boolean;stdcall; external 'YourImportDllName.dll ';

1.
if not Device_Write_CPP(buff,12) then//delphi中,传数组名就相当天传数组指针。
begin
application.MessageBox( '失败 ', 'Write fail! ',$10);

end;

2.

if not Device_Read_CPP(ReadBuff,4096) then
begin
application.MessageBox( '失败 ', 'Read fail! ',$10);

end;

读书人网 >.NET

热点推荐