Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting a vriable from an app 2

Status
Not open for further replies.

AndyHollywood

Programmer
Oct 7, 2001
30
0
0
GB
I was wondering if it was possible to export a variable from an application i am writing, and then use that exported variable in a dll as its initialisation value?!

i.e. I would like the dll's HWND to be set to the App's HWND.

I already use a initdll function to set it but it give me probs as it keeps reseting itself to null when the mouse cursor leaves the window, so i thought if i set the initialisation to the app's HWND in the first place then even if it resets itself it will be the apps HWND anyway.

Any suggestions?!

Cheers in advance

Andy

 
Once your dll is loaded it's a part of running process. You can use stuff from application in dll and vice versa.
Could you be more specific?
 
well i have dll that is initialised using initdll and this sets the hwnd of the dll to be the one of the app. this is fine while i am in the app window but as soon as the cursor moves out of the window the hwnd is reset to its original initialisation which is NULL, so the app ends up paiting the results onto the desktop and not the app that i want the results to paint into.

so i was trying to set the initialisation of the dll's hwnd to match that of the app and therfore avoid it reseting itself back to NULL as soon as i leave the window.

a copy of the project is here if your intersted:

do i need to explain it further?
 
I don't understand that. Sorry.
But it could be that you call InitDll with NULL parameter yourself. If you track underlying window with WM_MOUSEMOVE I would recommend to call SetCapture( HWND of your app ) and ReleaseCapture in the end.
 
I take it this is your global hook. The problem is most likely that global hook DLLs are loaded into every process, and the data is not shared (by default) across process boundaries. Even if you set a value in your initialising app, it won't be there in other instances of the DLL. I suggest you look at KB article Q125677 which explains sharing of DLL data between processes. :) Hope that this helped! ;-)
 
ok thanks guys



what do you reckon to the FindWindow() function or should i avoid it...i've currently got it working with the function in, but if it is bad practice then i would rather do it the proper way!
 
I've got rid of the finsWindow function and thanks to dave, i now have it working with a shared data segment.

Cheers Again for all your help

Andy
 
I assume you're trying to find your app window - should be OK as long as you can identify your window uniquely. If you looked some other way you'd need to pass a parameter to the DLL which is the problem you want to get around...but you want to cache the result and not call FindWindow() each time your hook function is entered. :) Hope that this helped! ;-)
 
Well i was caching it like you said and that worked fine, but now i have the shared data segment working properly i no longer need it!

cheers for the links to the msdn articles

thanks again

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top