0

I have a C++ application that maintains a couple of in memory data stores (vector/map in c++). I need to access these data stores from a C# application, preferably some kind of service (WCF) so I can expose it further to a web application. I will be looking at creating a C++/CLI wrapper next week but wanted to ask ahead of time if this will be able to do what I need? I am very new to C++ and usually just work with the .Net framework. Another option is to try and get the existing C++ application running as C++/CLI but I would prefer to try the wrapper approach first if possible. Or try something else entirely if there is a better way?

I have a test C# console application that is able to call C++ code exposed as a static library or a dynamic library and am comfortable with this now. From what I understand it does this using the DLLImport/P-invoke process. My problem is I need the C++ exe actually running rather than just exposing functions. I have tried to get the C# application to start a thread within the C++ program by calling a function within the C++ app but I receive a memory access violation so assume this can't be done?

[DllImport("DynamicLib.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void startServiceThread();
dymanoid
  • 14,771
  • 4
  • 36
  • 64
renz
  • 165
  • 3
  • 12
  • 3
    If you need to access data in a running process, you have to use inter-proc communication. There are plenty of IPC services provided by Windows, and there are APIs both on managed and unmanaged sides. But since your question is so abstract, it's difficult to suggest something particular. – dymanoid Aug 30 '19 at 09:53
  • Thanks, it looks like this is what I was after. I've already found some good articles. Cheers – renz Aug 30 '19 at 10:04
  • Why not make your `C++` project a console application which the `.Net` service starts with 'Process.Start'. Than you can use `Named Pipes` or 'Memory Mapped' files to communicate/pass data between both the process running the `.Net` application and the `C++` console application. You could also just use `TCP` and the loopback address for communications and `Memory Mapped` files for passing data. – WBuck Aug 30 '19 at 11:28

0 Answers0