473,806 Members | 2,845 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 1448

"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
2771
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
2915
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.
9
3123
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 this, I want to use it. Is it possible to call Managed class functions from Unmanaged class? How to do it? I did something like this. I declared a managed class (in C++ CLI) called as MyManagedClass whose
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
1622
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
3791
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
9597
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
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
6877
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
5546
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...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3850
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
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.