Skip to content

Commit 536a597

Browse files
committed
Use "SetLastError" for errors in "GetProcAddress".
1 parent c4e8de7 commit 536a597

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

MemoryModule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,14 @@ FARPROC MemoryGetProcAddress(HMEMORYMODULE module, const char *name)
448448
PIMAGE_DATA_DIRECTORY directory = GET_HEADER_DICTIONARY((PMEMORYMODULE)module, IMAGE_DIRECTORY_ENTRY_EXPORT);
449449
if (directory->Size == 0) {
450450
// no export table found
451+
SetLastError(ERROR_PROC_NOT_FOUND);
451452
return NULL;
452453
}
453454

454455
exports = (PIMAGE_EXPORT_DIRECTORY) (codeBase + directory->VirtualAddress);
455456
if (exports->NumberOfNames == 0 || exports->NumberOfFunctions == 0) {
456457
// DLL doesn't export anything
458+
SetLastError(ERROR_PROC_NOT_FOUND);
457459
return NULL;
458460
}
459461

@@ -469,11 +471,13 @@ FARPROC MemoryGetProcAddress(HMEMORYMODULE module, const char *name)
469471

470472
if (idx == -1) {
471473
// exported symbol not found
474+
SetLastError(ERROR_PROC_NOT_FOUND);
472475
return NULL;
473476
}
474477

475478
if ((DWORD)idx > exports->NumberOfFunctions) {
476479
// name <-> ordinal number don't match
480+
SetLastError(ERROR_PROC_NOT_FOUND);
477481
return NULL;
478482
}
479483

0 commit comments

Comments
 (0)