Hi,
I have written a sample code for exporting functions from a DLL to an EXE. It worked well. And, I decided to post it here for reference.
However, I would like to make this a complete reference. So, I will need to add exporting function from an EXE to a DLL, which I failed to implement correctly.
I need your help in fixing my error. It compiles correctly, however keeps crashing. I am not sure whether it is from the exported variables or from the exported functions.
I will write the parts that I want help with first!
p.s. Man I hate this automated tagger!!!!!
* Environment: Windows, Language: C
-------EXPORTING A FUNCTION FROM THE EXE TO THE DLL. (What am I doing wrong here? Cuz mine doesn't seem to work!!! )
This piece of code is in the EXE's header file.
__declspec(dllexport) RETURNVALUE MYFUNCTION( parameters )
This piece of code is in the DLL's header file.
__declspec(dllimport) RETURNVALUE MYFUNCTION( parameters )
Finally I added the "MYEXE.lib" to the additional dependencies YOURDLL project
-------EXPORTING A VARIABLE FROM THE EXE TO THE DLL. (I need help here too)
__declspec(dllimport) structuretype_t MYVAR2;__declspec(dllimport) struct structuretype_s *pMYVAR2;
------------------------Below is working! So please ignore, placed for reference only!
* Callback functions:
typedef void (* func_FUNCTIONNAME )(parameters);
void CB_FUNCTIONNAME( func_FUNCTIONNAME pFUNCTIONNAME, parameters );
void caller_function( void )
{
func_FUNCTIONNAME pFUNCTIONNAME;
HMODULE hLib;
hLib = LoadLibrary(TEXT("YOURDLL.dll"));
pFUNCTIONNAME = (func_FUNCTIONNAME)GetProcAddress(hLib, TEXT("FUNCTIONNAME"));
if ( pFUNCTIONNAME == NULL) {
return;
CB_FUNCTIONNAME(pFUNCTIONNAME, parameters);
CB_FUNCTIONNAME(pFUNCTIONNAME);
}
void CB_FUNCTIONNAME( func_FUNCTIONNAME pFUNCTIONNAME, parameters )
{
pFUNCTIONNAME( parameters );
return;
}
__declspec(dllexport) void CallBackToMe( void )
{
return;
}
-------EXPORTING A VARIABLE FROM THE DLL TO THE EXE.
I didn't! I added an additional function to handle editing the variables. I was lucky to have no pointer variables in my program! (^o^)/
Reference1:
Calling to an EXE function from inside a DLL[
^]
Reference2:
I made this callback function what is wrong?[
^]