안녕하세요. 최정원입니다.
소켓통신으로 서버에 연결된 카메라의 이미지를 클라이언트에 송신하는
프로그램을 작성하고 있습니다. 서버에는 CCTV Camera를 Control하는
VC++로 작성된 DLL을 Delphi에서 호출하는데 Kernel에러가 발생합니다.
VC++ Header File에는 다음과 같이 선언되어 있습니다.
// 한화면을 캡쳐
extern int FAR PASCAL EncodeStill(WORD * Stilbuf,int Size,int V_Synk);
// 캡쳐한 이미지를 JPG로 변환
extern long FAR PASCAL StillToJpg(BYTE * Stilbuf, BYTE * JPG, int comp, int res,
long length);
그리고 Delphi프로그램은 다음과 같이 선언하고 코딩하였습니다.
function EncodeStill(Stilbuf:PWord;Buffer_Size,V_Synk:Integer): Integer; stdcall;
external 'CCTVDLL.DLL';
function StillToJPG(Stilbuf,JPG:PByte;comp,res:Integer;length: Longint):
Longint; stdcall; external 'CCTVDLL.DLL';
// Compress,Resolution,JpgSize,OrgJpeg 는 Global변수
procedure TVideoForm.GetScreenCapture;
var
Mem: TMemoryStream;
still_size: longint;
still_buf: ^Word;
jpg_buf: ^Byte;
begin
try
GetMem(still_buf, 100000);
still_size := EncodeStill(PWord(still_buf), 100000-1024, 0);
if still_size <= 0 then exit;
GetMem(jpg_buf, 100000);
FillChar(jpg_buf^, 100000, 0);
JpgSize := StillToJPG(PByte(still_buf),PByte(jpg_buf),
Compress,Resolution,still_size);
if JpgSize<=0 then exit;
Mem := TMemoryStream.Create;
Mem.SetSize(JpgSize);
Mem.WriteBuffer(jpg_buf^, JpgSize);
Mem.Position := 0;
OrgJpeg := GlobalAllocPtr(GHND, Mem.Size);
FillChar(OrgJpeg^, Mem.Size, 0);
FullJpgSize := Mem.Size;
Mem.Readbuffer(OrgJpeg^, FullJpgSize);
finally
if Mem<>nil then
Mem.Free;
if jpg_buf<>nil then
FreeMem(jpg_buf, 100000);
if still_buf<>nil then
FreeMem(still_buf, 100000);
end;
SendImageToClient(OrgJpeg); // 클라이언트로 이미지를 송신
end;
실행하면 몇번 송신하다가 DLL을 호출하는데에서 커널에러가 발생합니다.
델파이에서 선언을 잘못하였는지... 어디가 잘못되었는지 모르겠습니다.
부디 고수님들 위 소스를 보시고 조언 부탁드립니다.
그럼 수고하세요!