So far, I had some kind of plugin mechanism in which I loaded the dll using LoadLibrary and GetProcAddress to create a specific object and return a common interface. This worked fine until I decided that one of the libraries should be exe.
The LoadLibrary documentation says that it can be used for exe too, so I gave it a chance. Exe loads without errors, like GetProcAddress. But when I try to call my constructor for specific objects, I get an access violation.
I thought this would happen because exe loading does not load all the dlls that it uses. So I tried loading them using LoadLibrary, but I got the same error. Any advice on this?
Here is my code (mixed C ++ / CLI):
Interface* MCFactory::LoadInstanceFromAssembly( String ^ concreteAssemblyName, String ^ param ){ string fullPathToAssembly = ""; fullPathToAssembly += FileSystem::GetPathToProgramDirectory(); fullPathToAssembly += "\\" + marshal_as<string>(concreteAssemblyName); MODULE hDLL = AssemblyLoader::GetInstance().LoadAssembly( fullPathToAssembly ); Interface* pObject = NULL; if (hDLL != NULL){ t_pCreateInstanceFunction pCreateInstanceFunction = (t_pCreateInstanceFunction) ::GetProcAddress (hDLL, CREATE_INSTANCE_FUNCTION_NAME.c_str()); if ( pCreateInstanceFunction != NULL ){
(AssemblyLoader :: GetInstance (). LoadAssembly is just a wrapper for :: LoadLibrary)
source share