Sign in to follow this  
Lucidquiet

c99 and DLLs

Recommended Posts

Hello, I'm trying to write a DLL with straight C using Mingw GCC. I'm having trouble finding anything about writing DLLs with C, but a bunch with C++ (and they are writting using VC++, not GCC). Also, I'm looking for something on how to load the DLL as well, and possible some drawbacks for using only straight C99, etc. Thanks for any help, L-

Share this post


Link to post
Share on other sites
Alright, I've looked and found some stuff on writing DLLs with MinGW (though I haven't had a chance to test them yet.) So NM I guess.

L-

Share this post


Link to post
Share on other sites
Afaik, there isn't much of a difference between writing a dll with C and writing a dll with C++. It's more of a compiler thing. If you want to use C and are frustrated with MinGW, check out PellesC and/or lcc-win32. You can find a lot of sample code for both of these compilers here. Here's project that involves a dll: GlobalMessageHook.

Here's a quick run down of dlls.

As for loading a dll into an exe, there are two approaches - static linking and dynamic linking. Static linking involves adding a library file to the exe compilation project. Different compilers use different formats for this file. They typically generate it during compilation along with the dll itself. If an exe is statically linked to a dll, it won't launch if the dll isn't available. That's where dynamic linking comes into play. Dynamic linking utilizes the LoadLibrary function (and related functions) at runtime to load the library into the address space of the process. If the dll isn't available, LoadLibrary returns NULL, allowing the exe to fail gracefully. If the dll is available, LoadLibrary returns a HMODULE handle that can be used with GetProcAddress to initialize function pointers to the functions exported by the dll.

There's a lot more that can be said about dlls.

Share this post


Link to post
Share on other sites
Thanks, I've used the LCC compiler for working with Eiffel. It seemed to work pretty good. Is the PellesC useable from the command line?

Also, what does Unixes use for runtime loading of a library. Is there something similar for Unix systems?

Thanks for the reply,
L-

Share this post


Link to post
Share on other sites
Yes, PellesC can be used from the command line. I don't know enough about Unix programming to address your question about runtime library loading. I would think it's possible.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Lucidquiet
Also, what does Unixes use for runtime loading of a library. Is there something similar for Unix systems?


That depends on the system. http://xaxxon.slackworks.com/phuku/sharedlib.html is quite informative. Libltdl can save you many headaches if you're going to target difference types of *NIX-like systems.


Hope this helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this