I have created a test application which uses DLL file and call its internal function(s).
I followed the steps given in the link: Dynamically load a function from a DLL
I have Win32 console application and a DLL creator application. Ideally the Win32 application LoadLibrary() and GetsProcAddress() and get the function pointer for that particular function inside the DLL with parameters passed, returns results, all done working fine.
Now, what I need to do is, From console application I need to call a function inside DLL and in DLL function I need to call a function in Win32 console application to get the values instead of passed as a parameter.
Something like this,
1) Include the same header file used in Win32 console project into the DLL project. 2) When the function inside the DLL project called by Win32 console project 3) Get value from console project, process it and set value back to the console application
dllmain.cpp:
#include "evaluate.h"
extern "C" __declspec(dllexport) int _cdecl ADD(void)
{
int a = getValueOfA();
int b = getValueofB();
setValueOfC((a+b));
}
evaluate.cpp:
int getValueOfA(void)
{
return 3;
}
int getValueOfB(void)
{
return 5;
}
void setValueOfC(int c)
{
printf("\nValue of C is: %d",c);
}
HINSTANCE hGetProcIDDLL;
typedef int(_cdecl *func_ptr)();
hGetProcIDDLL = LoadLibrary("MyDll.dll);
func_ptr addFunc = (func_ptr)GetProcAddress(hGetProcIDDLL, "ADD");
addFunc();
evaluate.h
int getValueOfA();
int getValueOfB();
void setValueOfC(int value);
MyDll.def:
EXPORTS
ADD @1
Any additional code or procedure need to be followed? Is this doable?