Results 1 to 5 of 5

Thread: Making a dll get info from the app!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    Making a dll get info from the app!

    I have an app that uses functions inside a dll. I would like the dll to get a variable hInstance from the app so when the dll is loaded it has the value assigned to an hInstance vraible in the dll?

    Is this possible?if so how would i go about doing this?

    Cheers in Advance

    Andy

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I'm not sure if GetCurrentProcess will return a handle to the DLL or the EXE. You'd have to use DuplicateHandle anyway.
    If this does not work, you have to require the app to call a init-function and supply it's own instance handle.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    ini function

    the dl currently uses an init function to get the handle and this works fine until the focus is taken off the app window and onto another, the dll seems to lose the handle and reset itself to NULL along with other static variables!?

    Hence why i wondered if you could get the dll to look at an apps varibales.

    I'll have a go with GetCurrentProcess.

    Cheers

    Andy

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    "seems to loose the handle" ???
    Do you mean, after returning to the process that uses the DLL the static variables are resetted??
    Or are the variables uninitialized in another process that uses the same DLL?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    This is because DLLs don't have their own memory, but rather use the one of the app they are linked too. This means there is one set of DLL static variables for every app that uses the DLL. If you want that those variables are the same for all applications that use them (you probably don't want, because HWND is specific to every application), you should insert this line after the data segment:
    #pragma comment(linker, "/SECTION:SHARDATA, RWS")

    but watch out: this also means that if one application changes the variables it can cause problems with other applications. Also, you'll have thread-synchronization problems, so you should know how to use critical sections, the Interlocked* function family, mutexes, events and semaphores (search for these things in MSDN).
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width