c99 and DLLs

Started by
4 comments, last by GameDev.net 18 years ago
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-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
Advertisement
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-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
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.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
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-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
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.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
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.

This topic is closed to new replies.

Advertisement