473,472 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

passing references between C# and managed C++

I'm trying to pass a variable by reference from a C# program to a
managed C++ wrapper. Something like this:

------------C++--------------
void GimmeByRef(int &reference);
-----------------------------

------------C#---------------
GimmeByRef(ref referenceVariable);
-----------------------------

However, I keep getting errors relating to not being able to convert
'ref uint' to 'uint*'. What am I doing wrong?

Lee Crabtree
Jan 30 '06 #1
8 1956
Change c++ to

void GimmeByRef(int __gc & reference);

?
"Lee Crabtree" <lc*******@goisi.com> wrote in message
news:Og**************@TK2MSFTNGP09.phx.gbl...
I'm trying to pass a variable by reference from a C# program to a managed
C++ wrapper. Something like this:

------------C++--------------
void GimmeByRef(int &reference);
-----------------------------

------------C#---------------
GimmeByRef(ref referenceVariable);
-----------------------------

However, I keep getting errors relating to not being able to convert 'ref
uint' to 'uint*'. What am I doing wrong?

Lee Crabtree

Jan 30 '06 #2
Lee Crabtree wrote:
I'm trying to pass a variable by reference from a C# program to a
managed C++ wrapper. Something like this:

------------C++--------------
void GimmeByRef(int &reference);
-----------------------------

------------C#---------------
GimmeByRef(ref referenceVariable);
-----------------------------

However, I keep getting errors relating to not being able to convert
'ref uint' to 'uint*'. What am I doing wrong?

Lee Crabtree


Well, trying an IntPtr didn't do any good. Converting a 'ref
System.IntPtr' to an 'int*' doesn't work any better than before.

I think the problem is somehow related to the fact that 'ref' in C#
doesn't equate to '&' in C++. What's the managed C++ equivalent of the
'ref' keyword?

Lee Crabtree
Jan 30 '06 #3
As per my previous post I think you need 'int __gc&' to make it a managed
reference. 'int&' is an unmanaged reference which is basically an unmanaged
pointer - hence the compiler complaint about int*.

"Lee Crabtree" <lc*******@goisi.com> wrote in message
news:OD**************@TK2MSFTNGP10.phx.gbl...
Lee Crabtree wrote:
I'm trying to pass a variable by reference from a C# program to a managed
C++ wrapper. Something like this:

------------C++--------------
void GimmeByRef(int &reference);
-----------------------------

------------C#---------------
GimmeByRef(ref referenceVariable);
-----------------------------

However, I keep getting errors relating to not being able to convert 'ref
uint' to 'uint*'. What am I doing wrong?

Lee Crabtree


Well, trying an IntPtr didn't do any good. Converting a 'ref
System.IntPtr' to an 'int*' doesn't work any better than before.

I think the problem is somehow related to the fact that 'ref' in C#
doesn't equate to '&' in C++. What's the managed C++ equivalent of the
'ref' keyword?

Lee Crabtree

Jan 30 '06 #4
Clive Dixon wrote:
As per my previous post I think you need 'int __gc&' to make it a managed
reference. 'int&' is an unmanaged reference which is basically an unmanaged
pointer - hence the compiler complaint about int*.

"Lee Crabtree" <lc*******@goisi.com> wrote in message
news:OD**************@TK2MSFTNGP10.phx.gbl...
Lee Crabtree wrote:
I'm trying to pass a variable by reference from a C# program to a managed
C++ wrapper. Something like this:

------------C++--------------
void GimmeByRef(int &reference);
-----------------------------

------------C#---------------
GimmeByRef(ref referenceVariable);
-----------------------------

However, I keep getting errors relating to not being able to convert 'ref
uint' to 'uint*'. What am I doing wrong?

Lee Crabtree

Well, trying an IntPtr didn't do any good. Converting a 'ref
System.IntPtr' to an 'int*' doesn't work any better than before.

I think the problem is somehow related to the fact that 'ref' in C#
doesn't equate to '&' in C++. What's the managed C++ equivalent of the
'ref' keyword?

Lee Crabtree



Yeah, we must have posted pretty close together...Thunderbird didn't
show a new post. You, sir, were correct, and I salute you for it.

Lee Crabtree
Jan 30 '06 #5

