MinGW Create Application C DLL Load-time dynamic linking

 

- Info:

- This tutorial shows how to use MinGW and C to create DLL which loads when executable is started.

- This tutorial is based on http://www.cygwin.com/cygwin-ug-net/dll.html

 

- Procedure:

- C:\Temp\Test.h, Test.c and Hello.c

- Start MSDOS

- gcc -shared Test.c -o message.dll

- gcc Hello.c -L./ -lmessage -o hello.exe

- hello.exe

 

Test.h

__declspec(dllexport) void hello(void);

Test.c

#include <stdio.h>

#include "Test.h"

void hello(void) { printf("Hello from DLL!\n"); }

 

Hello.c

int main () {

hello();

return 0;

}