diff options
author | Christopher Faylor <me@cgf.cx> | 2000-02-17 22:38:33 +0300 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2000-02-17 22:38:33 +0300 |
commit | 1fd5e000ace55b323124c7e556a7a864b972a5c4 (patch) | |
tree | dc4fcf1e5e22a040716ef92c496b8d94959b2baa /winsup/mingw/samples/dlltest/loadexe.c | |
parent | 369d8a8fd5e887eca547bf34bccfdf755c9e5397 (diff) |
import winsup-2000-02-17 snapshot
Diffstat (limited to 'winsup/mingw/samples/dlltest/loadexe.c')
-rw-r--r-- | winsup/mingw/samples/dlltest/loadexe.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/winsup/mingw/samples/dlltest/loadexe.c b/winsup/mingw/samples/dlltest/loadexe.c new file mode 100644 index 000000000..c5a84dc01 --- /dev/null +++ b/winsup/mingw/samples/dlltest/loadexe.c @@ -0,0 +1,47 @@ +/*
+ * This program attempts to load expexe.exe dynamically, get the address of the
+ * ExportedFromExe function, and then call it.
+ *
+ * This example DOES NOT WORK! I don't know exactly what can be done, but
+ * it simply seems that LoadLibrary refuses to load executables.
+ */
+
+#include <stdio.h>
+#include <windows.h>
+
+int (*ExportedFromExe)();
+
+int main()
+{
+ HINSTANCE hDll;
+ int i, j, k;
+
+ hDll = LoadLibrary ("expexe.exe");
+ if (!hDll)
+ {
+ printf ("Error %d loading exe.\n", GetLastError());
+ exit (-1);
+ }
+
+ if (!(ExportedFromExe = GetProcAddress (hDll, "ExportedFromExe")))
+ {
+ printf ("Error %d getting ExportedFromExe function.\n",
+ GetLastError());
+ exit (-1);
+ }
+ else
+ {
+ ExportedFromExe ();
+ }
+
+ /* NOTE: Unlike a DLL the exe doesn't have an entry point which
+ * initializes global objects and adds __do_global_dtors to
+ * the atexit list. Thus it should be safe(?) to free the
+ * library. Of course, this also makes it unsafe to use
+ * executables at all in this manner.
+ */
+ FreeLibrary (hDll);
+
+ return 0;
+}
+
|