473,811 Members | 2,856 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MC++ passing pointer to 'int'

I need to pass a pointer to 'int' as a parameter in a managed module to a
managed member function. I am assuming I need to box my value. Is this true,
or can I just pass the address of my variable ? The variable needs to
conform to CLS specifications.
Nov 16 '05 #1
2 1096
Hi Edward,

Ref parameters are part of CLS. Just pass a pointer to a System::Int32 (or
equivalently, a __gc pointer to an int).

Ronald Laeremans
Visual C++ team

"Edward Diener" <ed******@tropi csoft.com> wrote in message
news:ux******** ********@TK2MSF TNGP12.phx.gbl. ..
I need to pass a pointer to 'int' as a parameter in a managed module to a
managed member function. I am assuming I need to box my value. Is this true, or can I just pass the address of my variable ? The variable needs to
conform to CLS specifications.

Nov 16 '05 #2
Ronald Laeremans [MSFT] wrote:
Hi Edward,

Ref parameters are part of CLS. Just pass a pointer to a
System::Int32 (or equivalently, a __gc pointer to an int).
I have some confusion about this. My understanding is that System::Int32 is
a value type. So this means that if I pass a pointer to a System::Int32
object, I can just instantiate one on the stack and take its address to pass
it as a pointer, since as the documentation states, there is an implicit
conversion from a V __nogc * to a V __gc * , ie.

__gc class A { void SomeMemberFunct ion(System::Int 32 *); }
// System::Int32 * is a __gc pointer because System::32 is a managed type.
A * myA = new A();
System::Int32 avar;
myA -> SomeMemberFunct ion(&avar);

Now suppose I have an 'int' instead:

int avar;
myA -> SomeMemberFunct ion(&avar);

Does this work ? or do I have to do manual boxing such as:

myA -> SomeMemberFunct ion(__box(avar) );

Ronald Laeremans
Visual C++ team

"Edward Diener" <ed******@tropi csoft.com> wrote in message
news:ux******** ********@TK2MSF TNGP12.phx.gbl. ..
I need to pass a pointer to 'int' as a parameter in a managed module
to a managed member function. I am assuming I need to box my value.
Is this true, or can I just pass the address of my variable ? The
variable needs to conform to CLS specifications.

Nov 16 '05 #3

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

Similar topics

58
10191
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
2
4318
by: Morgan | last post by:
Thanks to all of you because I solved the problem related with my previous post. I simply made confusion with pointers to pointers and then succeeded passing the reference to the first element pointer. :-)) You were right about by mixed code: quickly writing an example to clarify the matter I made a C++ program, sorry for the inconvenience. Anyway, although it all works fine with monodimensional arrays, I still have a problem with...
1
2120
by: george doubleu | last post by:
hi, i'm using "gcc version 3.3.3 (Debian)" to compile the program pasted below. I get the two warnings you can see in the remarks. The second warning is perfectly OK for me, but the first one I don't understand. Isn't the "const int *" construct in the signature of func1 a hint for the user, that func1 doesn't modify **arg? Why then is it dangerous to pass an alterable argmument?
11
4477
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to accomplish. // - - - - - - - - begin code - - - - - - - typedef int sm_t; typedef int bg_t; sm_t sm; bg_t bg;
17
3608
by: Charles Sullivan | last post by:
The library function 'qsort' is declared thus: void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); If in my code I write: int cmp_fcn(...); int (*fcmp)() = &cmp_fcn; qsort(..., fcmp); then everything works. But if instead I code qsort as:
2
2520
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a pointer or reference to a derived type of the base class's return type. In .NET the overridden virtual function is similar, but an actual parameter of the function can be a derived reference from the base class's reference also. This dichotomy...
12
5407
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
4
3408
by: =?Utf-8?B?QmlsbCBTcGFobg==?= | last post by:
I have an abstract base class defined in an MC++ class library. I then create a descendent class in a C# class library. This seems to work OK with the exception of one of the abstract member functions/pure virtual function that uses a passed in pointer to a long. Just using pointers in the C# library results in the expected: Pointers and fixed size buffers may only be used in an unsafe context. And using the 'ref' keyword doesn't...
5
1479
by: CapCity | last post by:
I'm sure I'm missing something simple - I do not code in C regularly, and the breaks are long enough for me to forget. The situation I have is I need to create an array but I do not know the dimension until runtime. I pass the pointer to a function which then determines the size and then creates and populates it. I can walk the array OK in the function, but the app crashes when I try to do so in the calling routine. Here's a small...
0
9722
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...
0
9603
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
10644
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
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
9200
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...
0
6882
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
5550
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
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3863
muto222
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.