小弟计划做一些图形处理的东东,应用使用delphi开发。图形算法用C/C++实现,(速度可以快一些),通过Dll的方式。我想把位图的句柄传给dll中c/c++处理,但一运行就出异常。求各位大哥看看指导一下。delphi部分:(使用的地方)
procedure TForm1.btnloadClick(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
image1.Picture.LoadFromFile(OpenDialog1.FileName);
image1.Refresh;
GetPicWidth(image1.Picture.Bitmap.Canvas.Handle);
end;
end;
(dll使用声明)
interface
uses windows; function GetPicWidth(hPic:HBITMAP):longint;stdcall;
implementation
function GetPicWidth(hPic:HBITMAP):longint;stdcall;far; external 'cdlltest.dll' name 'getPicWidth';
end.c/c++ (dll实现部分)
extern "C"{
_declspec(dllexport) long getPicWidth(HBITMAP hbitmap)
{
BITMAP bm;
GetObject( hbitmap, sizeof( bm ), &bm );
return bm.bmWidth;
}
}多谢了
procedure TForm1.btnloadClick(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
image1.Picture.LoadFromFile(OpenDialog1.FileName);
image1.Refresh;
GetPicWidth(image1.Picture.Bitmap.Canvas.Handle);
end;
end;
(dll使用声明)
interface
uses windows; function GetPicWidth(hPic:HBITMAP):longint;stdcall;
implementation
function GetPicWidth(hPic:HBITMAP):longint;stdcall;far; external 'cdlltest.dll' name 'getPicWidth';
end.c/c++ (dll实现部分)
extern "C"{
_declspec(dllexport) long getPicWidth(HBITMAP hbitmap)
{
BITMAP bm;
GetObject( hbitmap, sizeof( bm ), &bm );
return bm.bmWidth;
}
}多谢了
extern "C"{
_declspec(dllexport) long WINAPI getPicWidth(HBITMAP hbitmap) //这里改一下试试
{
BITMAP bm;
GetObject( hbitmap, sizeof( bm ), &bm );
return bm.bmWidth;
}
}
implementation
function GetPicWidth(hPic:HBITMAP):longint;cdecl;far; external 'cdlltest.dll' name 'getPicWidth';
end.
内容如下:
LIBRARY
EXPORTS
getPicWidth
因为VC的WINAPI缺省会导出_getPicWidth@4,delphi认不到
---------------------------------------------------------
你的主要问题是函数调用不匹配造成的