By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,771 Members | 1,709 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,771 IT Pros & Developers. It's quick & easy.

vc++ migration to c# help

P: n/a
Hello,

I have a VS 2003.NET solution which consists of four c++ unmanaged legacy
projects. I am adding a new project to the solution which will be in c#.
What do I need to do to my c++ projects in order to call my c# modules from
within c++? From what I understand, I need to convert my c++ code from
unmanaged to managed using the /clr switch (IJW). Is this correct? Are
there any other considerations I need to be aware of?

Ben
Nov 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
You'll also need to be well versed with the managed extensions syntax to be
able to instantiate and use the C# classes.

Here is a simple intro from my web site - you'll find lots of others on
MSDN, CodeProject and other sites

http://www.voidnish.com/articles/Sho...de=mcppintro01

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Ben Terry" <bt@charter.net> wrote in message
news:O2**************@TK2MSFTNGP10.phx.gbl...
Hello,

I have a VS 2003.NET solution which consists of four c++ unmanaged legacy
projects. I am adding a new project to the solution which will be in c#.
What do I need to do to my c++ projects in order to call my c# modules from within c++? From what I understand, I need to convert my c++ code from
unmanaged to managed using the /clr switch (IJW). Is this correct? Are
there any other considerations I need to be aware of?

Ben

Nov 17 '05 #2

P: n/a
Two more things

(1) You'll need to do a lot of managed-unmanaged data marshalling on your
own

(2) This syntax is now more or less obsolete. In the next version of the
VC++ compiler, MS is giving us C++/CLI, though the older syntax will also be
supported but not recommended :-)

http://www.codeproject.com/managedcpp/cppcliintro01.asp - an intro to
C++/CLI
http://www.codeproject.com/managedcpp/cppcliintro01.asp - a blog entry on
whether you should use MC++ or not (in its current syntax)

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Nishant S" <ni**@nospam.asianetindia.com> wrote in message
news:ON**************@TK2MSFTNGP09.phx.gbl...
You'll also need to be well versed with the managed extensions syntax to be able to instantiate and use the C# classes.

Here is a simple intro from my web site - you'll find lots of others on
MSDN, CodeProject and other sites

http://www.voidnish.com/articles/Sho...de=mcppintro01

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Ben Terry" <bt@charter.net> wrote in message
news:O2**************@TK2MSFTNGP10.phx.gbl...
Hello,

I have a VS 2003.NET solution which consists of four c++ unmanaged legacy projects. I am adding a new project to the solution which will be in c#. What do I need to do to my c++ projects in order to call my c# modules

from
within c++? From what I understand, I need to convert my c++ code from
unmanaged to managed using the /clr switch (IJW). Is this correct? Are
there any other considerations I need to be aware of?

Ben


Nov 17 '05 #3

P: n/a
Damn [pasted the same URL for the blgo entry too]

The blog-entry URL is :-

http://blog.voidnish.com/index.php?p=11

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Nishant S" <ni**@nospam.asianetindia.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Two more things

(1) You'll need to do a lot of managed-unmanaged data marshalling on your
own

(2) This syntax is now more or less obsolete. In the next version of the
VC++ compiler, MS is giving us C++/CLI, though the older syntax will also be supported but not recommended :-)

http://www.codeproject.com/managedcpp/cppcliintro01.asp - an intro to
C++/CLI
http://www.codeproject.com/managedcpp/cppcliintro01.asp - a blog entry on
whether you should use MC++ or not (in its current syntax)

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Nishant S" <ni**@nospam.asianetindia.com> wrote in message
news:ON**************@TK2MSFTNGP09.phx.gbl...
You'll also need to be well versed with the managed extensions syntax to

be
able to instantiate and use the C# classes.

Here is a simple intro from my web site - you'll find lots of others on
MSDN, CodeProject and other sites

http://www.voidnish.com/articles/Sho...de=mcppintro01

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Ben Terry" <bt@charter.net> wrote in message
news:O2**************@TK2MSFTNGP10.phx.gbl...
Hello,

I have a VS 2003.NET solution which consists of four c++ unmanaged legacy projects. I am adding a new project to the solution which will be in c#. What do I need to do to my c++ projects in order to call my c# modules

from
within c++? From what I understand, I need to convert my c++ code from unmanaged to managed using the /clr switch (IJW). Is this correct? Are there any other considerations I need to be aware of?

Ben



Nov 17 '05 #4

P: n/a
Thanks for your help, Nishant. I enjoyed your website also. I have a
couple of follow-up questions:
1) All of the examples I've seen so far talk about creating managed c++.
What I am trying to do is use a C# class in an unmanaged C++ project that
has the managed extensions enabled (/clr). I'm using the gcroot template to
instantiate the managed "pointer". Do you know of some good examples of
this?

2) I have several legacy c++ projects in a .NET 2003 solution and a single
C# project. What is the correct c++ syntax to include the C# classes for
use in my legacy projects? Is this the correct way to do it?

