·  C – Create – Library – DLL – Load-time

 

- Info:

  - This tutorial shows how to create "C Load-time Dynamic Li" using different compilers and tools.

  - More about DLLs and Load Time DLLs can be found at DLL and  Load Time DLL.

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

 

- MinGW:

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

  - Start MSDOS

  - gcc -shared Test.c -o Test.dll               (creates Test.dll )

  - gcc Hello.c -L./ -lTest -o Hello.exe         (creates Hello.exe)

  - Hello.exe

 

- Microsoft Compiler:

  - Create C:\Temp\Test.c

  - Start MSDOS

  - cd C:\Temp

  - cl /c Test.c                                 (creates Test.obj )

  - link -dll Test.obj                           (creates Test.dll, Test.lib and Test.exp )

  - cl Hello.c Test.lib

  - Hello.exe

 

- Microsoft Visual Studio 2008:

  - Start MVS 2008 – File – New – Project ... – Visual C++ – General – Empty Project – Name: MyProject – OK

  - RC on MyProject – Properties... – Configuration Properties – General – Project Defaults

    – Configuration Type: Dynamic Library (.dll) – OK

  - RC on Source Files – Add – New Item... – Code – C++ File (.cpp) – Name: Test.c – Add – Paste Test.c

  - RC on Test.c – Properties – Configuration Properties – C/C++ – Advanced – Compile As: Compile as C Code (/TC)

  - Start Without Debugging Ctrl+F5

 

    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;

    }