// CodeProjectSample.h
If I'm still right, you have managed to export an entry that is now
correctly called by the main application.
The remaining problem is that you still need to manually copy all DLLs to the destination folder.
I believe that if you had added the C# layer as refrence to CLI code, when you complile the code,
the required DLLS (Debug or Release) will be copied to same folder where CLI dll is located.
Now you setup the main app to load your DLL in the destination folder where all other dlls are located, when you
start using the code in C# layer, in fact you are ordering CLR to load the C# dll which will fail, since it is not
located in the main app folder.
It could be solved using an AssemblyResolveHandler or adding path to private search path of AppDomain. But it is
very important that these actions be done before any attempt to call the C# layer. Therefore if you put the
C# call method in the main function, since before executing this function, CLR need to load the requested DLL, you
have no chance to do any fixups.
Following code is a sample for above consideration
*/
#pragma once
using namespace System;
using namespace System::Reflection;
namespace CodeProjectSample {
public ref class Helper
{
public:
static int DoWork()
{
return 0;
}
static String^ GetMyDllPath()
{
String^ myLocation = Helper::typeid->Assembly->Location;
return System::IO::Path::GetDirectoryName(myLocation);
}
static Helper()
{
AppDomain::CurrentDomain->AppendPrivatePath(GetMyDllPath());
AppDomain::CurrentDomain->AssemblyResolve += gcnew ResolveEventHandler(&CurrentDomain_AssemblyResolve);
}
static Assembly^ CurrentDomain_AssemblyResolve(System::Object^ sender,System::ResolveEventArgs^ args)
{
String^ CorrectedPath = args->Name;
return Assembly::Load(CorrectedPath);
}
};
}
#pragma comment(linker,"/EXPORT:PluginEntry=_PluginEntry@0");
extern "C" int __stdcall PluginEntry()
{
CodeProjectSample::Helper::DoWork();
return 0;
}