Thread: communicating with dll's

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    38

    communicating with dll's

    Hey guys,

    Well I finished coding my dll, and I wanted to communicate with it, using my .exe... I know between processess you can use pipes but I'm kinda lost right know, can you use pipes between Dll's and exe's? Or is there a better way of doing it?

    Thanks

  2. #2
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    LoadLibrary
    GetProcAddress
    FreeLibrary

    one way...or
    Use the .lib created from your DLL and just use the functions prototypes in your exe and link it
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    38
    Yeah well I forgot to mention, that I inject the DLL onto a process and then I want to communicate with it. I believe the 2nd option would work, but I just found out that you can use pipes also.

  4. #4
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    wouldn't #2 imply static linking, pretty much rendering the 'D' part of your DLL pointless...

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    No. The DLL is still a separate file that can be shared between processes, easily replaced without affecting other parts of your application, and so on.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by @nthony View Post
    wouldn't #2 imply static linking, pretty much rendering the 'D' part of your DLL pointless...
    no, you statically link to the LIB import library that is generated for the DLL, then you can just call the functions form your application directly adn teh LIB handles all the loading adn linking functionality. You can still update the DLL at any time without breaking the application, so long as you dont remove any of the functions it uses.

  7. #7
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Is the code for the above DLL linking generated at compile time? So if you stat-link foo.lib and call foo(x), will the foo(x) call then be replaced with:
    Code:
    LoadLibrary(foo.dll)
    GetProcAddress(foo(x))
    FreeLibrary(foo.dll)
    in the compiled object file? or does the LIB actually need to be present alongside the binary to perform the above steps on demand, whenever you run it?
    If it is the former case, then why do people even bother using manual library loading for DLLs they create, when it could be done automatically for them just by using a static lib for that DLL?

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Actually, linking against the static library means that the DLL will be added in the dependencies section of the executable, and thus the loader will load it. No explicit LoadLibrary call anywhere. No GetProcAddress either - the loader does that, too. And of course the FreeLibrary is resolved.

    So not only is using the LIB more convenient, it typically is faster, too. Less indirection. But the LIB doesn't need to be present after you've compiled the whole thing.

    So why do people manually load libraries? There are a few reasons.
    1) They want to discover libraries at run time. This is typically done for plug-in systems.
    2) They don't have a LIB. That happens, too.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Hey thanks, I think I understand now. I was confusing "dynamic-linking" with its subset "run-time linking". Although I've read the Wiki: DLL page many times before in the past, reading it again in light of what you said seemed to bring out that finer point that I seemed to have been overlooking before... you learn something new everytime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Protection of DLLs
    By Poche in forum C# Programming
    Replies: 5
    Last Post: 06-04-2009, 08:30 PM
  2. Some doubts on DLLs
    By BrownB in forum Windows Programming
    Replies: 1
    Last Post: 05-30-2007, 02:25 AM
  3. standart dlls
    By keeper in forum C++ Programming
    Replies: 3
    Last Post: 07-05-2006, 07:32 PM
  4. Can't load string from resource DLL's string table
    By s_k in forum Windows Programming
    Replies: 4
    Last Post: 07-15-2003, 06:43 AM
  5. DLLs <- sound files, and nesting.
    By sean in forum C++ Programming
    Replies: 2
    Last Post: 10-28-2002, 05:13 PM