Re: Using multiple programming languages - C++ & C#
From: Olaf Baeyens (olaf.baeyens_at_skyscan.be)
Date: 10/19/04
- Next message: Olaf Baeyens: "Re: Using multiple programming languages - C++ & C#"
- Previous message: Jacobo Rodriguez Villar: "Re: Using multiple programming languages - C++ & C#"
- In reply to: Marshall: "Using multiple programming languages - C++ & C#"
- Next in thread: Olaf Baeyens: "Re: Using multiple programming languages - C++ & C#"
- Reply: Olaf Baeyens: "Re: Using multiple programming languages - C++ & C#"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 19 Oct 2004 15:34:26 +0200
> I am the only C++ developer in my office. The rest of the team now uses
C#.
> I want to be able to use some of the C# classes they have developed. I
know
> this is possible, but can only find the usual VB/C# examples.
>
> Can someone give me some clear instructions (or point me to an article) on
> how to use C# classes from a project that is primarily C++ managed
extensions?
>
Simple:
In your project add the C# dll under the "references" option.
Now add this somewhere in your project:
#using <mscorlib.dll>
And now add the namespaces like this in the C++ code you wish to use
using namespace System;
using namespace CustomMadeDll;
And finally
Use the code like this:
CustomMadeDll::TheClass __gc *sc=new CustomMadeDll::TheClass();
TheClass->DoSomething();
You can safely use these classes in you unmanaged code.
One other thing: Strings must be something like this;
System::String *m_sMyString=new System::String("test")
Converting System::String to normal string:
System::String __gc *sCurrentComputer=sc->CurrentComputerName();
string
sComputerName=LPCTSTR((char*)(void*)Marshal::StringToHGlobalAnsi(sCurrentCom
puter));
And the way around something like this.
string sComputerName="abc";
System::String __gc *sCurrentComputer=sComputerName.c_str();
Do not search for header files or lib files to include, since they do not
exist.
The header information is contained into the C# dlls and is available when
you add it to your "references" option.
I hope this helps. :-)
-- http://www.skyscan.be
- Next message: Olaf Baeyens: "Re: Using multiple programming languages - C++ & C#"
- Previous message: Jacobo Rodriguez Villar: "Re: Using multiple programming languages - C++ & C#"
- In reply to: Marshall: "Using multiple programming languages - C++ & C#"
- Next in thread: Olaf Baeyens: "Re: Using multiple programming languages - C++ & C#"
- Reply: Olaf Baeyens: "Re: Using multiple programming languages - C++ & C#"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|