Here's what I have in the header:

#using <mscorlib.dll>
#using <system.dll>
// PetToolTCPLib.dll is the output of my C# project.
// If this is part of the VS.NET solution that houses my C++ legacy code, do
I need to do this?
#using "PetToolTCPLib.dll"
using namespace PetToolTCPLib;
using namespace System;
gcroot<CToolMain*> m_pTCPTool; // CToolMain is a C# class in
PetToolTCPLib.dll

Here's what I have in the .cpp file (unmanaged legacy):
#pragma push_macro("new")
#undef new
m_pTCPTool = new CToolMain;
#pragma pop_macro("new")
"Nishant S" <ni**@nospam.asianetindia.com> wrote in message
news:OR**************@tk2msftngp13.phx.gbl...
Damn [pasted the same URL for the blgo entry too]

The blog-entry URL is :-

http://blog.voidnish.com/index.php?p=11

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Nishant S" <ni**@nospam.asianetindia.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Two more things

(1) You'll need to do a lot of managed-unmanaged data marshalling on your
own

(2) This syntax is now more or less obsolete. In the next version of the
VC++ compiler, MS is giving us C++/CLI, though the older syntax will also
be
supported but not recommended :-)

http://www.codeproject.com/managedcpp/cppcliintro01.asp - an intro to
C++/CLI
http://www.codeproject.com/managedcpp/cppcliintro01.asp - a blog entry

on whether you should use MC++ or not (in its current syntax)

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Nishant S" <ni**@nospam.asianetindia.com> wrote in message
news:ON**************@TK2MSFTNGP09.phx.gbl...
You'll also need to be well versed with the managed extensions syntax to
be
able to instantiate and use the C# classes.

Here is a simple intro from my web site - you'll find lots of others
on MSDN, CodeProject and other sites

http://www.voidnish.com/articles/Sho...de=mcppintro01

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Ben Terry" <bt@charter.net> wrote in message
news:O2**************@TK2MSFTNGP10.phx.gbl...
> Hello,
>
> I have a VS 2003.NET solution which consists of four c++ unmanaged

legacy
> projects. I am adding a new project to the solution which will be in c#.
> What do I need to do to my c++ projects in order to call my c#

modules from
> within c++? From what I understand, I need to convert my c++ code

from > unmanaged to managed using the /clr switch (IJW). Is this correct? Are > there any other considerations I need to be aware of?
>
> Ben
>
>



Nov 17 '05 #5

P: n/a
(1) MSDN has a couple of examples for using gcroot. Basically there is
nothing very complicated about using gcroot. Simply include <vcclr.h> and
you can use gcroot to have managed members in your native classes :-

class A
{
gcroot<String*> s;
};

(2) Yup, you need to use #using on the C# DLL from your C++ code

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Ben Terry" <bt@charter.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Thanks for your help, Nishant. I enjoyed your website also. I have a
couple of follow-up questions:
1) All of the examples I've seen so far talk about creating managed c++.
What I am trying to do is use a C# class in an unmanaged C++ project that
has the managed extensions enabled (/clr). I'm using the gcroot template to instantiate the managed "pointer". Do you know of some good examples of
this?

2) I have several legacy c++ projects in a .NET 2003 solution and a single
C# project. What is the correct c++ syntax to include the C# classes for
use in my legacy projects? Is this the correct way to do it?

Here's what I have in the header:

#using <mscorlib.dll>
#using <system.dll>
// PetToolTCPLib.dll is the output of my C# project.
// If this is part of the VS.NET solution that houses my C++ legacy code, do I need to do this?
#using "PetToolTCPLib.dll"
using namespace PetToolTCPLib;
using namespace System;
gcroot<CToolMain*> m_pTCPTool; // CToolMain is a C# class in
PetToolTCPLib.dll

Here's what I have in the .cpp file (unmanaged legacy):
#pragma push_macro("new")
#undef new
m_pTCPTool = new CToolMain;
#pragma pop_macro("new")
"Nishant S" <ni**@nospam.asianetindia.com> wrote in message
news:OR**************@tk2msftngp13.phx.gbl...
Damn [pasted the same URL for the blgo entry too]

The blog-entry URL is :-

http://blog.voidnish.com/index.php?p=11

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Nishant S" <ni**@nospam.asianetindia.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Two more things

(1) You'll need to do a lot of managed-unmanaged data marshalling on your own

(2) This syntax is now more or less obsolete. In the next version of the VC++ compiler, MS is giving us C++/CLI, though the older syntax will also
be
supported but not recommended :-)

