Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / June 2005

Tip: Looking for answers? Try searching our database.

Calling C++ from C# Part 2

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard MSL - 30 May 2005 04:19 GMT
I am once again trying to call a MC++ method from a C# method. I am building
with the command line, not the IDE. This is my build file:

cl /clr mc.cpp
csc /r:mc.exe /t:module csh.cs

Here are the source files:

csh.cs

using System;
using MCfu;

namespace InHere
{

    public class AppClass
    {
        static void CSFu1()
        {
            Console.WriteLine("In CSFu");
            MCfu.MCClass.HereIsFu();
        }
        static void CSFu2()
        {
            Console.WriteLine("In CSFu");
        }
    }
}

Here is mc.cpp:

#using "mscorlib.dll"
#using <System.Windows.Forms.dll>
using namespace System;

namespace MCfu
{
    class MCClass{
        public: static void HereIsFu(void)
        {
         Console::WriteLine("HereIsFu");
        }
    };
}

int main(void)
{

 Console::WriteLine("MCpp Main");
 MCfu::MCClass::HereIsFu();
}

When I build, the C# build gives the following error:

csh.cs(2,7): error CS0246: The type or namespace 'MCfu' could not be found.

I would appreciate any suggestions about what is not correct. Thanks.
Willy Denoyette [MVP] - 10 Jun 2005 19:01 GMT
namespace MCfu
{
class MCClass{
...

must be a managed class!

Willy.

>I am once again trying to call a MC++ method from a C# method. I am
>building
[quoted text clipped - 56 lines]
>
> I would appreciate any suggestions about what is not correct. Thanks.
Richard MSL - 13 Jun 2005 17:35 GMT
Thanks, that solved the problem. Adding managed __gc to the class definition
made it work.

> namespace MCfu
> {
[quoted text clipped - 65 lines]
> >
> > I would appreciate any suggestions about what is not correct. Thanks.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.