So I have this perfectly fine and running app, that uses managed C++
forms.
Problem#1:
[1] I pass a Bitmap reference to a class, hoping to modify it in one
of the class's methods, so it reflects outside too. Something like
this:
// In a form's scope
Bitmap ^m_Bitmap;
// A separate class
template<typename Tref class ManagedImageModifier
{
public:
...
...
bool ChangeImage(Bitmap^ iImage)
{
// change iImage here
....
return true;
};
};
This builds fine. The problem is that iImage has a different address
in memory than the reference I pass in. Obviously this means any
change to iImage isnt reflected outside. This came as a surprise
initially to me as I am new to managed programming.
Problem#2:
Anyways, I chose to classify this parameter as a reference variable,
by using 'ref' keyword. Something like this
bool ChangeImage(ref Bitmap^ iImage)
{
// change iImage here
....
return true;
};
And now I get this compile error:
error C2061: syntax error : identifier 'ref'
Note that the same keyword when used to classify the class
ImageModifier wasnt giving me errors.
Any clues on whats going on here????
Thanks a lot!
-P. 6 4200
Pixel.to.life wrote:
So I have this perfectly fine and running app, that uses managed C++
forms.
Problem#1:
[1] I pass a Bitmap reference to a class, hoping to modify it in one
of the class's methods, so it reflects outside too. Something like
this:
// In a form's scope
Bitmap ^m_Bitmap;
// A separate class
template<typename Tref class ManagedImageModifier
{
public:
...
...
bool ChangeImage(Bitmap^ iImage)
{
// change iImage here
....
return true;
};
};
This builds fine. The problem is that iImage has a different address
in memory than the reference I pass in. Obviously this means any
change to iImage isnt reflected outside. This came as a surprise
initially to me as I am new to managed programming.
Problem#2:
Anyways, I chose to classify this parameter as a reference variable,
by using 'ref' keyword. Something like this
bool ChangeImage(ref Bitmap^ iImage)
{
// change iImage here
....
return true;
};
And now I get this compile error:
error C2061: syntax error : identifier 'ref'
Note that the same keyword when used to classify the class
ImageModifier wasnt giving me errors.
Any clues on whats going on here????
I think first important step in the troubleshooting is
to decide on whether you are coding C++ or C# !
Arne
On Apr 21, 6:01*am, Arne Vajhøj <a...@vajhoej.dkwrote:
Pixel.to.life wrote:
So I have this perfectly fine and running app, that uses managed C++
forms.
Problem#1:
[1] I pass a Bitmap reference to a class, hoping to modify it in one
of the class's methods, so it reflects outside too. Something like
this:
// In a form's scope
Bitmap * * ^m_Bitmap;
// A separate class
template<typename Tref class ManagedImageModifier
{
* *public:
* * * *...
* * * *...
* * * *bool ChangeImage(Bitmap^ iImage)
* * * *{
* * * * * // change iImage here
* * * * * ....
* * * * * return true;
* * * *};
};
This builds fine. The problem is that iImage has a different address
in memory than the reference I pass in. Obviously this means any
change to iImage isnt reflected outside. This came as a surprise
initially to me as I am new to managed programming.
Problem#2:
Anyways, I chose to classify this parameter as a reference variable,
by using 'ref' keyword. Something like this
bool ChangeImage(ref Bitmap^ iImage)
* * * *{
* * * * * // change iImage here
* * * * * ....
* * * * * return true;
* * * *};
And now I get this compile error:
error C2061: syntax error : identifier 'ref'
Note that the same keyword when used to classify the class
ImageModifier wasnt giving me errors.
Any clues on whats going on here????
I think first important step in the troubleshooting is
to decide on whether you are coding C++ or C# !
Arne- Hide quoted text -
- Show quoted text -
It is managed C++.
I already got a solution on the VC group, doesnt quite work. That
solution recommended using a '%' qualifier instead of
a 'ref' keyword to pass by reference. It builds fine, but still same
issue: what is passed to the method is a different reference from what
is intended.
Since the problem spans a bit of both C++/CLI, I posted it here too.
Thanks anyways.
On Mon, 21 Apr 2008 09:14:53 -0700, Pixel.to.life
<pi***********@gmail.comwrote:
It is managed C++.
Then you're posting to the wrong newsgroup. It does seem as though you
want to pass by reference. And if you were writing C# code, the "ref"
keyword would be useful for that.
But you're not. In C++ you can use the '&' character (not '%' AFAIK) and
it should work. If it doesn't, then you'll need to post your question to
a newsgroup specific to C++, not a newsgroup specific to C#.
Pete
Peter Duniho wrote:
On Mon, 21 Apr 2008 09:14:53 -0700, Pixel.to.life
<pi***********@gmail.comwrote:
>It is managed C++.
Then you're posting to the wrong newsgroup. It does seem as though
you want to pass by reference. And if you were writing C# code, the
"ref" keyword would be useful for that.
But you're not. In C++ you can use the '&' character (not '%' AFAIK)
and it should work. If it doesn't, then you'll need to post your
question to a newsgroup specific to C++, not a newsgroup specific to
C#.
& is standard C++ for a reference.
Standard C++ pointers and references don't play well with a compacting
garbage collector such as .NET has, because objects move around in memory.
So C++/CLI adds a tracking handle (^) and tracking reference (%) which are
GC-aware. The tracking reference is how you define a parameter which C#
sees as "ref" or "out".
>
Pete
On Mon, 21 Apr 2008 10:39:17 -0700, Ben Voigt [C++ MVP]
<rb*@nospam.nospamwrote:
[...]
So C++/CLI adds a tracking handle (^) and tracking reference (%) which
are
GC-aware. The tracking reference is how you define a parameter which C#
sees as "ref" or "out".
Ah, okay.
Well, there's a good example of why this question doesn't belong in this
newsgroup. :)
To the OP: if you can't get % to work for you, you need to post your
question in a managed C++ newsgroup. It has nothing to do with C#. I
recommend when you do so, that you include a concise-but-complete code
sample that reliably demonstrates the problem.
Pete
Pixel.to.life wrote:
It is managed C++.
I already got a solution on the VC group, doesnt quite work. That
solution recommended using a '%' qualifier instead of
a 'ref' keyword to pass by reference. It builds fine, but still same
issue: what is passed to the method is a different reference from what
is intended.
Since the problem spans a bit of both C++/CLI, I posted it here too.
This group has nothing to with C++ or C++/CLI.
It is easy to show that % is working.
Simple example:
#using <mscorlib.dll>
using namespace System;
void f1(String^ s)
{
s = "f1";
}
void f2(String^ %s)
{
s = "f2";
}
int main(array<String^^args)
{
String^ s = "ABC";
Console::WriteLine(s);
f1(s);
Console::WriteLine(s);
f2(s);
Console::WriteLine(s);
return 0;
}
Arne This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andrew Luke |
last post by:
Hi all you C++ guru's!
I'm 'very, very' new to C++ and I'm having a little trouble configuring
my VS environment I think - when I try and compile some sample code I'm
getting the following...
|
by: Avery Fong |
last post by:
The following program will result in a compile error when building under Debug but will compile under Release. Why does is work under Release mode but not under Debug
This program is developed...
|
by: MWK |
last post by:
Hi All,
I don't understand why I get "error c2061: syntax error : identifier" in
VS2003. I thought it's fixed in .Net 2003:
__hook(&TCP_Client::LineReceived, client, HandlerLineReceived);
...
|
by: notahipee |
last post by:
I have been trying to cin an number from 0 to 9 with a leading 0. For
example 00 or 07. I was using a switch case.
switch (int)
{
case 01: break;
case 02: break;.....
My problem arises at 08...
|
by: Pixel.to.life |
last post by:
So I have this perfectly fine and running app, that uses managed C++
forms.
Problem#1:
I pass a Bitmap reference to a class, hoping to modify it in one
of the class's methods, so it...
|
by: =?GB2312?B?yum09MXt?= |
last post by:
today I forgot to include some header,then I found the error message by the compiler is quite strange.
so I want to know exactly the inner details of the compiler impletation,if possible.
and I...
|
by: charmeda103 |
last post by:
My program keeps getting me and error and i dont why
here is the error message
error C2061: syntax error: identifier 'infile'
error C2660: 'ReadDate' : function does not take 6 arguments...
|
by: madhu.ab |
last post by:
Hi All,
I am getting the following errors when i am including header file
winuser.h
I dont know whats happening. How will an error occur in winuser.h??
Please help.
\microsoft visual...
|
by: muby |
last post by:
Hi everybody :)
I'm modifying a C++ code in VC++ 2005
my code snippet
void BandwidthAllocationScheduler::insert(
Message* msg,
BOOL* QueueIsFull,
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
| |