@@ -253,16 +253,15 @@ BuildImportTable(PMEMORYMODULE module)
253253 FARPROC * funcRef ;
254254 HCUSTOMMODULE handle = module -> loadLibrary ((LPCSTR ) (codeBase + importDesc -> Name ), module -> userdata );
255255 if (handle == NULL ) {
256- #if DEBUG_OUTPUT
257- OutputLastError ("Can't load library" );
258- #endif
256+ SetLastError (ERROR_MOD_NOT_FOUND );
259257 result = 0 ;
260258 break ;
261259 }
262260
263261 tmp = (HCUSTOMMODULE * ) realloc (module -> modules , (module -> numModules + 1 )* (sizeof (HCUSTOMMODULE )));
264262 if (tmp == NULL ) {
265263 module -> freeLibrary (handle , module -> userdata );
264+ SetLastError (ERROR_OUTOFMEMORY );
266265 result = 0 ;
267266 break ;
268267 }
@@ -292,6 +291,7 @@ BuildImportTable(PMEMORYMODULE module)
292291
293292 if (!result ) {
294293 module -> freeLibrary (handle , module -> userdata );
294+ SetLastError (ERROR_PROC_NOT_FOUND );
295295 break ;
296296 }
297297 }
@@ -341,17 +341,13 @@ HMEMORYMODULE MemoryLoadLibraryEx(const void *data,
341341
342342 dos_header = (PIMAGE_DOS_HEADER )data ;
343343 if (dos_header -> e_magic != IMAGE_DOS_SIGNATURE ) {
344- #if DEBUG_OUTPUT
345- OutputDebugString ("Not a valid executable file.\n" );
346- #endif
344+ SetLastError (ERROR_BAD_EXE_FORMAT );
347345 return NULL ;
348346 }
349347
350348 old_header = (PIMAGE_NT_HEADERS )& ((const unsigned char * )(data ))[dos_header -> e_lfanew ];
351349 if (old_header -> Signature != IMAGE_NT_SIGNATURE ) {
352- #if DEBUG_OUTPUT
353- OutputDebugString ("No PE header found.\n" );
354- #endif
350+ SetLastError (ERROR_BAD_EXE_FORMAT );
355351 return NULL ;
356352 }
357353
@@ -370,18 +366,14 @@ HMEMORYMODULE MemoryLoadLibraryEx(const void *data,
370366 MEM_RESERVE | MEM_COMMIT ,
371367 PAGE_READWRITE );
372368 if (code == NULL ) {
373- #if DEBUG_OUTPUT
374- OutputLastError ("Can't reserve memory" );
375- #endif
369+ SetLastError (ERROR_OUTOFMEMORY );
376370 return NULL ;
377371 }
378372 }
379373
380374 result = (PMEMORYMODULE )HeapAlloc (GetProcessHeap (), 0 , sizeof (MEMORYMODULE ));
381375 if (result == NULL ) {
382- #if DEBUG_OUTPUT
383- OutputLastError ("Can't reserve memory" );
384- #endif
376+ SetLastError (ERROR_OUTOFMEMORY );
385377 VirtualFree (code , 0 , MEM_RELEASE );
386378 return NULL ;
387379 }
@@ -432,9 +424,7 @@ HMEMORYMODULE MemoryLoadLibraryEx(const void *data,
432424 // notify library about attaching to process
433425 successfull = (* DllEntry )((HINSTANCE )code , DLL_PROCESS_ATTACH , 0 );
434426 if (!successfull ) {
435- #if DEBUG_OUTPUT
436- OutputDebugString ("Can't attach library.\n" );
437- #endif
427+ SetLastError (ERROR_DLL_INIT_FAILED );
438428 goto error ;
439429 }
440430 result -> initialized = 1 ;
0 commit comments