求助:C语言代码转为DELPHI代码(200分)

  • 主题发起人 JackyKen
  • 开始时间
J

JackyKen

Unregistered / Unconfirmed
GUEST, unregistred user!
C语言代码段如下:
int w,h;
unsigned char *bitsBuffer = (unsigned char *)malloc(128 * 128 * 2);
if(bitsBuffer == NULL)
return;
if (LoadYUVFromBmpFile("logo.bmp", bitsBuffer, 128 * 128 * 2, &w, &h))
{
AfxMessageBox("logo.bmp not exsit!/n");
return;
}
for( i = 0;
i < GetTotalDSPs();
i++){
SetLogo(ChannelHandle, 0, 0, w, h, (UCHAR *)bitsBuffer);
}
free(bitsBuffer);
把上面这段代码转为DELPHI代码,我转过来怎么运行错误,请各位帮帮忙,谢谢
其中用到的几个函数声明如下(从DLL中引出的):
C语言中:
int SetLogo(HANDLE hChannelHandle, int x, int y, int w, int h, unsigned char *yuv);
int LoadYUVFromBmpFile(char *FileName, unsigned char *yuv, int BufLen, int *Width, int *Height);
DELPHI中:
function SetLogo( hChannelHandle : HANDLE ;
x : integer ;
y : integer ;
w : integer ;
h : integer ;
yuv : PUCHAR) : integer;
function LoadYUVFromBmpFile( FileName : pchar ;
yuv : PUCHAR ;
BufLen : integer ;
Width : PINT ;
Height : PINT) : integer;
 
var
h, w: Integer;
i: Integer;
bitsBuffer: PUCHAR;
begin
h := 0;
w := 0;
bitsBuffer := AllocMem(128 * 128 * 2);
if bitsBuffer = nil then
Exit;
try
if LoadYUVFromBmpFile('logo.bmp', bitsBuffer, 128 * 128 * 2, @h, @w) = 0 then
begin
MessageBox(0, 'logo.bmp not exsit', '警告', MB_OK);
Exit;
end;
for i := 0 to GetTotalDSPs() - 1do
SetLogo(ChannelHandle, 0, 0, w, h, bitsBuffer);
finally
FreeMem(bitsBuffer);
end;
end;
 
function SetLogo( hChannelHandle : HANDLE ;
x : integer ;
y : integer ;
w : integer ;
h : integer ;
yuv : PUCHAR) : integer;
===>
function SetLogo( hChannelHandle : THANDLE ;
x : integer ;
y : integer ;
w : integer ;
h : integer ;
yuv : PUCHAR) : integer;
 
我自己转换的代码如下,运行到LoadYUVFromBmpFile这句时出错,写内存错误
var
FileName:string;
w,h:pINT;
ABuffer:pUChar;
begin
GetMem(ABuffer,128*32*2);
if ABuffer=nil then
Exit;
FileName:='D:/logo.bmp';
if LoadYUVFromBmpFile(PChar(FileName),ABuffer, 128 * 32 * 2,w,h)<>0 then
begin
ShowMessage('载入BMP错误');
Exit;
end;
SetLogo(DisCamera[ChannelNo].ChannelHandle,0,0,w^,h^,ABuffer);
FreeMem(ABuffer);
end;
 
谢谢放飞答复,我先试一下
 
谢谢放飞兄,完全没问题
再次感谢!
结贴给分.
 
你可以检查一下函数参数的传递方式,是stdcall还是pascal
默认情况下,c使用的是stdcall方式
 

Similar threads

I
回复
0
查看
745
import
I
I
回复
0
查看
883
import
I
I
回复
0
查看
514
import
I
顶部