execute dll with parameters
Feb 19, 2013 at 11:08am UTC
Hello my Friends,
ive got a question about handling with dlls. ive a special dll from a customer which contains a algorithm and i want to test this algorithm with user specific values and collect the results. I am a hardcore beginner in c++ and sorry for that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
string dllAbsolutePath = "C:\\temp\\costum_algorithm.dll" ;
LPCSTR result = dllAbsolutePath.c_str();
FARPROC pFunc;
ifstream file;
file.open(dllAbsolutePath.c_str());
if (file.is_open() == false )
{
cout << "*.dll initiliazed failed" << endl << endl;
}
else
{
cout << endl << endl;
// dll loaded successfully
HMODULE hMod = LoadLibrary(dllAbsolutePath.c_str());
pFunc = GetProcAddress(hMod, "Algorithm_Function" );
cout << pFunc << endl;
Right now i get only the Address of the Function but i want that this Function calculate some Values for me.
I hope that you can support me
Thank you
Last edited on Feb 19, 2013 at 1:06pm UTC
Feb 19, 2013 at 2:07pm UTC
You need to know the signature of the function you want to test in order to call it correctly.
Create a function pointer with the correct signature, assign pFunc to that function pointer. Then call the function via the new function pointer.
Example:
1 2 3 4 5 6
int (*somefunc) (int arg1, int arg);
int rslt;
somefunc = (int (*)(int ,int )) pFunc; // cast function pointer
rslt = (*somefunc) (1,2);
Note the cast from the void pointer to the signature of the function.
edit:
Corrected cast.
Last edited on Feb 20, 2013 at 1:38am UTC
Topic archived. No new replies allowed.