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

loadexe.c « dlltest « samples « mingw « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c5a84dc01772f3482444b6cb177b3167c8876af1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;
}