CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2005
    Location
    Detroit MI
    Posts
    80

    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.
    Regards,

    Big Winston

  2. #2
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    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.
    Har Har

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    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 -
    Last edited by Siddhartha; April 10th, 2006 at 04:33 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured