Skip to content

Commit

Permalink
Prepare for version 1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPayne committed Apr 16, 2011
0 parents commit 635b8e6
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore compiled binaries
/obj/
*.exe
*.dll
*.a
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This Makefile will build a DLL and an application using the DLL.

all : AddLib.dll AddTest.exe

AddLib.dll : include/add.h
gcc -O3 -std=c99 -D ADD_EXPORTS -Wall -I.\include -c src/add.c -o obj/add.o
windres -i res/resource.rc -o obj/resource.o
gcc -o AddLib.dll obj/add.o obj/resource.o -shared -s -Wl,--subsystem,windows,--out-implib,libaddlib.a

AddTest.exe : include/add.h AddLib.dll
gcc -O3 -std=c99 -Wall -I.\include -c src/addtest.c -o obj/addtest.o
gcc -o AddTest.exe obj/addtest.o -s -L. -lAddLib

clean :
del obj\*.o *.exe *.dll *.a
46 changes: 46 additions & 0 deletions Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
MinGW DLL Example

This is an example Win32 DLL and application, written using MinGW. It is
intended to demonstrate how to write DLLs using MinGW, and utilise their
functionality within a client application. It accompanies an article from my
web site, which is located at
http://www.transmissionzero.co.uk/computing/building-dlls-with-mingw/.

To build the application on a Windows machine, simply extract the contents of
this archive to a folder on your computer. Open a command prompt, change to the
directory where you extracted the files, and type �mingw32-make�. The DLL and
executable should be compiled, linked, and output as �AddLib.dll� and
�AddTest.exe�.

To build under another operating system, the Makefile will probably require
some small changes. For example, under Fedora the C compiler and resource
compiler are named �i686-pc-mingw32-gcc� and �i686-pc-mingw32-windres�. Also,
your version of the make utility may be named differently�please check the
documentation which came with your MinGW packages.

Disclaimer

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

Terms of Use

There is no specific license attached to the use this application. You are free
to use it however you see fit, whether for commercial or non-commercial
purposes. The intention is that you use it as a starting point for building
Windows applications, so that you don�t have to write all of your applications
from scratch. You are encouraged to modify it to suit your needs as a Windows
application template, and how you license any applictions built with it is
entirely up to you. Of course, you must still comply with the licensing
conditions of the tools you are using to build the application.

Problems?

If you have any problems or questions, please get in contact via
http://www.transmissionzero.co.uk/contact/. Please ensure that you read the
article at http://www.transmissionzero.co.uk/computing/building-dlls-with-mingw/
before sending any questions.

Martin Payne
2011�04�16
32 changes: 32 additions & 0 deletions include/add.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* add.h
Declares a function and variables to be imported by our application, and
exported by our DLL.
*/

/* You should define ADD_EXPORTS *only* when building the DLL. */
#ifdef ADD_EXPORTS
#define ADDAPI __declspec(dllexport)
#else
#define ADDAPI __declspec(dllimport)
#endif

/* Define calling convention in one place, for convenience. */
#define ADDCALL __cdecl

/* Make sure functions are exported with C linkage under C++ compilers. */
#ifdef __cplusplus
extern "C"
{
#endif

/* Declare our Add function using the above definitions. */
ADDAPI int ADDCALL Add(int a, int b);

/* Exported variables. */
extern ADDAPI int foo;
extern ADDAPI int bar;

#ifdef __cplusplus
} // __cplusplus defined.
#endif
33 changes: 33 additions & 0 deletions res/resource.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BEGIN
VALUE "Comments", "Addition Library"
VALUE "CompanyName", "Transmission Zero"
VALUE "FileDescription", "A library to perform addition."
VALUE "FileVersion", "1, 0, 0, 0"
VALUE "InternalName", "AddLib"
VALUE "LegalCopyright", "�2011 Martin Payne"
VALUE "OriginalFilename", "AddLib.dll"
VALUE "ProductName", "Addition Library"
VALUE "ProductVersion", "1, 0, 0, 0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 1200
END
END
15 changes: 15 additions & 0 deletions src/add.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* add.c
Demonstrates creating a DLL with an exported function and imported variables.
*/

#include "add.h"

int ADDCALL Add(int a, int b)
{
return (a + b);
}

/* Assign value to exported variables. */
int foo = 7;
int bar = 41;
16 changes: 16 additions & 0 deletions src/addtest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* addtest.c
Demonstrates using the function and variables exported by our DLL.
*/

#include <stdlib.h>
#include <stdio.h>
#include <add.h>

int main(int argc, char** argv)
{
/* foo + bar = Add(foo, bar) */
printf("%d + %d = %d\n", foo, bar, Add(foo, bar));

return EXIT_SUCCESS;
}

0 comments on commit 635b8e6

Please sign in to comment.