473,396 Members | 2,024 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,396 software developers and data experts.

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 1953
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...
0
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...
0
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...

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.