Dll creating

Maybe someone could give me some advises or substances about creating Dynamic Link Libraries and fit it to games because I even dont't know where to start?
closed account (E0p9LyTq)
Dynamic-Link Library Creation (Windows) - https://msdn.microsoft.com/en-us/library/windows/desktop/ms682592%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

See also:
Creating a Simple Dynamic-link Library - https://msdn.microsoft.com/en-us/library/windows/desktop/ms682507(v=vs.85).aspx

and

Walkthrough: Creating and Using a Dynamic Link Library (C++) - https://msdn.microsoft.com/en-us/library/ms235636.aspx
Is there a non-MSDN answer? I was looking for answers to this today as well. I have code I wrote and compiled with Codeblocks IDE and would like to get this done with it, at least until I get Visual Studio installed sometime soon. Thanks for any help you can give.
MSDN is just fine - there's not much of a difference between compiling with MinGW (Code::Blocks' compiler, pretty much) and Visual Studio. Probably the only gotcha is that MinGW calls the '-A' variants rather than the '-W' variants by default (e.g. CreateFile becomes CreateFileA instead of CreateFileW), though you shouldn't be using those functions anyway.
I mostly only do command line compiling work, as IDEs get in my way - especially when dealing with dlls, where, in my opinion, their behavior is atrocious. They make all these directories and subdirectories, with the host in one directory and the dll in another, then they can't find each other and whatnot. Like I said, a real mess. And they all do it. So I don't know if this will help you. However, it works with TDM-GCC-4.8. I do have a recent version of CodeBlocks I use occasionally though, and I believe I've gleaned the command line compiling strings from those generated within the CodeBlocks development environment. So here's a little useless test app to show the mechanics of getting it all working together. Here's the dll, which simply has a useless function - IncrOne(int iNum), to incremrnt whatever number is passed into it as a parameter. And all the files go in the same directory...

1
2
3
4
5
6
7
8
9
10
// dllMain.cpp
//g++.exe -DBUILD_DLL -O1 -Os -c dllMain.cpp -o dllMain.o
//g++.exe -shared -Wl,--output-def=libdllTrial.def -Wl,--out-implib=libdllTrial.a -Wl,--dll dllMain.o -o dllMain.dll -s -s 

extern "C" __declspec(dllexport) int IncrOne(int iNumber);

int IncrOne(int iNumber)
{
 return ++iNumber;
}


And here would be an exe host to load and use the dll...

1
2
3
4
5
6
7
8
9
10
11
12
// Host.cpp
//g++ Host.cpp -O1 -s -o Host.exe -s libdllTrial.a
#include <cstdio>
extern "C" __declspec(dllimport) int IncrOne(int iNumber);

int main(void)
{
 printf("IncrOne(5) = %d\n",IncrOne(5));
 getchar();

 return 0;
}


The command line compilation strings are commented out at top in both files. Note I needed two invocations of the compiler to create the dllMain.dll file. If somebody knows how to do it simpler with this example I'd appreciate knowing about it. The MS compiler is much simpler to use in my opinion. I can't believe its really as complicated as my command line from CodeBlocks has it. Its only redeeming feature though is that it does work, so I guess that counts for something. Below is my full command line screen for building the dll, then the host, then invoking the host.exe and calling InCrOne() in the dll with 5. Note my project is at C:\Code\CodeBlks\dllTrial...

1
2
3
4
5
6
7
8
C:\Code\CodeBlks\dllTrial>g++.exe -DBUILD_DLL -O1 -Os -c dllMain.cpp -o dllMain.o

C:\Code\CodeBlks\dllTrial>g++.exe -shared -Wl,--output-def=libdllTrial.def -Wl,--out-implib=libdllTrial.a -Wl,--dll dllMain.o -o dllMain.dll -s -s

C:\Code\CodeBlks\dllTrial>g++ Host.cpp -O1 -s -o Host.exe -s libdllTrial.a

C:\Code\CodeBlks\dllTrial>Host
IncrOne(5) = 6

Topic archived. No new replies allowed.