我在Delphi7中编写有以下代码:procedure TForm1.Button1Click(Sender: TObject);
var
hMod:Thandle;
MyText:function(DC: HDC; X, Y: Integer; Str: PChar; Count: Integer): BOOL; stdcall;
begin
hMod:=LoadLibrary('C:\Windows\System32\GDI32.dll');
try
if hMod<=0 then
MessageBox(0,'装载DLL失败!','提示',MB_OK or MB_ICONERROR)
else
begin
@MyText:=GetProcAddress(hMod,'TextOut');
if (@MyText<>nil) then
MyText(Self.Canvas.Handle,600,300,'HJXLJ',5)
else
MessageBox(0,'取函数地址失败!','提示',MB_OK or MB_ICONERROR);
end;
finally
FreeLibrary(hMod);
end;
end;但在运行时总是显示"取函数地址失败!"。不知是何缘故,请大家给予指点。另外,我使用的操作系统为Windows XP Home Edition(Service Pack2)。
var
hMod:Thandle;
MyText:function(DC: HDC; X, Y: Integer; Str: PChar; Count: Integer): BOOL; stdcall;
begin
hMod:=LoadLibrary('C:\Windows\System32\GDI32.dll');
try
if hMod<=0 then
MessageBox(0,'装载DLL失败!','提示',MB_OK or MB_ICONERROR)
else
begin
@MyText:=GetProcAddress(hMod,'TextOut');
if (@MyText<>nil) then
MyText(Self.Canvas.Handle,600,300,'HJXLJ',5)
else
MessageBox(0,'取函数地址失败!','提示',MB_OK or MB_ICONERROR);
end;
finally
FreeLibrary(hMod);
end;
end;但在运行时总是显示"取函数地址失败!"。不知是何缘故,请大家给予指点。另外,我使用的操作系统为Windows XP Home Edition(Service Pack2)。
TextOut只存在于win16中。
没有textout这个函数.
有TextoutA,TextOutW
@MyText:=GetProcAddress(hMod,'TextOut'); 更换为
@MyText:=GetProcAddress(hMod,'TextOutA');
程序即运行正常。
再次感谢所有关注以及帮助本人解决这个疑惑的所有人士。谢谢!