"Lee Crabtree" <lc*******@goisi.com> wrote in message
news:Og**************@TK2MSFTNGP09.phx.gbl...
| I'm trying to pass a variable by reference from a C# program to a
| managed C++ wrapper. Something like this:
|
| ------------C++--------------
| void GimmeByRef(int &reference);
| -----------------------------
|
| ------------C#---------------
| GimmeByRef(ref referenceVariable);
| -----------------------------
|
| However, I keep getting errors relating to not being able to convert
| 'ref uint' to 'uint*'. What am I doing wrong?
|
| Lee Crabtree

void GimmeByRef(int __gc &reference)
or
void GimmeByRef(int __gc *reference)

another option is to pass a pointer in an unsafe context.

Willy.
Jan 30 '06 #6
Adding __gc works fine in VS2003 and it also works if you use the
/clr:oldSyntax compiler option in VS2005. However, how do you do it using
the new syntax in VS2005 (with just /clr as the compiler option)?
"Clive Dixon" wrote:
Change c++ to

void GimmeByRef(int __gc & reference);

?
"Lee Crabtree" <lc*******@goisi.com> wrote in message
news:Og**************@TK2MSFTNGP09.phx.gbl...
I'm trying to pass a variable by reference from a C# program to a managed
C++ wrapper. Something like this:

------------C++--------------
void GimmeByRef(int &reference);
-----------------------------

------------C#---------------
GimmeByRef(ref referenceVariable);
-----------------------------

However, I keep getting errors relating to not being able to convert 'ref
uint' to 'uint*'. What am I doing wrong?

Lee Crabtree


Mar 21 '06 #7
Use a "tracking reference", this will be emitted as a managed pointer in IL.

func(int% reference)

Willy.

"Matt Sawyer" <Ma********@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
| Adding __gc works fine in VS2003 and it also works if you use the
| /clr:oldSyntax compiler option in VS2005. However, how do you do it using
| the new syntax in VS2005 (with just /clr as the compiler option)?
|
|
| "Clive Dixon" wrote:
|
| > Change c++ to
| >
| > void GimmeByRef(int __gc & reference);
| >
| > ?
| >
| >
| > "Lee Crabtree" <lc*******@goisi.com> wrote in message
| > news:Og**************@TK2MSFTNGP09.phx.gbl...
| > > I'm trying to pass a variable by reference from a C# program to a
managed
| > > C++ wrapper. Something like this:
| > >
| > > ------------C++--------------
| > > void GimmeByRef(int &reference);
| > > -----------------------------
| > >
| > > ------------C#---------------
| > > GimmeByRef(ref referenceVariable);
| > > -----------------------------
| > >
| > > However, I keep getting errors relating to not being able to convert
'ref
| > > uint' to 'uint*'. What am I doing wrong?
| > >
| > > Lee Crabtree
| >
| >
| >
Mar 22 '06 #8
That did the trick, thank you!!!

"Willy Denoyette [MVP]" wrote:
Use a "tracking reference", this will be emitted as a managed pointer in IL.

func(int% reference)

Willy.

"Matt Sawyer" <Ma********@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
| Adding __gc works fine in VS2003 and it also works if you use the
| /clr:oldSyntax compiler option in VS2005. However, how do you do it using
| the new syntax in VS2005 (with just /clr as the compiler option)?
|
|
| "Clive Dixon" wrote:
|
| > Change c++ to
| >
| > void GimmeByRef(int __gc & reference);
| >
| > ?
| >
| >
| > "Lee Crabtree" <lc*******@goisi.com> wrote in message
| > news:Og**************@TK2MSFTNGP09.phx.gbl...
| > > I'm trying to pass a variable by reference from a C# program to a
managed
| > > C++ wrapper. Something like this:
| > >
| > > ------------C++--------------
| > > void GimmeByRef(int &reference);
| > > -----------------------------
| > >
| > > ------------C#---------------
| > > GimmeByRef(ref referenceVariable);
| > > -----------------------------
| > >
| > > However, I keep getting errors relating to not being able to convert
'ref
| > > uint' to 'uint*'. What am I doing wrong?
| > >
| > > Lee Crabtree
| >
| >
| >

Mar 22 '06 #9

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

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
1
by: lolomgwtf | last post by:
I have a managed C++ method that wraps unmanaged code and creates a managed object holding data retrieved form an unmanged one. I want create an instance of this managed class in C#, pass it to...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
3
by: dbuchanan | last post by:
newbie question What are the various ways that data can be passed between pages. For example; How is data about the logged in user passed to subsequent pages Thank you, Doug
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
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...
1
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
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.