473,701 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

new to managed c++, interop questions

Hello,

I'm starting to investigate cs, managed c++ and interoperating with a very
large unmanaged code base. We are going to use Windows Forms (written in
cs) to replace our old fashioned GUI. The guts will remain in unmanaged
c++. So I need to write public managed c++ wrapper classes for the couple
of interfaces the unmanaged stuff needs to expose for the GUI.

Questions:

1) I export a function, say CreateFooInterf ace, from my unmanaged code
(extern "C"). It my managed wrapper class I have a private pointer object
declared as IFoo* m_pFoo. Call the wrapper class tMgdFoo. In tMgdFoo ctor
I need to create an m_pFoo. If CreateFooInterf ace returns a pointer to
IFoo, I can successfully write:

m_pFoo = CreateFooInterf ace();

However, if I declare CreateFooInterf ace as: long CreateFooInterf ace( IFoo**
ppFoo ), and attempt to write:

CreateFooInterf ace( &m_pFoo );

in my tMgdFoo ctor, then I get a compiler error saying it can't convert from
IFoo * __gc * to IFoo**. Why does the former work, but the latter does not?
Is it because I can't take the address of a member variable of a __gc class?
Or is there a mechanism to allow me to do that? I guess I don't understand
the rules about passing around (or back) pointers to memory allocated by the
c run time.

2) In my test app to try all this out I have a cs exe, a dll in which
managed c++ code only resides, and the original unmanaged dll. If I debug
the cs exe and turn on unmanaged code debugging I can place break points in
my unmanaged dll code and I will hit them. The problem is that doing any
debugging there takes a very very long time as the IDE is extremely slow to
respond. Obviously something is going on under the covers when the outer
layer (app) is running in the clr but one is debugging the unmanaged stuff.
So I turned it around and specified that the project I was debugging was the
unmanaged dll and then I specified the cs exe as the app to execute to start
the debugging session. When I did this I was not able to hit breakpoints I
had set in my unmanaged code.

So the question is: How can I reasonably debug unmanaged code when the app
that eventually causes that dll to load is a cs app? It is not really
usable as it is, for instance one line of code of the sort std::cout <<
"line of text" << std::endl; when executed in this manner results in the
characters displaying on the console one by one, extremely slowly. There
must be a better way.

Thanks for the help,

Eric Twietmeyer
Nov 16 '05 #1
1 2122
Hi,
Answer to first part of your question
This is because m_pFoo is a member of a gc class , so it exists on the
GC(Managed) heap. Taking its address gives a managed pointer..so the
compiler is complaining (valid)
Imagine u pass this pointer to a unmanaged function, and in the meantime
Garbage collection happens..this may move the object.. and so the address
is no longer valid..

So u need to pin the object..before u can pass the managed pointer to a
unmanaged func..
look up __pin* in MSDN..
--------------------
From: "Eric Twietmeyer" <no******@noisp .com>
Subject: new to managed c++, interop questions
Date: Fri, 3 Oct 2003 13:30:20 -0700
Lines: 54
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <ep************ **@TK2MSFTNGP12 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.vc
NNTP-Posting-Host: s235.207-182-32-net.desert.net 207.182.32.235
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vc:29008
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vc

Hello,

I'm starting to investigate cs, managed c++ and interoperating with a very
large unmanaged code base. We are going to use Windows Forms (written in
cs) to replace our old fashioned GUI. The guts will remain in unmanaged
c++. So I need to write public managed c++ wrapper classes for the couple
of interfaces the unmanaged stuff needs to expose for the GUI.

Questions:

1) I export a function, say CreateFooInterf ace, from my unmanaged code
(extern "C"). It my managed wrapper class I have a private pointer object
declared as IFoo* m_pFoo. Call the wrapper class tMgdFoo. In tMgdFoo ctor
I need to create an m_pFoo. If CreateFooInterf ace returns a pointer to
IFoo, I can successfully write:

m_pFoo = CreateFooInterf ace();

However, if I declare CreateFooInterf ace as: long CreateFooInterf ace( IFoo**ppFoo ), and attempt to write:

CreateFooInter face( &m_pFoo );

in my tMgdFoo ctor, then I get a compiler error saying it can't convert fromIFoo * __gc * to IFoo**. Why does the former work, but the latter does not?Is it because I can't take the address of a member variable of a __gc class?Or is there a mechanism to allow me to do that? I guess I don't understand
the rules about passing around (or back) pointers to memory allocated by thec run time.

