C++ Class From a DLL using C#
Hi guys!
I need a little help here. I've built a piece of code that wraps around several functions of windows. I've done this by creating a class in the C++ DLL. I know how to call functions from a C++ DLL already but how to you create a class from the C++ library and call its methods?
Cheers :)
Re: C++ Class From a DLL using C#
Wait, what..? You know how to call functions from a C++ DLL, but you don't know how to call methods from a C++ library?
Here's a hint: functions are methods too.
And another hint: a DLL is a library too.
Re: C++ Class From a DLL using C#
I got that. But since these methods require class initialization isn't there something that I need to do before I call them?
Currently I do this:
Code:
[DllImport("cpu.information.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?HasSSE42Extensions@CPUIdentification@@QAE_NXZ")]
public static extern bool HasSSE42Extensions();
Which works but seems... wrong. Does the code internally run the class constructor or something?
Re: C++ Class From a DLL using C#
Well you should have mentioned that in your post :)
I can't really help you as I don't know myself, I just happened to read your post and it sounded to me like you had already answered your own question.
So just to be clear, the know how to call static methods, but you don't know how to call instance methods (or, how to create an instance and then call its methods)?
Re: C++ Class From a DLL using C#
Yeah. You got it. I can confirm that the above code doesn't work if the class has not been initialized first.