I’m trying to monitor a running application written in C++ using a different C# application.
In my C++ code I have defined an API:
_declspec(dllexport) //is this even possible when compiling an .exe?
int getSomething();
Is there a way to call this function from the C# code?
Will the classic approach work:
[DllImport("myexe.exe", CharSet = CharSet.Auto)]
public static extern int getSomething();
Yes, any PE executable can export functions this way. Just keep in mind that the compiler will sometimes mangle the export names, resulting in stuff like this:
You can check that the names are OK by loading the executable file into a tool such as PEInfo.
You should be able to call it in exactly the same way you would a function in a DLL.
Update
Ok, so it looks like you want IPC, not a P/Invoke call. See this page for info on how to use named pipes in C#. And here‘s a great place to start looking for info on how to use named pipes in C++.