我在DLL中定义了全局变量x:string;
handle:THandle;然后使用回调函数
function GetStr(A:String):string;stdcall;export;
implementation
function GetStr(A:String):string;stdcall;
begin
x:='$'+A;
handle:=strtoint(x);
end;在程序中使用了.
var
function GetStr(a:String):String;stdcall;external 'xxxxx.dll';
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
GetStr(Edit1.text);//Edit1.text内容为输入窗口句柄
end;
问题:为什么我取得的句柄没有错,但使用sendmessage(handle,wm_char,92,0);或postmessage(handle,wm_char,92,0);均没能起到向窗口发送消息.或启动只能发送一次,之后就再也没有发送成功.
而在DLL中的键盘钩子回调函数中用 hw := FindWindow(nil,'窗口');后再用 sendMessage及postmessage却可以????有没有办法可以解决以上问题? 却从程序中的输入框取得窗口句柄然后把此句柄输入到DLL中,供其调用!
handle:THandle;然后使用回调函数
function GetStr(A:String):string;stdcall;export;
implementation
function GetStr(A:String):string;stdcall;
begin
x:='$'+A;
handle:=strtoint(x);
end;在程序中使用了.
var
function GetStr(a:String):String;stdcall;external 'xxxxx.dll';
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
GetStr(Edit1.text);//Edit1.text内容为输入窗口句柄
end;
问题:为什么我取得的句柄没有错,但使用sendmessage(handle,wm_char,92,0);或postmessage(handle,wm_char,92,0);均没能起到向窗口发送消息.或启动只能发送一次,之后就再也没有发送成功.
而在DLL中的键盘钩子回调函数中用 hw := FindWindow(nil,'窗口');后再用 sendMessage及postmessage却可以????有没有办法可以解决以上问题? 却从程序中的输入框取得窗口句柄然后把此句柄输入到DLL中,供其调用!
handle:THandle;然后使用回调函数
function GetStr(A:String):string;stdcall;export;
implementation
function GetStr(A:String):string;stdcall;
begin
x:='$'+A;
handle:=strtoint(x);
result:='...' //应该有吧
end;
{ ...To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
先写代码测试handle里面的内容是否正确
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }