Archived

This topic is now archived and is closed to further replies.

Guest Anonymous Poster

DLLs

This topic is 6595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The only real difference with MSVC is that Microsoft has created their own little standard for declaring DLL imports and exports. Here's a little example of how to make a DLL you can import into other projects.

//
// MyDLL.h
//

// Visual C++ version
#ifdef MYDLL_IMPORT
#define MYDLL_API _declspec(dllimport)
#else
#define MYDLL_API _declspec(dllexport)
#endif

// You'll have to find the way Borland declares variables as imported/exported
// and replace _declspec(...) with the appropriate commands

// Force compiler to use undecorated function/variable names.
// This is most useful if you plan to dynamically link the DLLs.
extern "C"
{
void MYDLL_API MyDLLFunc( void );
}

//
// MyDLL.cpp
//

#include "MyDLL.h"

void MYDLL_API MyDLLFunc( void )
{
}

Add the two above files to an empty DLL project and it will compile a DLL that exports one function (MyDLLFunc) that does nothing. You get the idea. Also, to import the DLL into a project, link the project to the .lib file compiled with the DLL and include the .h file like this:

//
// MyProject.cpp
//

#define MYDLL_IMPORT
#include "MyDLL.h"

Then you can just call the functions exported in the DLL wherever you like. If you want to dynamically load the DLLs (load them without having to link to their lib), check out the Windows API commands LoadLibrary and GetProcAddress.

Share this post


Link to post
Share on other sites
Microsoft simply included that for simplicity and inline exporting and importing. If you want to do it the "old fashioned" way, you can construct a .DEF file that contains the information necessary to the compiler for creating the DLL. MSDN (as always) has a bunch of info on this method. MSDN is my friend...

- Splat

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Alright, first, thanks for your replies, it answered my original question but I think I left something out, how would I export classes (and, for that matter, import them) ?

Thanks again for any replies!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I just finished the GUI for my new game, and it works perfectly, but I wanted to make it into a DLL. I've looked around quite a bit, but I havn't seen any tutorial on "How to make DLLs". I'm using Borland C++ 5, so if anyone knows any tutorials, or finds it simple enough to tell me right here, thanks! (Oh, and if you ONLY know how to do it for MSVC++, that's okay too, I could probably translate it okay! Thanx again!)

Share this post


Link to post
Share on other sites
Hey, you insulting MSDN Library? I thought not...

Actually, I've initially learned a whole shit load of stuff from MSDN, it is the reason Win32 development is much better than any other platform. I mean, yes, every so often MSDN is wrong (gotta love the "undocumented" features of the Platform SDK), but what other platform can you in 5 seconds have a detailed syntaxical listing of a function with the desciption of each return value, quirks, and what it actually does?

However, some of my friends are A LOT more annoying than MSDN.

- Splat

Share this post


Link to post
Share on other sites