How a to expose data of an application (.EXE) to a DLL on runtime?
-
Hello, I have an application that uses a DLL but the DLL needs to access data provided by the application on runtime. Tryng to make .exe objects visible to the DLL brings me to awful linking problems The solution I tested is to use COM but this forces to use RPC for communication between the .DLL and the .EXE world. COM solution sounds complex and out-proc is slower than in-proc. Please could you help me with a more simple solution? Thank you in advance
-
Hello, I have an application that uses a DLL but the DLL needs to access data provided by the application on runtime. Tryng to make .exe objects visible to the DLL brings me to awful linking problems The solution I tested is to use COM but this forces to use RPC for communication between the .DLL and the .EXE world. COM solution sounds complex and out-proc is slower than in-proc. Please could you help me with a more simple solution? Thank you in advance
What data is needed by the DLL? You should export a function from the DLL that the EXE can call to pass in the data using function parameters.
«_Superman_» _I love work. It gives me something to do between weekends.
-
What data is needed by the DLL? You should export a function from the DLL that the EXE can call to pass in the data using function parameters.
«_Superman_» _I love work. It gives me something to do between weekends.
Data is contained in arrays which objects are instances of classes of the application. I have tried to pass a reference of the object in the exported function but the parameter type is not known by the DLL. I also tried to make the header file visible to the DLL and set a #include "myfile.h" in the DLL but this does not work.
-
Data is contained in arrays which objects are instances of classes of the application. I have tried to pass a reference of the object in the exported function but the parameter type is not known by the DLL. I also tried to make the header file visible to the DLL and set a #include "myfile.h" in the DLL but this does not work.
I'm assuming you're getting compile time errors when compiling the DLL. Please post the error messages and the relevant code.
«_Superman_» _I love work. It gives me something to do between weekends.
-
Hello, I have an application that uses a DLL but the DLL needs to access data provided by the application on runtime. Tryng to make .exe objects visible to the DLL brings me to awful linking problems The solution I tested is to use COM but this forces to use RPC for communication between the .DLL and the .EXE world. COM solution sounds complex and out-proc is slower than in-proc. Please could you help me with a more simple solution? Thank you in advance
-
Data is contained in arrays which objects are instances of classes of the application. I have tried to pass a reference of the object in the exported function but the parameter type is not known by the DLL. I also tried to make the header file visible to the DLL and set a #include "myfile.h" in the DLL but this does not work.
If you're going to pass by reference, your recipient (the DLL) needs the definition of what's enclosed, so it'll need the header file anyway. Just make sure it gets included into the DLL project as well.
-
If you're going to pass by reference, your recipient (the DLL) needs the definition of what's enclosed, so it'll need the header file anyway. Just make sure it gets included into the DLL project as well.
Hello Albert, Many thanks for your help. Actually my problem is a linking issue. with this message: error LNK2019: unresolved external symbol "public: double __thiscall TestRef::unDouble(double)" (?unDouble@TestRef@@QAENN@Z) referenced in function "public: void __thiscall ClassRef::setval(int)" (?setval@ClassRef@@QAEXH@Z) MYDLL.obj fatal error LNK1120: 1 unresolved externals Debug/MYDLL.dll My Dll function has a pointer as parameter and the pointer calls the function member of the application's class and that function uses an object of another class of the application. Could you please tell me how to solve it? Below is the sample source of the DLL function
#include "classref.h" // file header of the application using the DLL
extern "C" __declspec(dllexport) int MainEntry( ClassRef* pRef )
{
// entier is a public attribute of the application that uses the DLL
int XX = pRef->entier; // This works//getval is a public member function of the application that uses the DLL XX = pRef->setval(5); // compile but does not build. unresolved external symbol errors
return 0;
}And below is definition of setval(int )
void setval( int val)
{
double dbl = m_ref->unDouble(16.45);// This is a member function of another class of the application
entier = val * dbl ;
} -
I'm assuming you're getting compile time errors when compiling the DLL. Please post the error messages and the relevant code.
«_Superman_» _I love work. It gives me something to do between weekends.
-
Hello Albert, Many thanks for your help. Actually my problem is a linking issue. with this message: error LNK2019: unresolved external symbol "public: double __thiscall TestRef::unDouble(double)" (?unDouble@TestRef@@QAENN@Z) referenced in function "public: void __thiscall ClassRef::setval(int)" (?setval@ClassRef@@QAEXH@Z) MYDLL.obj fatal error LNK1120: 1 unresolved externals Debug/MYDLL.dll My Dll function has a pointer as parameter and the pointer calls the function member of the application's class and that function uses an object of another class of the application. Could you please tell me how to solve it? Below is the sample source of the DLL function
#include "classref.h" // file header of the application using the DLL
extern "C" __declspec(dllexport) int MainEntry( ClassRef* pRef )
{
// entier is a public attribute of the application that uses the DLL
int XX = pRef->entier; // This works//getval is a public member function of the application that uses the DLL XX = pRef->setval(5); // compile but does not build. unresolved external symbol errors
return 0;
}And below is definition of setval(int )
void setval( int val)
{
double dbl = m_ref->unDouble(16.45);// This is a member function of another class of the application
entier = val * dbl ;
}Your error is telling you that that code was never compiled, did you add the header and cpp of "classref.h" to your DLL project?
-
Your error is telling you that that code was never compiled, did you add the header and cpp of "classref.h" to your DLL project?
Sure I tried the header alone and the cpp. with the header but linking message is still here. I noticed a curious behavior as following: 1. If I put a comment on the function setval from within my Dll. Then it builds correctly 2. if I remove the comment and I just compile. This works fine as well. 3. Finally if I rebuild the DLL I get the linking errors.
-
Your error is telling you that that code was never compiled, did you add the header and cpp of "classref.h" to your DLL project?
-
I have got the reason of the problem. Implementation and definition must be in the same file. I.e in the header. But this brings to another problem that is the source code will be disclosed if the application is distributed.
It doesn't have to be in the same file, you just have to include both in your DLL project. As far as the source requiring to be disclosed.... well, don't pass an entire class to your DLL and you won't have to disclose the code. You should probably only pass data along. Make use of data structures instead of passing classes.