How to work with manage code in the dll
-
Hi All, I have another problem with calling manage code from dll. I do the following: 1. Create dll project in the VS2005, add /clr option under project property->C++->general 2. Add header file to the project with interface:
#define Base_API __declspec(dllexport) class BaseI_SqlDbConnection; class Base_API Base_SqlDbConnection { public: Base_SqlDbConnection(); BaseI_SqlDbConnection *m_pi; };
3. Add define of class to the .cpp file. It is the simple wrapper on the SqlClient.using namespace System; using namespace Data; using namespace SqlClient; #ifdef _MANAGED #pragma managed(push, off) #endif BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } #ifdef _MANAGED #pragma managed(pop) #endif class BaseI_SqlDbConnection { public: BaseI_SqlDbConnection() : m_SqlDbConnection(gcnew SqlConnection){} gcroot m_SqlDbConnection; }; Base_SqlDbConnection::Base_SqlDbConnection() : m_pi(new BaseI_SqlDbConnection) { }
4. Call the class from MFC application looking like this: Base_SqlDbConnection test; With help of debugger, I found that the BaseI_SqlDbConnection() constructor doesn't want to call and object m_SqlDbConnection could not be created. I guess that the problem is in the managed code, but I am newbie for this. Please help me to resolve the problem:( or point me to the article about this.