Board index » cppbuilder » How to call a function inside EXE from a DLL

How to call a function inside EXE from a DLL

Hello,

I have a program (EXE) written in C++Builder 6.
I have a DLL written in C++Builder 6.
The EXE is using the DLL

Now I want to call a function inside the EXE from the DLL.
How to do?
Any example?

best regards
Martin

 

Re:How to call a function inside EXE from a DLL


Martin,

Quote
> Now I want to call a function inside the EXE from the DLL.
> How to do?

You have to pass a function pointer to the DLL. This is called a
callback. In the following code there are three parts. Code for the
EXE, code for DLL and code that both may need.

// Common header
typedef void ( *TCallBack )( char const * message );
// Define the function pointer

// EXE
void wibble( char const * message )
{ // The function to callback. Compare with typedef.
  ShowMessage( message );

Quote
}

{
  giveDLLTheCallBack( wibble ); // Note, no ()s

Quote
}

// DLL
void giveDLLTheCallBack( TCallBack CallBackFn )
{
  CallBackFn( "Yippee" ); // Call the exe function.
Quote
}

--
Andrue Cope
[Bicester, UK]

Team Thai Kingdom

Other Threads