|
I tried this also with the same result. The problem with this equals is that Object.Equals is a comparison of the references if the object is a reference, but derived classes can change this to a value equality (see the documentation for more details). It is better to use the ReferenceEquals to ensure you are really determining if the references are refering to the same instance of the object. This is very confusing.
The only things I didn't have in my code to make it compile is:
using namespace System::Collections::Generic;
at the top of the file and
int numPts = 100000;
at the top of main.
Actually I just tried this on another machine and it worked. I am using the .NET Beta2 and I may have an older install on the other machine. I will try it again on that machine and let you know.
Thanks, Charlie
|
|
|
|
|
I figured out one problem. That is why the ReferenceEquals is returning false. Somehow, my compile switch got changed to /02 (optimization = Max speed). If I change it to /Od (Disabled), the ReferenceEquals returns true. This seems like a defect in the compiler. I will submit this to Microsoft.
I still don't understand the debugger watch window showing different addresses for the errList[0] and errListCopy[0] references though.
Thanks all for the comments.
Charlie
|
|
|
|
|
Hello Charlie
I tried both Debug and Release builds. It works as expected for me.
Here's my Release build compiler command line :-
/O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /FD /EHa /MD /Yu"stdafx.h" /Fp"Release\Test_Del.pch" /Fo"Release\\" /Fd"Release\vc80.pdb" /W3 /nologo /c /Zi /clr /TP /errorReport:prompt /FU
void main()
{
int numPts = 10;
List< PointRef^ > errList(numPts);
List< PointRef^ > errListCopy(numPts);
for (int idx = 0; idx < numPts; ++idx)
errList.Add(gcnew PointRef(idx, idx));
errListCopy.AddRange(%errList);
if (Object::ReferenceEquals(errList[0], errListCopy[0]))
{
int i = 0;
Console::WriteLine("here");
}
int b = 1;
}
I am using VS.NET Beta 2
Regards,
Nish
|
|
|
|
|
How is that possible? PointRef is a ref struct, errList[0] and errListCopy[0] should get boxed into two different objects, right?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote:
How is that possible? PointRef is a ref struct, errList[0] and errListCopy[0] should get boxed into two different objects, right?
Hello Senthil
In C++, a ref struct and a ref class are both reference types. While a value struct and a value class are value types. So, PointRef in the above example is *not* a value type.
|
|
|
|
|
I keep forgetting that there are ref and value prefixes to structs. Thanks for clearing that up.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Oh crap, PointRef ^x = gcnew PointRef itself seems to create a boxed object. Yet another thing I have to remember when I switch between C++/CLI and C#.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote:
Oh crap, PointRef ^x = gcnew PointRef itself seems to create a boxed object.
No - PointRef is a reference type - there is no boxing involved here.
|
|
|
|
|
Hi all,
I've got a form with a number of picture boxes. I now want to add a small picturebox on top of these main boxes and be able to see the main box through the small box. If I set the background colour to transparent it, as you probably know, will show the main forms background. Is there a way that I can set the parent of the small box to be the main box?
If not how do I go about creating a picturebox that does have true transparency. I presume I can write my own pictureBox class but don't know how and what I would need to override. Does anyone have any idea because I'm dying here guys!!
|
|
|
|
|
Forget the stupid picture box and draw your own image onto the screen.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
So how do I draw a transparent image?
|
|
|
|
|
Use the DrawImage method that takes an ImageAttributes class instance. That class does many things, transparency is one of them.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Ok, I've used drawimage and imageattributes to make my image transparent. Now how do I float this image over a picturebox control (it seems to be painted under the control).
What I'm basically looking for is an image on the form that will change size and position dynamically. I need to be able to set things like cursors when I'm over a certain area of the image. So my idea was to float another image over the top and use this region to set cursors. The only way to use cursors I've found at the moment is by using forms controls (hence the pictureboxes). I've tried using rectangles and regions but I get the same problem as I'm now getting with images - they seem to be hidden under the picture.
I've tried overriding picturebox but can't seem to get it working. In fact anything I try doesn't produce the goods.
|
|
|
|
|
richiemac wrote:
What I'm basically looking for is an image on the form that will change size and position dynamically.
Sounds like you want to write your own control, from the total base class, that draws these images for you. A picture box will not work for this, that's why I said to draw yourself.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Could you please point me towards a good tutorial on this subject as I'm totally new to this stuff. From what I gather I would have to write my own paint events - is that right??
|
|
|
|
|
That's right. If you search this site for user control, you'll get heaps of hits.
This[^] and this[^] look like good places to start.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi all, I've run into some problems with a template I'm trying to do.
First of all I declared a class and its members in a header file.
eg:
class SomeClass
{
public:
SomeClass(void);
~SomeClass(void);
int SomeFunction(int &, int &);
private:
int someVars;
};
and then defined the class and its members in a source file.
This all worked fine, and run as expected.
but because it's for a library I'm writting, I need it to handle multiple datatypes, so naturally I turned the relivent parts into templates.
The problem is, the template only works if the whole class is declared and defined in the header file. If I try to put the definitions into a source file, I get undefined errors popping up everywhere.
Is there a way and could someone explain how I can declare a template in a header file and define it in a source file. It just keeps things somewhat tidy.
Regards
|
|
|
|
|
hello again :P, my modifing is broken. anyway on a final note to defining / declaring template...
in the eg shown above I had added something similar to
template <typename datatype="">
class SomeClass
{
...
}; replaced all the int's with DATATYPE.
in the source file I was messing around and have tried a few things like
template <typename datatype="">
SomeClass<datatype>::SomeClass(void) { }
... etc etc
I've tried other variouis things, but I haven't found a solution, the net hasn't been much help as of yet.
N/B: Not to worry, I have just read they have to be declared and defined in the same file, grrr. well I have to live with what I've got
Freedom doesn't come without a fight.
|
|
|
|
|
I have made it.
So:
Create cpp file and h file. the cpp file will have strange error. Right click on that cpp in solution explorer. Find Precompiled headers under C/C++. Under option "Create/Use Precompiled Header" chose "Not Using Precompiled Headers"
|
|
|
|
|
hello,
i want to send an XML file as an argument to a function which is being tested in CPPUNIT. how do i parse the entire file
thanks
|
|
|
|
|
I had to google CPPUNIT to find out what it was.
It would be better if you would post the actual code so we can see what you are doing.
The System::Xml namesapce has a number of well-developed classes that can used to read XML data into memory. The most obvious is: XmlReader. But, in your case, (I'm guessing here) you might prefer XmlDocument or the Navigator object that be created for XmlDocument.
Read the documentation; these classes are easy to use and almost foolproof.
|
|
|
|
|
hi
I've started R&D work on a USB-232 converter cable (comply with FCC standards).
My application (C++ driver on Linux OS) tries to connect with a device & communicates via this cable.(the device is connected to the rs232 port & PC is connected to the USB port)
I'd tested with the RS232 cable & now I want to use this USB-232 converter cable.
Are there any libraries or sample source codes to do that.
Thanks
|
|
|
|
|
It's a bit misleading IMO, but C++/CLI is the managed C++ forum. Either way, I suspect this is the wrong place to ask how Linux provides USB libraries. By all means, ask in the C++ forum, but I'd be looking at also asking where more people use Linux.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi
I need to convert a char a[8000] to a String* (in .NET)
how do I do it?
<br />
String * b = (String *) a;
will crash at a certain point.
thanks alot
|
|
|
|
|
A String does not contain a char *, it's a Unicode string. At a minimum, you'd need to turn your pointer into a BSTR, I would think. Either way, you can't cast a char * to a string type, you need to pass the byte array into a constructor. That memory address contains an array of bytes representing character data, it does NOT contain an instance of hte String class, which encapsulates a Unicode string.
Christian Graus - Microsoft MVP - C++
|
|
|
|