Compilation of different source files
Hi There,
I'm not 100% sure if this is in the correct forum... Apologies if it is not.
Basically, I have a class written in C# spread over 3 .cs files.
Is it possible for me to include these in a VC++ project and just create instances of the class as if were written in C++?
If so, please explain how! :)
Thanks in advance.
Re: Compilation of different source files
No, you cannot. But you can make a COM from your C# class and use it in the C++ project. See MSDN for details.
Re: Compilation of different source files
No. It's not possible. It would be possible if you were using MC++ or C++/CLI and the C# class the CLS-compliant.
Re: Compilation of different source files
Quote:
Originally Posted by BigWinston
Basically, I have a class written in C# spread over 3 .cs files.
Let these classes be a part of a C# DLL project.
To instantiate and access them in regular and unmanaged C++ code, you need to register the assembly using regasm.
Like this -
Code:
regasm.exe YourCSharpDllName.dll
Now, instantiate the way one would instantiate any COM Class. So, if YourCSharpLibName.ClassName is the Prog Id as seen in the registry post successful assembly registration, then you would create an instance of this class inside an unmanaged C++ Client like this -
Code:
CComQIPtr <IInterfaceRegistered> spInterfacePtr;
if (SUCCEEDED (spInterfacePtr.CoCreateInstance (L"YourCSharpLibName.ClassName")))
spInterfacePtr->SomePublicMethod ();
For more information -