1212#include " ../../MemoryModule.h"
1313
1414typedef int (*addNumberProc)(int , int );
15+ #ifdef _WIN64
16+ typedef void (*throwExceptionProc)(void );
17+ #endif
1518
1619#define DLL_FILE TEXT (" ..\\ SampleDLL\\ SampleDLL.dll" )
1720
1821void LoadFromFile(void )
1922{
2023 addNumberProc addNumber;
24+ #ifdef _WIN64
25+ throwExceptionProc throwException;
26+ #endif
2127 HRSRC resourceInfo;
2228 DWORD resourceSize;
2329 LPVOID resourceData;
@@ -43,6 +49,24 @@ void LoadFromFile(void)
4349 LoadString (handle, 20 , buffer, sizeof (buffer));
4450 _tprintf (_T (" String2: %s\n " ), buffer);
4551
52+ #ifdef _WIN64
53+ throwException = (throwExceptionProc)GetProcAddress (handle, " throwException" );
54+ if (!throwException) {
55+ _tprintf (_T (" GetProcAddress(\" throwException\" ) returned NULL\n " ));
56+ } else {
57+ try {
58+ throwException ();
59+ _tprintf (_T (" Should have caught exception.\n " ));
60+ } catch (int e) {
61+ if (e != 42 ) {
62+ _tprintf (_T (" Should have caught exception 42, got %d instead\n " ), e);
63+ } else {
64+ _tprintf (_T (" Caught exception %d\n " ), e);
65+ }
66+ }
67+ }
68+ #endif
69+
4670 FreeLibrary (handle);
4771}
4872
@@ -90,6 +114,9 @@ void LoadFromMemory(void)
90114 size_t size;
91115 HMEMORYMODULE handle;
92116 addNumberProc addNumber;
117+ #ifdef _WIN64
118+ throwExceptionProc throwException;
119+ #endif
93120 HMEMORYRSRC resourceInfo;
94121 DWORD resourceSize;
95122 LPVOID resourceData;
@@ -124,6 +151,24 @@ void LoadFromMemory(void)
124151 MemoryLoadString (handle, 20 , buffer, sizeof (buffer));
125152 _tprintf (_T (" String2: %s\n " ), buffer);
126153
154+ #ifdef _WIN64
155+ throwException = (throwExceptionProc)MemoryGetProcAddress (handle, " throwException" );
156+ if (!throwException) {
157+ _tprintf (_T (" MemoryGetProcAddress(\" throwException\" ) returned NULL\n " ));
158+ } else {
159+ try {
160+ throwException ();
161+ _tprintf (_T (" Should have caught exception.\n " ));
162+ } catch (int e) {
163+ if (e != 42 ) {
164+ _tprintf (_T (" Should have caught exception 42, got %d instead\n " ), e);
165+ } else {
166+ _tprintf (_T (" Caught exception %d\n " ), e);
167+ }
168+ }
169+ }
170+ #endif
171+
127172 MemoryFreeLibrary (handle);
128173
129174exit:
0 commit comments