Dll function calls are not called right
-
Hi, I have created a dll which exports a factory function that returns an object of the type of the dll class: class CMyDll { Z(); X(); Y(); } extern "c" { __declspec(dllexport) CMyDll* Factory(); } The program that utilize the dll loads the dll calls the factory function and get the dll object. from that object i call the dll functions. MyApp() { hmodule = AfxLoadLibrary(MyDll.dll); typedef CMyDll* (*FACTORY )(void); FACTORY pFunc; pFunc = (FACTORY)GetProcAddress(hmodule,"Factory"); CMyDll *dllObj = pFunc(); dllObj->X(); dllObj->Y(); dllObj->Z(); } But there is a problem , the functions are not called right, if i call functions X,Y and Z, it calls functions Z,Y and X in a certain order which i couldn't specify. If someone spotted the source of the error please let me know Thanks :confused: Simon
-
Hi, I have created a dll which exports a factory function that returns an object of the type of the dll class: class CMyDll { Z(); X(); Y(); } extern "c" { __declspec(dllexport) CMyDll* Factory(); } The program that utilize the dll loads the dll calls the factory function and get the dll object. from that object i call the dll functions. MyApp() { hmodule = AfxLoadLibrary(MyDll.dll); typedef CMyDll* (*FACTORY )(void); FACTORY pFunc; pFunc = (FACTORY)GetProcAddress(hmodule,"Factory"); CMyDll *dllObj = pFunc(); dllObj->X(); dllObj->Y(); dllObj->Z(); } But there is a problem , the functions are not called right, if i call functions X,Y and Z, it calls functions Z,Y and X in a certain order which i couldn't specify. If someone spotted the source of the error please let me know Thanks :confused: Simon
what about this :
pFunc = (FACTORY)GetProcAddress(hmodule,"
**_Factory**
");BTW, your code is not very secure, as you don't test hmodule before using it...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Hi, I have created a dll which exports a factory function that returns an object of the type of the dll class: class CMyDll { Z(); X(); Y(); } extern "c" { __declspec(dllexport) CMyDll* Factory(); } The program that utilize the dll loads the dll calls the factory function and get the dll object. from that object i call the dll functions. MyApp() { hmodule = AfxLoadLibrary(MyDll.dll); typedef CMyDll* (*FACTORY )(void); FACTORY pFunc; pFunc = (FACTORY)GetProcAddress(hmodule,"Factory"); CMyDll *dllObj = pFunc(); dllObj->X(); dllObj->Y(); dllObj->Z(); } But there is a problem , the functions are not called right, if i call functions X,Y and Z, it calls functions Z,Y and X in a certain order which i couldn't specify. If someone spotted the source of the error please let me know Thanks :confused: Simon
-
Hi all, thanks for your answers. The problem was that i declared a function in the interface as an int, but the implementing class declared the same function with an enum. So when calling the function from the dll (which was the implementing class) the function was not found and another function was called. ______________ |Interface | |-x(int var);| -------------- | \/ ______________ |dll class | |-x(enum var)| -------------- ;)