Line | |
---|
1 | #include <stdio.h> |
---|
2 | |
---|
3 | typedef void (*Procedure) (); |
---|
4 | |
---|
5 | #ifdef WIN32 |
---|
6 | #include <windows.h> |
---|
7 | |
---|
8 | Procedure get_proc (const char* name) |
---|
9 | { |
---|
10 | void* f = ::LoadLibrary ("..\\Win32Debug\\C.dll"); |
---|
11 | |
---|
12 | if (f == 0) |
---|
13 | { |
---|
14 | f = ::LoadLibrary ("..\\VisualC\\C.dll"); |
---|
15 | } |
---|
16 | |
---|
17 | if (f == 0) |
---|
18 | { |
---|
19 | printf ("Cannot load the library\n"); |
---|
20 | exit (0); |
---|
21 | } |
---|
22 | |
---|
23 | Procedure p; |
---|
24 | |
---|
25 | p = (Procedure)::GetProcAddress ((HMODULE) f, name); |
---|
26 | if (p == 0) |
---|
27 | { |
---|
28 | char* s = new char[strlen(name) + 2]; |
---|
29 | s[0] = '_'; |
---|
30 | strcpy (s+1, name); |
---|
31 | p = (Procedure)::GetProcAddress((HMODULE) f, s); |
---|
32 | } |
---|
33 | |
---|
34 | if (p == 0) |
---|
35 | { |
---|
36 | printf ("Cannot get the module %s\n", name); |
---|
37 | exit (0); |
---|
38 | } |
---|
39 | |
---|
40 | return (p); |
---|
41 | } |
---|
42 | #else |
---|
43 | extern "C" { |
---|
44 | void C1 (); |
---|
45 | void C2 (); |
---|
46 | void C3 (); |
---|
47 | } |
---|
48 | #endif |
---|
49 | |
---|
50 | int main () |
---|
51 | { |
---|
52 | printf ("demoC\n"); |
---|
53 | |
---|
54 | Procedure c = 0; |
---|
55 | |
---|
56 | #ifdef WIN32 |
---|
57 | c = get_proc ("C1"); |
---|
58 | c (); |
---|
59 | c = get_proc ("C2"); |
---|
60 | c (); |
---|
61 | c = get_proc ("C3"); |
---|
62 | c (); |
---|
63 | #else |
---|
64 | C1 (); |
---|
65 | C2 (); |
---|
66 | C3 (); |
---|
67 | #endif |
---|
68 | |
---|
69 | return (0); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | |
---|
Note: See
TracBrowser
for help on using the repository browser.