读书人

delphi 怎么调用VC写的dll

发布时间: 2012-03-12 12:45:33 作者: rapoo

delphi 如何调用VC写的dll?
VC中的定义:
extern "C " __declspec(dllexport) ConverFont(LPCTSTR pInFile,LPCTSTR pOutFile,DWORD VirtualAddr,LOGFONT* pLogFont,DWORD *pAddr)


我按下面的在delphi中声明,但是传入VC中的参数值是空的或错的。请问要如何声明才是正确的呢?
function ConverFont(pInFile,pOutFile: LPCTSTR; VirtualAddr: DWORD; pLogFont: TLogFont; var pVirturalAddr: integer): Boolean; external 'FontConver.dll ';

[解决办法]
关注
[解决办法]
function CONVERFONT(pInFile :LPCTSTR;var pOutFile: CTSTR;VirtualAddr: LongInt;var pLogFont: LogFont;var pAddr: LongInt) : Boolean;

调用方式根据VC里的形式,用cdecl; 或者stdcall
[解决办法]
在Delphi当中TLogFont是一个指针,而在VC当中也需要传入tagLOGFONT的指针,另外注意tagLOGFONTA (ANSI) 和tagLOGFONTW (Unicode)别传错就OK了。
[解决办法]
function TFont.GetHandle: HFont;
var
LogFont: TLogFont;
begin
with FResource^ do
begin
if Handle = 0 then
begin
FontManager.Lock;
with LogFont do
try
if Handle = 0 then
begin
lfHeight := Font.Height;
lfWidth := 0; { have font mapper choose }
lfEscapement := Font.Orientation;
lfOrientation := Font.Orientation;
if fsBold in Font.Style then
lfWeight := FW_BOLD
else
lfWeight := FW_NORMAL;
lfItalic := Byte(fsItalic in Font.Style);
lfUnderline := Byte(fsUnderline in Font.Style);
lfStrikeOut := Byte(fsStrikeOut in Font.Style);
if (Font.CharSet = DEFAULT_CHARSET) and
(DefFontData.Charset <> DEFAULT_CHARSET) then
lfCharSet := DefFontData.Charset
else
lfCharSet := Byte(Font.Charset);
if AnsiCompareText(Font.Name, 'Default ') = 0 then // do not localize
StrPCopy(lfFaceName, DefFontData.Name)
else
StrPCopy(lfFaceName, Font.Name);
if (Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
(GetDefFontCharset = SHIFTJIS_CHARSET) and IsDefaultFont(Font) then
lfCharSet := SHIFTJIS_CHARSET;
lfQuality := DEFAULT_QUALITY;
{ Everything else as default }
{ Only True Type fonts support the angles }
if lfOrientation <> 0 then
lfOutPrecision := OUT_TT_ONLY_PRECIS
else
lfOutPrecision := OUT_DEFAULT_PRECIS;
lfClipPrecision := CLIP_DEFAULT_PRECIS;
case Pitch of
fpVariable: lfPitchAndFamily := VARIABLE_PITCH;
fpFixed: lfPitchAndFamily := FIXED_PITCH;
else
lfPitchAndFamily := DEFAULT_PITCH;
end;
Handle := CreateFontIndirect(LogFont);
end;
finally
FontManager.Unlock;
end;
end;
Result := Handle;
end;
end;

读书人网 >.NET

热点推荐