Dear Kind-Coders,
I am trying to learn to use boost::shared_ptr to manage the lifetime of a DLL, but I am having a type conversion problem whilst setting it up.
Please see the following code:
#include <boost/make_shared.hpp>
int main()
{
{
class CMyClass {
public:
CMyClass() {}
~CMyClass() {}
int MyInt;
};
typedef void* (*fpFunct1)();
fpFunct1 CreateFoo;
/***********************************************
Build error because cannot convert
from 'HINSTANCE__ *' to 'HINSTANCE__ **'
************************************************/
boost::shared_ptr<HMODULE> spHDL (LoadLibrary("DllMain.dll"), FreeLibrary);
// get the function pointer
CreateFoo = (fpFunct1)(GetProcAddress(*spHDL, "CreateFooClassInstance"));
// get pointer to object
auto pMyClass = boost::make_shared<CMyClass*>
(static_cast<CMyClass*> (CreateFoo()));
(*pMyClass)->MyInt = 9;
} // See destructor/custom_deleter here (FreeLibrary())
return 0;
}
As it is I get the error:...boost_1_55_0\boost\smart_ptr\shared_ptr.hpp(364): error C2440: 'initializing' : cannot convert from 'HINSTANCE__ *' to 'HINSTANCE__ **'
If I do boost::shared_ptr<HINSTANCE__> spHDL (LoadLibrary("DllMain.dll"), FreeLibrary);
instead I get the error:...error C2664: 'GetProcAddress' : cannot convert parameter 1 from 'HINSTANCE__' to 'HMODULE'
Please can you show me how this is supposed to be done correctly.
Thanks in advance...
Elixir42