Friday, 15 February 2013

Calling C DLL from Delphi program -



Calling C DLL from Delphi program -

in delphi code have phone call dll's function (written in visual c) next prototype:

int pwfunc(lpcstr szname, int nwidth, int nheight, lpcstr szfilename)

ho can convert delphi ansistring variables (for name , filename) right type parameters (lpcstr szname , szfilename) of function phone call ? know vc lpcstr type corresponds delphi pansichar type, right procedure convert ansistring pansichar ?

lpcstr , lpstr correspond pansichar, use:

function pwfunc(szname: pansichar; nwidth, nheight: longint; szfilename: pansichar): longint; cdecl { or stdcall, see documentation }; external 'somedll.dll' name 'pwfunc';

you phone call like:

x := pwfunc(pansichar(ansistring(somename)), 17, 33, pansichar(ansistring(somefilename)));

whether function stdcall or dcecl depends on compiler settings. read documentation. if in doubt, seek both. looks cdecl me, start that.

delphi dll parameters type-conversion

No comments:

Post a Comment