C++ CLI Wrapper for native functions : I'm trying to create a C++ CLI .Net wrapper for some native DLLs.
There is seven of these DLLs and more in the future so i need to load the dynamically. They all have the same set of functions.
LoadLibrary and GetProcAddress worked great in a native application to load these functions.

Whenever i load a DLL, and call Initialize i get AccessViolationException. 
Not really sure why.


It seems to Load the DLL fine and also the function "TSRInit"
If I pass in a path to the DLL i know is incorrect it tells me loading it failed. But doesnt say failed if I pass the correct path.

Likewise, Loading "TRInit" seems to work. 
If i pass in a function name that doesnt exist it also tells me.

Im testing with a C# Console app with platform x86 selected.



    typedef long (WINAPI *TSRINIT)(long lType, HWND hParent, RECT *pRect);
       
    namespace Imagery
    {
	    public ref class Recongizer
	{
	public:
		Recongizer(String^ DllPath) { LoadRecongizer(DllPath); }
		~Recongizer() { UnloadLibrary(); }
		bool LoadRecongizer(String^ DllPath)
		{
			HInstance = ::LoadLibrary(msclr::interop::marshal_as<std::wstring>(DllPath).c_str());
			if (HInstance == nullptr) return false;
			if (!LoadFunctions())	return false;
			return true;
		}
		long Initalize(long lType)
		{
			if (HInstance == nullptr) return 0;
			return TSInit(0, nullptr, nullptr);
		}
	private:
		void UnloadLibrary()
		{
			if (HInstance != nullptr) ::FreeLibrary(HInstance);
		}
		bool LoadFunctions()
		{ 
			TSInit = (TSRINIT)::GetProcAddress(HInstance, "TSRInit");
			if (TSInit == nullptr)
			{
				ErrorMessage = "TSRInit could not be loaded.";
				return false;
			}
			return true;
		}
		property String^ ErrorMessage;
	private:
		HINSTANCE HInstance{ nullptr };
		TSRINIT TSInit{ nullptr };
	};
}
 
