Ronald Ku
Ronald Ku

Reputation: 327

Start application even if DLL isn't found?

Suppose I have

  1. main() in main.exe
  2. functionA() in dllA
  3. functionB() in dllB

In main.exe,

int main()
{
   if(1)
    {
       functionA();
    }
    else
    {
       functionB();
    }
}

Suppose I do not have dllB but only dllA and I still want to launch the application main.exe.

Is there any way I can bypass the DLL check right at the launch of main.exe so I can still start the application without dllB?

Upvotes: 0

Views: 72

Answers (2)

pqnet
pqnet

Reputation: 6588

Do not specify the DLL as dependency. You can then use this code to dynamically load functions:

HMODULE libA = LoadLibrary("dllA.dll"); // NULL if load failed
HMODULE libB = LoadLibrary("dllB.dll"); // NULL if load failed

void (*functionA)(void) = libA ? GetProcAddress(libA,"functionA"):NULL;
void (*functionB)(void) = libB ? GetProcAddress(libB,"functionB"):NULL;

Upvotes: 2

Martin Beckett
Martin Beckett

Reputation: 96119

At least on windows you can explictly load the dll at runtime with Loadlibrary

edit: It returns NULL if the DLL isn't found or can't be loaded

Upvotes: 1

Related Questions