473,386 Members | 1,647 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,386 software developers and data experts.

C++ interop /CLR confusion

Hello,

I wonder if anyone can help lift the cloud of confusion hanging over me
at the moment ;-)

I have a load of unmanaged code in a project that I am compiling NOT
USING /CLR

I have some managed code and I want to call some of the functions in
the unmanaged code. So I create a file with mixed C++ and C++/CLI code

Now, the function signatures of the unamaged code contain
structures/classes that are declared in their own headers

//Unmanaged....
struct someData
{
int a;
double b;
};

struct bigstruct
{
//lots of data......
};

funcDoSomething(std::vector<somedata>& data, bigStruct* bigstruct)
{
.....
}

In the managed/mixed code I #include the appropriate headers and go
about constructing the data into the unmanged C++ structs [from managed
data types say from a Form] so that I can call the functions....

this will involve push_back calls onto a vector and newing in a struct
on the unmanaged HEAP.

What my question is - if I compile the code with /CLR - what actually
is going on behind the scenes - is the compiler turning the C++ code
into MSIL?? If so how does this fit in with using things like a call to
"new" and std::vector.

Do I have to pin the vector before passing it to the function??

Is it ok to just pass in the pointer to bigStruct??

Is there a performance hit from following this approach?

Is this indeed the correct approach to take?

Many thanks for any help you can offer me.

Oct 19 '06 #1
3 2150
You can write managed wrapper classes for native classes and redirect all
method calls. The function calls are marshalled so you can call a native
function (with proper parameter and return value marshalling) from managed
code.
--
Regards
Sheng Jiang

Microsoft Most Valuable Professional in Visual C++
http://www.jiangsheng.net
http://blog.joycode.com/jiangsheng/
<aj******@hushmail.com????
news:11**********************@h48g2000cwc.googlegr oups.com...
Hello,

I wonder if anyone can help lift the cloud of confusion hanging over me
at the moment ;-)

I have a load of unmanaged code in a project that I am compiling NOT
USING /CLR

I have some managed code and I want to call some of the functions in
the unmanaged code. So I create a file with mixed C++ and C++/CLI code

Now, the function signatures of the unamaged code contain
structures/classes that are declared in their own headers

//Unmanaged....
struct someData
{
int a;
double b;
};

struct bigstruct
{
//lots of data......
};

funcDoSomething(std::vector<somedata>& data, bigStruct* bigstruct)
{
....
}

In the managed/mixed code I #include the appropriate headers and go
about constructing the data into the unmanged C++ structs [from managed
data types say from a Form] so that I can call the functions....

this will involve push_back calls onto a vector and newing in a struct
on the unmanaged HEAP.

What my question is - if I compile the code with /CLR - what actually
is going on behind the scenes - is the compiler turning the C++ code
into MSIL?? If so how does this fit in with using things like a call to
"new" and std::vector.

Do I have to pin the vector before passing it to the function??

Is it ok to just pass in the pointer to bigStruct??

Is there a performance hit from following this approach?

Is this indeed the correct approach to take?

Many thanks for any help you can offer me.

Oct 19 '06 #2

jiangsheng[MVP] wrote:
You can write managed wrapper classes for native classes and redirect all
method calls. The function calls are marshalled so you can call a native
function (with proper parameter and return value marshalling) from managed
code.
--
Regards
Sheng Jiang
Many thanks for your reply.

The thing is all I really want to do is call the umanaged code - I dont
really want to create a managed wrapper for it as its not going to be
used by other managed classes so its not really worth the effort.

My enquiry is to what goes on "behind the scenes" if I construct
unmanaged C++ classes in a mixed code file compiled with /clr and call
unmanaged functions. In particular how I handle things on the unmanaged
heap and STL classes like vector.

Oct 19 '06 #3
compiled with /clr does not move your code to managed world automatically.
Only managed classes (ref class, interface class, etc) and functions after
a #pragra managed statement will be compiled into IL and visible to other
managed assemblies. So you need to write your interface functions (much like
DLL exports) and /or classes for managed assemblies.

--
Regards
Sheng Jiang

Microsoft Most Valuable Professional in Visual C++
http://www.jiangsheng.net
http://blog.joycode.com/jiangsheng/
<aj******@hushmail.com????
news:11**********************@f16g2000cwb.googlegr oups.com...
>
jiangsheng[MVP] wrote:
You can write managed wrapper classes for native classes and redirect
all
method calls. The function calls are marshalled so you can call a native
function (with proper parameter and return value marshalling) from
managed
code.
--
Regards
Sheng Jiang

Many thanks for your reply.

The thing is all I really want to do is call the umanaged code - I dont
really want to create a managed wrapper for it as its not going to be
used by other managed classes so its not really worth the effort.

My enquiry is to what goes on "behind the scenes" if I construct
unmanaged C++ classes in a mixed code file compiled with /clr and call
unmanaged functions. In particular how I handle things on the unmanaged
heap and STL classes like vector.

Oct 20 '06 #4

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

Similar topics

0
by: keefah | last post by:
Hi, I'm writing a C# web app that uses Outlook to send email. I use a reference to the Microsoft Outlook 11.0 Object Library, but it's giving me problems. I tracked down some stuff on the Net...
0
by: lacour | last post by:
I can't seem to figure out the difference between adding a COM dll reference in VS2003 and by using TLBIMP. I have a COM dll that references another COM dll, and I want the syntax of my...
8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
8
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be...
4
by: Uraza | last post by:
I am creating an application that is a COM class that will be accessed by that route. It doesn't seem to be being called when I try it. I have created the DLL in the IDE and it also creates the...
7
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed...
2
by: JC | last post by:
Anybody knows what problem has this code? I think, in the Garbage Collector? You know the Solution? The program in the test's case, whit 350 contacts, run OK before number 86. The error is a...
1
by: allbelonging | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox...
5
by: John | last post by:
I would like to ask a question that is obvious to all people porting applications from the "traditional" C\VB6 interop scheme choosing C# vs VB.NET. We have a math library in C which...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.