I have an injected C++ DLL, and, I'm trying to create a plugin system using C#. (I want to be able to load C# libs as plugins, and have the C# code trigger natives, kinda like a wrapper, or maybe trigger wrapped functions, whatever it takes to make this work.)
GTA IV Script Hook .Net, does exactly this, so, I know it's possible, but, I'm having trouble getting C++\C# to play nicely.
I have what is essentially a pure native C++ DLL, I created one .cpp\.h combo, which is compiled with CLR.
#using <mscorlib.dll>
#using <HackNet.dll>
#include "DotNetPlugins.h"
using namespace HackNet;
void ExecuteNet()
{
General::PrintFile("NetTest.log", "Net Test...");
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HackNet
{
public class General
{
public static void PrintFile(string path, string text)
{
System.IO.File.WriteAllText(path, text);
}
}
}
My CLR cpp\h files, and C# lib are based on this article.
http://msdn.microsoft.com/en-us/magazine/cc188703.aspx[
^]
But, it refuses to work(C++ runtime error R6033) on startup, telling me that I have a bug in my application, that I attempted to run it from a constructor, or DLLMain, neither of which is true. (The call is injected to a function that isn't invoked until I press a key, and that won't even work until the app is fully loaded, and considering it won't even launch..)
So, where am I going wrong, I know this is possible, I can name two projects that do this, unfortunately, no source code is available demonstrating how it was done. (My native DLL of course works fine, without the CLR stuff, etc,.)