Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2000-02-17 22:38:33 +0300
committerChristopher Faylor <me@cgf.cx>2000-02-17 22:38:33 +0300
commit1fd5e000ace55b323124c7e556a7a864b972a5c4 (patch)
treedc4fcf1e5e22a040716ef92c496b8d94959b2baa /winsup/mingw/samples/simpledll
parent369d8a8fd5e887eca547bf34bccfdf755c9e5397 (diff)
import winsup-2000-02-17 snapshot
Diffstat (limited to 'winsup/mingw/samples/simpledll')
-rw-r--r--winsup/mingw/samples/simpledll/dll.c33
-rw-r--r--winsup/mingw/samples/simpledll/dll.cpp44
-rw-r--r--winsup/mingw/samples/simpledll/dll.def2
-rw-r--r--winsup/mingw/samples/simpledll/exe.c13
-rw-r--r--winsup/mingw/samples/simpledll/jamfile14
-rw-r--r--winsup/mingw/samples/simpledll/makedll.bat23
6 files changed, 129 insertions, 0 deletions
diff --git a/winsup/mingw/samples/simpledll/dll.c b/winsup/mingw/samples/simpledll/dll.c
new file mode 100644
index 000000000..7f743bfcd
--- /dev/null
+++ b/winsup/mingw/samples/simpledll/dll.c
@@ -0,0 +1,33 @@
+
+#include <windows.h>
+
+BOOL WINAPI
+DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
+{
+ switch (dwReason)
+ {
+ case DLL_PROCESS_ATTACH:
+ printf ("DLL Attached.\n");
+ break;
+
+ case DLL_PROCESS_DETACH:
+ printf ("DLL Detached.\n");
+ break;
+
+ case DLL_THREAD_ATTACH:
+ printf ("DLL Thread Attached.\n");
+ break;
+
+ case DLL_THREAD_DETACH:
+ printf ("DLL Thread Detached.\n");
+ break;
+ }
+ return TRUE;
+}
+
+void
+Test ()
+{
+ printf ("Test Function called!\n");
+}
+
diff --git a/winsup/mingw/samples/simpledll/dll.cpp b/winsup/mingw/samples/simpledll/dll.cpp
new file mode 100644
index 000000000..0c0240685
--- /dev/null
+++ b/winsup/mingw/samples/simpledll/dll.cpp
@@ -0,0 +1,44 @@
+//
+// This is a C++ version of the code in dll.c. NOTE that you need to put
+// extern "C" { ... } around DllMain or it will not be called when your
+// Dll starts up! (It will get name mangled as a C++ function and the C
+// default version in libmingw32.a will get called instead.)
+//
+
+#include <windows.h>
+
+#include <iostream>
+
+extern "C" {
+
+BOOL WINAPI
+DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
+{
+ switch (dwReason)
+ {
+ case DLL_PROCESS_ATTACH:
+ cout << "Dll Attached" << endl ;
+ break;
+
+ case DLL_PROCESS_DETACH:
+ cout << "Dll Detached" << endl ;
+ break;
+
+ case DLL_THREAD_ATTACH:
+ printf ("DLL Thread Attached.\n");
+ break;
+
+ case DLL_THREAD_DETACH:
+ printf ("DLL Thread Detached.\n");
+ break;
+ }
+ return TRUE;
+}
+
+void
+Test ()
+{
+ printf ("Test Function called!\n");
+}
+
+};
diff --git a/winsup/mingw/samples/simpledll/dll.def b/winsup/mingw/samples/simpledll/dll.def
new file mode 100644
index 000000000..0a623d6b5
--- /dev/null
+++ b/winsup/mingw/samples/simpledll/dll.def
@@ -0,0 +1,2 @@
+EXPORTS
+Test
diff --git a/winsup/mingw/samples/simpledll/exe.c b/winsup/mingw/samples/simpledll/exe.c
new file mode 100644
index 000000000..cc44202ee
--- /dev/null
+++ b/winsup/mingw/samples/simpledll/exe.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+extern void Test();
+
+int main()
+{
+ printf ("Program started.\n");
+ Test ();
+ printf ("Program ends.\n");
+
+ return 0;
+}
+
diff --git a/winsup/mingw/samples/simpledll/jamfile b/winsup/mingw/samples/simpledll/jamfile
new file mode 100644
index 000000000..30704e68d
--- /dev/null
+++ b/winsup/mingw/samples/simpledll/jamfile
@@ -0,0 +1,14 @@
+
+Dll dll.dll : dll.c ;
+
+ImportLib libdll.a : dll.def ;
+
+
+Main exe.exe : exe.c ;
+
+LinkLibraries exe.exe : libdll.a ;
+
+DEPENDS exe.exe : dll.dll ;
+
+LINKFLAGS on exe.exe = $(LINKFLAGS) -L. ;
+
diff --git a/winsup/mingw/samples/simpledll/makedll.bat b/winsup/mingw/samples/simpledll/makedll.bat
new file mode 100644
index 000000000..c7f9b2ae8
--- /dev/null
+++ b/winsup/mingw/samples/simpledll/makedll.bat
@@ -0,0 +1,23 @@
+rem *** Create the import library for the dll ***
+dlltool --dllname dll.dll --def dll.def --output-lib libdll.a
+
+rem *** Compile the dll ***
+gcc -c -o dll.o dll.c
+
+rem *** Link the dll ***
+gcc -s -mdll -o dll.dll -Wl,--base-file,dll.b dll.o
+dlltool --dllname dll.dll --base-file dll.b --output-exp dll.e --def dll.def
+gcc -s -mdll -o dll.dll -Wl,--base-file,dll.b dll.o -Wl,dll.e
+dlltool --dllname dll.dll --base-file dll.b --output-exp dll.e --def dll.def
+gcc -s -mdll -o dll.dll dll.o -Wl,dll.e
+
+rem *** Delete temporary files from dll linking ***
+del dll.b
+del dll.e
+
+rem *** Compile exe, which uses dll. ***
+gcc -c -o exe.o exe.c
+
+rem *** Link exe.exe, which uses dll.dll ***
+gcc -s -L. -o exe.exe exe.o libdll.a
+