delphi7环境下,动态库的静态声明与动态声明及调用问题,请大家帮忙救急!
SZSGL 2010-07-15 01:19:50 我在delphi 7 环境下,使用天敏VC4000的监控卡进行图片抓拍的应用。
动态库的名称为:Sa7134Capture.dll!
待调用的函数名为:VCAGetVidCapSize;
问题描述:
1、在delphi中采用动态声明方式:
在文件:VC4000Fun.pas中声明
type
TVCAGetVidCapSize=function (ACard: longword; var AWidth, AHeight: longword): longbool; stdcall;
var
VCAGetvidCapSize : TVCAGetvidCapSize;
在文件:main.pas中load动态库
MVDVRHandle := LoadLibrary('Sa7134Capture.dll');
try
if MVDVRHandle <> 0 then
begin
@VCAGetvidCapSize := GetProcAddress(MVDVRHandle,'VCAGetvidCapSize');
end;
except
end;
在main.pas中调用:
procedure Tfrm_main.MyMessage(var MyMsg: TMessage);
var
nWidth : LongWord;
nHeight : LongWord;
MyVal:integer;
yuv2, rgb4: PChar;
i: longword;
pBuf : PByte;
begin
MyVal:=MyMsg.WParam;
nWidth := 0;
nHeight := 0;
VCAGetvidCapSize(MyVal,nWidth,nHeight);
yuv2 := AllocMem(nWidth * nHeight * 2 * 2);
rgb4 := AllocMem(nWidth * nHeight * 4 * 2);
pBuf := pbufSnapPic[MyVal];
for i := 0 to nHeight - 1 do
begin
Move(pBuf^, yuv2[(nHeight - i - 1) * nWidth * 2 * 2],nWidth * 2);
Move(pBuf^, yuv2[(nHeight - i - 1) * nWidth * 2 * 2 + nWidth * 2],nWidth * 2);
Inc(pBuf,nWidth * 2);
end;
if CaptureFileAsJpeg(PChar(m_ImagePath[MyVal]),yuv2,rgb4,nWidth,nHeight * 2,100) = 0 then
begin
raise Exception.Create('CaptureFileAsJpeg Error!');
end
else
TImage(FindComponent('image'+inttostr(MyVal+1))).Picture.LoadFromFile(m_ImagePath[MyVal]);
FreeMem(yuv2,nWidth * nHeight * 2 * 2);
FreeMem(rgb4,nWidth * nHeight * 4 * 2);
SnapPicture[MyVal] := false;
VCAStopVideoCapture(MyVal);
end;
在运行到:VCAGetvidCapSize(MyVal,nWidth,nHeight)时,不能取回nWidth,nHeight这两个值。
2、如果采用静态声明,如下:
function VCAGetVidCapSize(ACard: longword; var AWidth, AHeight: longword): longbool; stdcall; external 'Sa7134Capture.dll';
再调用的时候,能取回nWidth,nHeight这两个值。
为什么动态申明时,函数不能正常工作?我的申明错在哪?