1

Good afternoon,

I'm currently working on a debugger for an ancient app and I've ran into an issue.

My goal is to inject CLR environment, so I can write majority of the debugger in pure C#; to achieve this, I've injected a C# dll with a static class inside of it.

The said class performs various things, such as allocation of the console and redirection of exceptions from the said app to it.

The issue I'm having is quite an old one, the C# class won't start working until I execute any of its' methods - hence why I've created a C++ library.

The said library will be injected into the same app and (hopefully) will be able to execute the method.

I've looked all around the internet, I've found some solutions - but all the posts are from 2009, 2010, 2013 and seem rather overdone.

I would appreciate any suggestions!

5
  • 3
    It's a very general question, can you be more specific, at least about the starting point, and what have you already tried? Do you want to be able to invoke a function from C# dll from your C++ dll, regardless of the injecting, or does it make it a special case? Also, is it C++ or C++ CLI? Commented Dec 14, 2018 at 21:43
  • @nemanja228 To put simply: I have 2 injected DLLs - C# one and C++ one (could be C++ CLI if needed). The plan is to run method from the C# dll using the C++ dll. Commented Dec 14, 2018 at 22:04
  • 1
    Check this out stackoverflow.com/questions/778590/calling-c-sharp-code-from-c, especially the second answer, the not accepted one. It has 5 different ways. The simplest one is to compile C++ with /clr flag and call C# directly from it, or use C++ CLI dll as a bridge between the regular C++ and C#. Commented Dec 14, 2018 at 22:14
  • Most of these solutions do not work for me because I need to call it at runtime, not compile time. I can't reference it when I'm compiling the C++ library, but when I inject it into a process that has the C# library injected aswell. I'll check the other solutions thought. Commented Dec 14, 2018 at 22:20
  • As I've mentioned, you create a C# DLL. Then you create a managed C++ /clr DLL that exposes the methods needed. Then you can call those C++ methods from any C++ code, compile or run time. No obstacles in dynamic loading. I can link you additional examples if its eneded Commented Dec 14, 2018 at 22:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.