Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

class in managed c++ called from c#

Tags:

c++

c#

dll

managed

I have a class decalred inside managed c++ dll as

public class IPHelper
{
public:
    static void CheckIP(LPWSTR pSocketName);
    static void DebugMessage(const wchar_t *str, ...);
private:        
    static DWORD GetIPInformation(PSOCKET_RECORD &pInfo);
};

I compiled it successfully and add it as reference to my c# project. I am able to use the namespace, however the class seems empty and I'm unable to call the functions inside it.

Any ideas?

like image 595
Moti Avatar asked Feb 22 '26 21:02

Moti


2 Answers

That class is not managed, it is native. You need to call it a public ref class if you want to use it from managed code.

like image 107
Puppy Avatar answered Feb 25 '26 09:02

Puppy


You're going to need to invoke it using the P/Invoke method. See this reference for more information.

like image 27
Paul Sonier Avatar answered Feb 25 '26 11:02

Paul Sonier