http://www.codeproject.com/managedcpp/cppcliintro01.asp - an intro to
C++/CLI
http://www.codeproject.com/managedcpp/cppcliintro01.asp - a blog entry on whether you should use MC++ or not (in its current syntax)

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Nishant S" <ni**@nospam.asianetindia.com> wrote in message
news:ON**************@TK2MSFTNGP09.phx.gbl...
> You'll also need to be well versed with the managed extensions
syntax
to be
> able to instantiate and use the C# classes.
>
> Here is a simple intro from my web site - you'll find lots of others on > MSDN, CodeProject and other sites
>
> http://www.voidnish.com/articles/Sho...de=mcppintro01
>
> --
> Regards,
> Nish [VC++ MVP]
> http://www.voidnish.com /* MVP tips tricks and essays web site */
>
>
> "Ben Terry" <bt@charter.net> wrote in message
> news:O2**************@TK2MSFTNGP10.phx.gbl...
> > Hello,
> >
> > I have a VS 2003.NET solution which consists of four c++ unmanaged
legacy
> > projects. I am adding a new project to the solution which will be in c#.
> > What do I need to do to my c++ projects in order to call my c# modules > from
> > within c++? From what I understand, I need to convert my c++ code

from
> > unmanaged to managed using the /clr switch (IJW). Is this

correct? Are
> > there any other considerations I need to be aware of?
> >
> > Ben
> >
> >
>
>



Nov 17 '05 #6

P: n/a
Thanks!

"Nishant S" <ni**@nospam.asianetindia.com> wrote in message
news:ut**************@TK2MSFTNGP11.phx.gbl...
(1) MSDN has a couple of examples for using gcroot. Basically there is
nothing very complicated about using gcroot. Simply include <vcclr.h> and
you can use gcroot to have managed members in your native classes :-

class A
{
gcroot<String*> s;
};

(2) Yup, you need to use #using on the C# DLL from your C++ code

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Ben Terry" <bt@charter.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Thanks for your help, Nishant. I enjoyed your website also. I have a
couple of follow-up questions:
1) All of the examples I've seen so far talk about creating managed c++.
What I am trying to do is use a C# class in an unmanaged C++ project that
has the managed extensions enabled (/clr). I'm using the gcroot template
to
instantiate the managed "pointer". Do you know of some good examples of
this?

2) I have several legacy c++ projects in a .NET 2003 solution and a
single C# project. What is the correct c++ syntax to include the C# classes for use in my legacy projects? Is this the correct way to do it?

Here's what I have in the header:

#using <mscorlib.dll>
#using <system.dll>
// PetToolTCPLib.dll is the output of my C# project.
// If this is part of the VS.NET solution that houses my C++ legacy code, do
I need to do this?
#using "PetToolTCPLib.dll"
using namespace PetToolTCPLib;
using namespace System;
gcroot<CToolMain*> m_pTCPTool; // CToolMain is a C# class in
PetToolTCPLib.dll

Here's what I have in the .cpp file (unmanaged legacy):
#pragma push_macro("new")
#undef new
m_pTCPTool = new CToolMain;
#pragma pop_macro("new")
"Nishant S" <ni**@nospam.asianetindia.com> wrote in message
news:OR**************@tk2msftngp13.phx.gbl...
Damn [pasted the same URL for the blgo entry too]

The blog-entry URL is :-

http://blog.voidnish.com/index.php?p=11

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Nishant S" <ni**@nospam.asianetindia.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> Two more things
>
> (1) You'll need to do a lot of managed-unmanaged data marshalling on

your
> own
>
> (2) This syntax is now more or less obsolete. In the next version of

the > VC++ compiler, MS is giving us C++/CLI, though the older syntax will

also
be
> supported but not recommended :-)
>
> http://www.codeproject.com/managedcpp/cppcliintro01.asp - an intro to > C++/CLI
> http://www.codeproject.com/managedcpp/cppcliintro01.asp - a blog entry on
> whether you should use MC++ or not (in its current syntax)
>
> --
> Regards,
> Nish [VC++ MVP]
> http://www.voidnish.com /* MVP tips tricks and essays web site */
>
>
> "Nishant S" <ni**@nospam.asianetindia.com> wrote in message
> news:ON**************@TK2MSFTNGP09.phx.gbl...
> > You'll also need to be well versed with the managed extensions syntax
to
> be
> > able to instantiate and use the C# classes.
> >
> > Here is a simple intro from my web site - you'll find lots of
others on
> > MSDN, CodeProject and other sites
> >
> > http://www.voidnish.com/articles/Sho...de=mcppintro01
> >
> > --
> > Regards,
> > Nish [VC++ MVP]
> > http://www.voidnish.com /* MVP tips tricks and essays web site */
> >
> >
> > "Ben Terry" <bt@charter.net> wrote in message
> > news:O2**************@TK2MSFTNGP10.phx.gbl...
> > > Hello,
> > >
> > > I have a VS 2003.NET solution which consists of four c++
unmanaged > legacy
> > > projects. I am adding a new project to the solution which will be in
> c#.
> > > What do I need to do to my c++ projects in order to call my c#

modules
> > from
> > > within c++? From what I understand, I need to convert my c++

code from
> > > unmanaged to managed using the /clr switch (IJW). Is this

correct? Are
> > > there any other considerations I need to be aware of?
> > >
> > > Ben
> > >
> > >
> >
> >
>
>



Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.