473,796 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1621

"Andy" <go****@jenkins online.co.ukwro te in message
news:11******** **************@ 22g2000hsm.goog legroups.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.no spamwrote:
"Andy" <goo...@jenkins online.co.ukwro te in message

news:11******** **************@ 22g2000hsm.goog legroups.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****@jenkins online.co.ukwro te in message
news:11******** **************@ d55g2000hsg.goo glegroups.com.. .
On Oct 9, 3:39 pm, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
>"Andy" <goo...@jenkins online.co.ukwro te in message

news:11******* *************** @22g2000hsm.goo glegroups.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
2770
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
2914
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 written in C#. When the app calls my unmanaged functions, they work fine. But as soon as my unmanaged functions call managed functions (in the same source file!), the app reports an "unknown exception" error.
1
1604
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 set, normalizing it to 0x00000001. If it wants to normalize the value then it should only operate on the al register since that's all that the native bool method uses to hold the return value. Is this a known VC 7.1 bug? Is there a hotfix...
3
3893
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.
7
3150
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 problem now is that somehow I get runtime errors when trying to pass a function (via delegates) into the c# code in order to make c# call back that function. The message box says: "An unhandled exeption of type 'System.ArgumentException' occurred...
11
3203
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 Esa_Init. When I make a call, VS2005 reports "AccessViolationException" and refers to the 4th parameter (EsaT_State_Handle). I don't know how to define nor pass this reference correctly to the legacy DLL. What am I doing wrong? Thanks in...
3
4713
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 application. Furthermore, I use a pointer to an unmanaged function to jump back into the managed dll. The managed part is basically a remoting enhancement which asynchronly
4
1448
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 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,...
16
3790
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 compiled a DLL of the Python source code using the pythoncode VC++ project in the PCbuild folder of the source download and this works 100% without any warnings etc. I've done this in Debug and Release mode without any problems.
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10468
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.