Groups | Blog | Home
all groups > dotnet interop > may 2005 >

dotnet interop : Calling C++ from C# Part 2


Richard MSL
5/29/2005 8:19:21 PM
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]
6/10/2005 8:01:18 PM
namespace MCfu
{
class MCClass{
....

must be a managed class!

Willy.

[quoted text, click to view]

Richard MSL
6/13/2005 9:35:06 AM
Thanks, that solved the problem. Adding managed __gc to the class definition
made it work.

[quoted text, click to view]
AddThis Social Bookmark Button