2) In my test app to try all this out I have a cs exe, a dll in which
managed c++ code only resides, and the original unmanaged dll. If I debug
the cs exe and turn on unmanaged code debugging I can place break points in
my unmanaged dll code and I will hit them. The problem is that doing any
debugging there takes a very very long time as the IDE is extremely slow to
respond. Obviously something is going on under the covers when the outer
layer (app) is running in the clr but one is debugging the unmanaged stuff.
So I turned it around and specified that the project I was debugging was theunmanaged dll and then I specified the cs exe as the app to execute to startthe debugging session. When I did this I was not able to hit breakpoints I
had set in my unmanaged code.

So the question is: How can I reasonably debug unmanaged code when the app
that eventually causes that dll to load is a cs app? It is not really
usable as it is, for instance one line of code of the sort std::cout <<
"line of text" << std::endl; when executed in this manner results in the
characters displaying on the console one by one, extremely slowly. There
must be a better way.

Thanks for the help,

Eric Twietmeyer


Nov 16 '05 #2

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

Similar topics

16
14127
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the byteArray and afterwards see the changes in C#. (if you wanna know more details: the goal is to write the content of an existing char-array in c++ precisely into the passed byteArray, so that after the function has proceded the content of the...
1
9457
by: Zapbbx | last post by:
I have a 3rd party application that can reference external dll's. The dll's have to be written in unmanaged code with an exported function I can reference and call. I would like it to call a C# dll file but it cant call a managed C# dll. I need to create an unmanaged C++.net wrapper for a Managed C# dll. Does anyone know how to do this? can you please give me a simple example of what the C++.Net code would look like to do this Take for...
7
7565
by: Bob Rock | last post by:
Hello, converting from the managed to the unmanaged world (and viceversa strings) and byte arrays is something I do often and I'd like to identify the most correct and efficient way to do it. Also, I was wondering could there be issues in not making copies when converting??? I was thinking, when "pointing" to the same data with both managed and unmanaged strings/arrays couldn't there be issues such as the garbage collector trying to...
0
977
by: Gerhard Menzl | last post by:
I got no response to this in microsoft.public.dotnet.framework.interop, and since it is a C++-related problem, I am now trying it here: I am using an Interop assembly for communication between my Managed C++ application and an ATL-based COM server. The Interop assembly was created with Visual Studio, and the COM server is third-party software that is not under my control. One of the COM interfaces supported by the server has a method...
3
1955
by: Tommy Svensson \(InfoGrafix\) | last post by:
I've been instructed to work againt a huge unmanaged C++ API from a C# application. Now, the only way, as I've understood it, is to go the Managed Extensions for C++ way. This means I have to write a wrapper between unmanaged API and my managed app. Now on to the question: If there's an unmanaged API class called X with a defined method
1
2133
by: Ryan Melville | last post by:
Hi, I need to use WIA (Windows Image Acquisition) from managed C++. Is there a "new and improved" way to access WIA from managed C++ (i.e., through .net)? Or, is it the same COM calls as from unmanaged C++? If it's the same COM calls, is there a "new and improved" way to access COM through managed C++? Or, do I do the same CComPtr magic as with unmanaged C++? Or, can I not use ATL facilities from managed C++ and I would have to...
2
2090
by: Hans Wien | last post by:
I have to write a lot of data to excel for analysts who use it further from there but would like to use managed C++ and not C# since a lot of code is involved which already exists now in managed C++. In C# I could handle it easily as you can see in this sample: using Excel = Microsoft.Office.Interop.Excel; .... private Excel.Application thisApplication; private Excel.Workbook myWorkbook1;
6
1644
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hello gurus, I have the following C# function signature: void TheFunction(Dictionary<string, MyClassObjdicName, out int nOne, out int nTwo, out int nThree, out int nFour); And it works fine. I'm trying to write a managed C++ function that will save the save signature, but till now I've got all kind of compiler error.
20
2298
by: =?Utf-8?B?VGhlTWFkSGF0dGVy?= | last post by:
Sorry to bring up a topic that is just flogging a dead horse.... but... On the topic of memory management.... I am doing some file parcing that has to be done as quick as posible, but what I have found hasnt been encouraging... I found that the *quickest* way is to use a struct to retrieve fixed length packets out of the file, but structs get placed on the stack! In one of the books I read, the stack is only about 1mb, so I would...
0
8736
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...
1
8977
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
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
6571
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
5904
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
4410
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
4662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2398
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2035
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.