-1

Preamble: I've been programming in PowerBuilder for 25 years and took one class in C before that so I have no idea what I'm doing and am in serious need of help.

I need to write a VERY simple C program (no user interface) that will load a 32-bit DLL, call 2 functions then release the DLL. I first used VS Code 2019 and I got a 193 when I tried to load the DLL. From what I've found it appears it's due to 64-bit system calling 32-bit DLL? I tried using VS Premium 2010 and got a 126 on the loadlibrary. The DLL in question is pborc050. Any thoughts or suggestions? Everything I found for what I'm trying to do suggested that I need to use a C program (call the function in the dll to create the powerbuilder library list then call another function to export all of the source code). This is being done for an app that is still coded in PB7 which is extremely ancient and I'm assuming is why a C program is required vs. any other newer languages.

int main(void) 
{
  HINSTANCE hinstLib;
  MYPROC ProcAdd;
  BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;

  // Get a handle to the pborc050.dll
  hinstLib = LoadLibrary("pborc050.dll");

  // If the handle is valid, try to get the function address.
  if (hinstLib != NULL)
    ....
  else
    printf("The LoadLibrary(pborc050) dll handle is not valid, error: %d.\n", GetLastError());

  return 0;
}
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
Aimee
  • 1
  • Can you confirm that you are compiling targeting x86 and not x64? Also did you look at https://stackoverflow.com/questions/38579909/loadlibrary-fails-with-error-code-193 – sbingner Aug 20 '21 at 20:46
  • Your process' bit-ness needs to match that of the dll. Presumably that means x86 (32 bits) in your case. Most likely the 126 means that your dll has other dependencies, possibly the dynamic c rtl run-time dlls. One way to see what other dlls might be loaded is to attach to a running process that uses the dll with a debugger and look at the loaded modules list. I assume you have PowerBuilder apps that can load this dll. – 500 - Internal Server Error Aug 20 '21 at 21:00
  • What is the exact question? – Ted Lyngmo Aug 20 '21 at 21:36

1 Answers1

0

Error 126 = ERROR_MOD_NOT_FOUND "Module not found"
Error 193 = ERROR_BAD_EXE_FORMAT maybe pborc050.dll is damaged or bitness mismatch
make sure you're compiling with the same format as pborc050.dll
if pborc050.dll is 32bit then compile with 32bit, otherwise 64bit

Errorist
  • 224
  • 2
  • 6