Antony
Antony

Reputation: 199

How to call a function in source from a dll in c

I have created a DLL in C++ and have successfully been able to use it in another application. What I would like to is to use a function in my application code - NOT THE DLL - and be able to use that function within the DLL.

Is this possible? Thanks.

Upvotes: 0

Views: 116

Answers (1)

Georg Fritzsche
Georg Fritzsche

Reputation: 98974

Sure - if you can call functions in your DLL, you can e.g. pass function pointers to it from the hosting application (or another DLL in the same process) and then call those:

// DLL side:
typedef void (*CallbackFunc)();
APISTUFF void dllFunction(CallbackFunc f) {
  f();
}

// hosting app side:
void hostFunction() {
    // ...
}

void doPluginStuff() {
  // ... load DLL, resolve dllFunction, etc.
  dllFunction(&hostFunction);
}

That is how C-style plugin APIs like NPAPI work.

Upvotes: 4

Related Questions