473,395 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Calling managed VC++ from C#

Hi all, sorry for the cross group spam but my question does really
fall into both groups. Here's my issue.

I have a Visual C++, CLR Class Library with a public class and a
public method in a solution. Also in the solution is a c# console app.
I have referenced the c++ project from the c# project and can
instanciate the vc++ class, however I cannot see my vc++ method from
my c# project.

As I understood it, as this was all managed code, that was all I
needed to do....

Anyone got any hints as to what's gone wrong?

Thanks
Andy

Oct 9 '07 #1
4 1430

"Andy" <go****@jenkinsonline.co.ukwrote in message
news:11**********************@22g2000hsm.googlegro ups.com...
Hi all, sorry for the cross group spam but my question does really
fall into both groups. Here's my issue.

I have a Visual C++, CLR Class Library with a public class and a
public method in a solution. Also in the solution is a c# console app.
I have referenced the c++ project from the c# project and can
instanciate the vc++ class, however I cannot see my vc++ method from
my c# project.

As I understood it, as this was all managed code, that was all I
needed to do....

Anyone got any hints as to what's gone wrong?
Which version of C++? 2002, 2003, or 2005? 2005's support for .NET is
called C++/CLI, not managed VC++. The older Managed Extensions for C++ are
buggy (but not causing your problem).

I suspect you forgot to declare the access for your member function. Try
this:

public ref class MyClass
{
public: // <- this is important
void CallMe(void);
};

or

public ref struct MyClass // still a C# "class", not "struct". For C#
"struct" you'd use "value class" or "value struct"
{
// in a C++ struct, things are public by default
void CallMe(void);
};
>
Thanks
Andy

Oct 9 '07 #2
On Oct 9, 3:39 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"Andy" <goo...@jenkinsonline.co.ukwrote in message

news:11**********************@22g2000hsm.googlegro ups.com...
Hi all, sorry for the cross group spam but my question does really
fall into both groups. Here's my issue.
I have a Visual C++, CLR Class Library with a public class and a
public method in a solution. Also in the solution is a c# console app.
I have referenced the c++ project from the c# project and can
instanciate the vc++ class, however I cannot see my vc++ method from
my c# project.
As I understood it, as this was all managed code, that was all I
needed to do....
Anyone got any hints as to what's gone wrong?

Which version of C++? 2002, 2003, or 2005? 2005's support for .NET is
called C++/CLI, not managed VC++. The older Managed Extensions for C++ are
buggy (but not causing your problem).

I suspect you forgot to declare the access for your member function. Try
this:

public ref class MyClass
{
public: // <- this is important
void CallMe(void);

};

or

public ref struct MyClass // still a C# "class", not "struct". For C#
"struct" you'd use "value class" or "value struct"
{
// in a C++ struct, things are public by default
void CallMe(void);

};
Thanks
Andy- Hide quoted text -

- Show quoted text -
Hi Ben and thanks for replying.

Sorry, you are right I am using VS 2005 and C++/CLI and after much
messing about I managed to get it to work. Basically I removed the
header file for my cpp class definition and bingo, it all worked. Not
sure why and the old school c/c++ guy that sits behind be said that
removing the .h was a bad idea and it shouldn't work...

To my next problem..... My C++/CLI code is trying to return a type
defined in C# but I get a complilation exception
error C2440 'return' : cannot convert from '<type>' to '<type>'

where type is the same thing! :-(

Andy

Oct 11 '07 #3

"Andy" <go****@jenkinsonline.co.ukwrote in message
news:11**********************@d55g2000hsg.googlegr oups.com...
On Oct 9, 3:39 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
>"Andy" <goo...@jenkinsonline.co.ukwrote in message

news:11**********************@22g2000hsm.googlegr oups.com...
Hi all, sorry for the cross group spam but my question does really
fall into both groups. Here's my issue.
I have a Visual C++, CLR Class Library with a public class and a
public method in a solution. Also in the solution is a c# console app.
I have referenced the c++ project from the c# project and can
instanciate the vc++ class, however I cannot see my vc++ method from
my c# project.
As I understood it, as this was all managed code, that was all I
needed to do....
Anyone got any hints as to what's gone wrong?

Which version of C++? 2002, 2003, or 2005? 2005's support for .NET is
called C++/CLI, not managed VC++. The older Managed Extensions for C++
are
buggy (but not causing your problem).

I suspect you forgot to declare the access for your member function. Try
this:

public ref class MyClass
{
public: // <- this is important
void CallMe(void);

};

or

public ref struct MyClass // still a C# "class", not "struct". For C#
"struct" you'd use "value class" or "value struct"
{
// in a C++ struct, things are public by default
void CallMe(void);

};
Thanks
Andy- Hide quoted text -

- Show quoted text -

Hi Ben and thanks for replying.

Sorry, you are right I am using VS 2005 and C++/CLI and after much
messing about I managed to get it to work. Basically I removed the
header file for my cpp class definition and bingo, it all worked. Not
sure why and the old school c/c++ guy that sits behind be said that
removing the .h was a bad idea and it shouldn't work...

To my next problem..... My C++/CLI code is trying to return a type
defined in C# but I get a complilation exception
error C2440 'return' : cannot convert from '<type>' to '<type>'

where type is the same thing! :-(
Is it a C# struct or class?

If a class (reference type), make sure you haven't forgotten the ^ (meaning
tracking handle).
>
Andy

Oct 11 '07 #4
Sorry, you are right I am using VS 2005 and C++/CLI and after much
messing about I managed to get it to work. Basically I removed the
header file for my cpp class definition and bingo, it all worked. Not
sure why and the old school c/c++ guy that sits behind be said that
removing the .h was a bad idea and it shouldn't work...
And just to mention, I've got a lot of code with ref classes declared in
headers and member functions defined in implementation files, so that should
work.

Oct 12 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Shai Levi | last post by:
Hi, I'm trying to migrate native c++ class to managed c++ class. The native class header definition looks as: class NativeClass { public: typedef void (CbFunc1)(int n,void* p);
1
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code...
1
by: Bern McCarty | last post by:
What do you make of this? I cannot tell for sure but it almost seems as the the transition thunk to get back from the native bool method to the managed caller is looking at eax and, if any bit is...
3
by: Yoavo | last post by:
Hi, I have an C++ MFC application and a c# DLL (which contains a Form class). I want to invoke the c# dialog from the C++ application. How do I do it ? thanks, Yoav.
9
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
7
by: Andreas Reiff | last post by:
Hey! I have a managed c++ app (actually, the app is mixed managed/unmanaged, but this happens in the managed part) that dynamically generates some program in c# (with CSharpCodeProvider). The...
11
by: briankirkpatrick | last post by:
Forgive me if my post seems a little amateurish... I'm requesting assistance from some of you smart folks out there to get the managed calls write that meet the specification in the esa.h for...
3
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC...
4
by: Andy | last post by:
Hi all, sorry for the cross group spam but my question does really fall into both groups. Here's my issue. I have a Visual C++, CLR Class Library with a public class and a public method in a...
16
by: Jaco Naude | last post by:
Hi there, This is my first post over here and I hope someone can give me some guidance. I'm trying to embed Python into a Visual C++ 2008 application and I'm getting linker problems. I've...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.