OK well after thinking about your reply it made me decide to rethink my problem. I am not sure what to do now because my original question is not really where the problem lies, the call back works unless I switch focus to another app, so I dont know if I need to close this question and start another one. But just incase you are familar enough with DLLs I will describe my real problem. I tried to attach my source files but EE wouldnt let me so I will paste it below.
I created a test DLL (KBHook.dll) to create a global keyboard hook and declare a TStringList to save keys to a text file C:\Temp\KeyList.txt. The client app just loads the dll, calls the method in dll to set the hook or unset the hook. Then the client app has a button to load the file that the dll writes into a memo control. Here is what I found. When I run the client app and load the dll and call the set hook method for the dll then I type "ABC" with my client app having focus, I can click the button on the client and "ABC" is loaded in from the file. But if I switch to NotePad and type "XYZ" then click back to the client app and load the file I get "XYZ" but the "ABC" is now missing so it is like another instance of the dll was loaded for each process. Also If I go back to my client app and type "HHH" then load the file into the memo I see "ABCHHH". I dont understand how multiple instances are being loaded into memory. I would have thought there would only ever be one instance and the string list would contain the keys from all apps into a single list. There is obviously multiple copies of the string list. This explains why I had my original problem because the variable that held the pointer to the callback method was a new variable when I switched to another app. Also after I close the client app then NotePad generates an error about unable to write memory. I was thinking maybe this is why I need to create a memory map file but not sure how it work with something like a string list.
Main Topics
Browse All Topics





by: MvanderKooijPosted on 2009-08-28 at 01:51:05ID: 25205804
Hi ddideveloper,
vent: TKeyboardEvent);
vent: TKeyboardEvent);
vent: TKeyboardEvent);
;
Why are you using memorymapped files while you are in the same proces?
An other way is to add a callback setter to the dll:
DLL:
interface
procedure SetKeyboardEventCallback(e
implementation
var
gl_event: TKeyboardEvent;
exports
SetKeyboardEventCallback;
procedure SetKeyboardEventCallback(e
begin
gl_event := event;
end;
Application:
interface
procedure SetKeyboardEventCallback(e
implementation
function SetKeyboardEventCallback; external 'dllname.dll' name 'SetKeyboardEventCallback'
Now you can call SetKeyboardEventCallback from the application to start and stop the calling from the dll