MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / mod_GetSymbol

Function mod_GetSymbol

module/module.cpp:411–472  ·  view source on GitHub ↗

Returns a pointer to a function within a loaded module. If it returns NULL there was an error. Check mod_GetLastError to see if there was an error symstr is the name of the function you want to get the symbol for (Do NOT give any pre/suffix to this name) parmbytes is the size (in bytes) of the parameter list the function should have

Source from the content-addressed store, hash-verified

409// mod_GetLastError to see if there was an error symstr is the name of the function you want to get the symbol for (Do
410// NOT give any pre/suffix to this name) parmbytes is the size (in bytes) of the parameter list the function should have
411MODPROCADDRESS mod_GetSymbol(module *handle, const char *symstr, uint8_t parmbytes) {
412 char buffer[256];
413 MODPROCADDRESS sym;
414 if (!handle) {
415 ModLastError = MODERR_INVALIDHANDLE;
416 return NULL;
417 }
418 if (!symstr) {
419 ModLastError = MODERR_OTHER;
420 return NULL;
421 }
422 if (!handle->handle) {
423 ModLastError = MODERR_NOMOD;
424 return NULL;
425 }
426#if defined(WIN32)
427 // We need to first form the correct symbol name (for Windows)
428 if (parmbytes == 255)
429 sprintf(buffer, "%s", symstr);
430 else
431 sprintf(buffer, "_%s@%d", symstr, parmbytes);
432 DWORD err;
433 sym = GetProcAddress(handle->handle, buffer);
434 if (!sym) {
435 err = GetLastError();
436
437 // Try again using no byte ordinals
438 if (parmbytes != 255) {
439 sprintf(buffer, "%s", symstr);
440 sym = GetProcAddress(handle->handle, buffer);
441 if (!sym)
442 err = GetLastError();
443 }
444 }
445 if (!sym) {
446 // there was an error
447
448 switch (err) {
449 case ERROR_DLL_INIT_FAILED:
450 ModLastError = MODERR_MODINITFAIL;
451 break;
452 case ERROR_DLL_NOT_FOUND:
453 ModLastError = MODERR_MODNOTFOUND;
454 break;
455 case ERROR_INVALID_DLL:
456 ModLastError = MODERR_INVALIDMOD;
457 break;
458 default:
459 ModLastError = MODERR_OTHER;
460 break;
461 }
462 return NULL;
463 }
464#elif defined(POSIX)
465 sym = dlsym(handle->handle, symstr);
466 if (!sym) {
467 ModLastError = MODERR_OTHER;
468 return NULL;

Callers 9

dyna_gl.hFile · 0.85
opengl_GetDLLFunctionsFunction · 0.85
IsScriptOutofSyncFunction · 0.85
LoadMultiDLLFunction · 0.85
LoadGameDLLFunction · 0.85
GetDLLGameInfoFunction · 0.85
Osiris_LoadLevelModuleFunction · 0.85
Osiris_LoadGameModuleFunction · 0.85
Osiris_LoadMissionModuleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected