470,810 Members | 1,147 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

Tasks which are more difficult than they should be

While I really like VS C++.NET 2005, there are a number of tasks which are
harder than they should be. Conversion from old 'char' arrays to new String
entities for instance. This thread is to list problems that seem like they
should be easy, but are a bit kludgy. Then solutions can be pointed to or
described! I'll begin:

(*) It is not easy to create a mouse cursor based on an arbitrary bitmap,
even one with restrictions such as dimensional size and use of colors. In
fact, it is tough to customize a mouse cursor in general.

(*) It is tough to insert a single character into a String. As a corollary,
it is tough to convert a single character into a String (Note: ToString
doesn't do this).

(*) It is tough to create an array of objects INSTANCES based on custom
classes. It is easy to create an array of POINTERS to custom objects, but an
array of custom objects have to be VALUE objects and not REF objects. Thus,
they can't have constructors or any other method as part of their definition
(they are what old 'structs' use to be, data but no code).

(*) It requires a sub-system to place a simple shape (e.g., solid-colored
box) on the screen permanently (that is, not only does one have to put code
in the Paint even handler to be run every screen refresh, but one must
actually manually refresh the portion of the screen when and where there are
any changes for them to be seen).

(*) The lack of multiple inheritance means one can't customize innate
controls 'en mass". That is, I can't create a class that Form's AND Panel's
can both inherent from as a common basis. For example, if I want to add a
Graphic sub-system ala the above item I need to put the code in both custom
classes and inherit only from the control's. I can't create a
'GraphicHandler' class and define two new classes, one that derives from
Form and GraphicHandler, and one that derives from Panel and Graphics
handler. I can do this with composition, however, but its not as clean and
requires code to 'bring up' the functionality of the composited sub-class.

I'll try to think of some more...

[==P==]
Feb 6 '06 #1
9 1123
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:Od**************@TK2MSFTNGP14.phx.gbl...
While I really like VS C++.NET 2005, there are a number of tasks which are
harder than they should be. Conversion from old 'char' arrays to new
String entities for instance.
gcnew String(charArray);
(*) It is tough to insert a single character into a String. As a
corollary, it is tough to convert a single character into a String (Note:
ToString doesn't do this).


String^ text = "";
text->Insert(0, Char::ToString('a'));

but not

text->Insert(0, 'a'.ToString());

since 'a' is an SByte.
Feb 7 '06 #2
James Park wrote:
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:Od**************@TK2MSFTNGP14.phx.gbl...
While I really like VS C++.NET 2005, there are a number of tasks
which are harder than they should be. Conversion from old 'char'
arrays to new String entities for instance.


gcnew String(charArray);
(*) It is tough to insert a single character into a String. As a
corollary, it is tough to convert a single character into a String
(Note: ToString doesn't do this).


String^ text = "";
text->Insert(0, Char::ToString('a'));


text = text->Insert(0,Char.ToString('a'));

remember, strings are immutable.

-cd
Feb 7 '06 #3

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:u2*************@TK2MSFTNGP15.phx.gbl...
| James Park wrote:
| > "Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
| > news:Od**************@TK2MSFTNGP14.phx.gbl...
| >> While I really like VS C++.NET 2005, there are a number of tasks
| >> which are harder than they should be. Conversion from old 'char'
| >> arrays to new String entities for instance.
| >
| > gcnew String(charArray);
| >
| >> (*) It is tough to insert a single character into a String. As a
| >> corollary, it is tough to convert a single character into a String
| >> (Note: ToString doesn't do this).
| >
| > String^ text = "";
| > text->Insert(0, Char::ToString('a'));
|
| text = text->Insert(0,Char.ToString('a'));
|
| remember, strings are immutable.
|
| -cd
|
|

Or :

text = text->Insert(0, "a");

Willy.
Feb 7 '06 #4
Cool. The code you provided works! But, it is easy to fall into the
following trap. This code doesn't work:

char chr_a = 'a' ;
string text = "" ;
text = text->Insert(0, chr_a.ToString()) ;

The difference here is that it invokes the 'char' version of ToString. The
result of the above is the following:

text = "97" ;

97? That's weird. Not really. the ASCII value of the char ' a' is 97. But I
definitiely fell into the trap a few weeks back. The reason this works:

text = text->Insert(0, Char::ToString(chr_a)) ;

is because it uses the 'Char' version of ToString instead of the 'char'.
What a difference a capital 'C' makes...

[==P==]

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:e4**************@TK2MSFTNGP10.phx.gbl...

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:u2*************@TK2MSFTNGP15.phx.gbl...
| James Park wrote:
| > "Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
| > news:Od**************@TK2MSFTNGP14.phx.gbl...
| >> While I really like VS C++.NET 2005, there are a number of tasks
| >> which are harder than they should be. Conversion from old 'char'
| >> arrays to new String entities for instance.
| >
| > gcnew String(charArray);
| >
| >> (*) It is tough to insert a single character into a String. As a
| >> corollary, it is tough to convert a single character into a String
| >> (Note: ToString doesn't do this).
| >
| > String^ text = "";
| > text->Insert(0, Char::ToString('a'));
|
| text = text->Insert(0,Char.ToString('a'));
|
| remember, strings are immutable.
|
| -cd
|
|

Or :

text = text->Insert(0, "a");

Willy.

Feb 7 '06 #5
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Cool. The code you provided works! But, it is easy to fall into the
following trap. This code doesn't work:

char chr_a = 'a' ;
string text = "" ;
text = text->Insert(0, chr_a.ToString()) ;

The difference here is that it invokes the 'char' version of ToString. The
result of the above is the following:

text = "97" ;

97? That's weird. Not really. the ASCII value of the char ' a' is 97. But
I definitiely fell into the trap a few weeks back. The reason this works:

text = text->Insert(0, Char::ToString(chr_a)) ;

is because it uses the 'Char' version of ToString instead of the 'char'.
What a difference a capital 'C' makes...


If you want to use the VC++ type name for Char, it's wchar_t. You can find a
table at
http://msdn.microsoft.com/library/en...eConfusion.asp
Feb 7 '06 #6

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
| Cool. The code you provided works! But, it is easy to fall into the
| following trap. This code doesn't work:
|
| char chr_a = 'a' ;
| string text = "" ;
| text = text->Insert(0, chr_a.ToString()) ;
|
| The difference here is that it invokes the 'char' version of ToString. The
| result of the above is the following:
|
| text = "97" ;
|
| 97? That's weird. Not really. the ASCII value of the char ' a' is 97. But
I
| definitiely fell into the trap a few weeks back. The reason this works:
|
| text = text->Insert(0, Char::ToString(chr_a)) ;
|
| is because it uses the 'Char' version of ToString instead of the 'char'.
| What a difference a capital 'C' makes...
|

For the time being, it's fundamental to understand the difference between
managed types and unmanaged types when using C+++CLI in mixed mode. Maybe a
later version of C++/CLI will support seamless integration of both managed
and unmanaged types.

Willy.
| [==P==]
|
| "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
| news:e4**************@TK2MSFTNGP10.phx.gbl...
| >
| > "Carl Daniel [VC++ MVP]"
<cp*****************************@mvps.org.nospam >
| > wrote in message news:u2*************@TK2MSFTNGP15.phx.gbl...
| > | James Park wrote:
| > | > "Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
| > | > news:Od**************@TK2MSFTNGP14.phx.gbl...
| > | >> While I really like VS C++.NET 2005, there are a number of tasks
| > | >> which are harder than they should be. Conversion from old 'char'
| > | >> arrays to new String entities for instance.
| > | >
| > | > gcnew String(charArray);
| > | >
| > | >> (*) It is tough to insert a single character into a String. As a
| > | >> corollary, it is tough to convert a single character into a String
| > | >> (Note: ToString doesn't do this).
| > | >
| > | > String^ text = "";
| > | > text->Insert(0, Char::ToString('a'));
| > |
| > | text = text->Insert(0,Char.ToString('a'));
| > |
| > | remember, strings are immutable.
| > |
| > | -cd
| > |
| > |
| >
| > Or :
| >
| > text = text->Insert(0, "a");
| >
| > Willy.
| >
| >
|
|
Feb 7 '06 #7

"James Park" <so*****@hotmail.com> wrote in message
news:eN**************@TK2MSFTNGP15.phx.gbl...
| "Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
| news:%2****************@TK2MSFTNGP12.phx.gbl...
| > Cool. The code you provided works! But, it is easy to fall into the
| > following trap. This code doesn't work:
| >
| > char chr_a = 'a' ;
| > string text = "" ;
| > text = text->Insert(0, chr_a.ToString()) ;
| >
| > The difference here is that it invokes the 'char' version of ToString.
The
| > result of the above is the following:
| >
| > text = "97" ;
| >
| > 97? That's weird. Not really. the ASCII value of the char ' a' is 97.
But
| > I definitiely fell into the trap a few weeks back. The reason this
works:
| >
| > text = text->Insert(0, Char::ToString(chr_a)) ;
| >
| > is because it uses the 'Char' version of ToString instead of the 'char'.
| > What a difference a capital 'C' makes...
|
| If you want to use the VC++ type name for Char, it's wchar_t. You can find
a
| table at
|
http://msdn.microsoft.com/library/en...eConfusion.asp
|
|

Which is just another native type, not the managed reference type
(System.Char).

Willy.

Feb 7 '06 #8
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:OP**************@TK2MSFTNGP10.phx.gbl...

"James Park" <so*****@hotmail.com> wrote in message
news:eN**************@TK2MSFTNGP15.phx.gbl...
| "Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
| news:%2****************@TK2MSFTNGP12.phx.gbl...
| > Cool. The code you provided works! But, it is easy to fall into the
| > following trap. This code doesn't work:
| >
| > char chr_a = 'a' ;
| > string text = "" ;
| > text = text->Insert(0, chr_a.ToString()) ;
| >
| > The difference here is that it invokes the 'char' version of ToString.
The
| > result of the above is the following:
| >
| > text = "97" ;
| >
| > 97? That's weird. Not really. the ASCII value of the char ' a' is 97.
But
| > I definitiely fell into the trap a few weeks back. The reason this
works:
| >
| > text = text->Insert(0, Char::ToString(chr_a)) ;
| >
| > is because it uses the 'Char' version of ToString instead of the
'char'.
| > What a difference a capital 'C' makes...
|
| If you want to use the VC++ type name for Char, it's wchar_t. You can
find
a
| table at
|
http://msdn.microsoft.com/library/en...eConfusion.asp
|
|

Which is just another native type, not the managed reference type
(System.Char).


Don't native types just become aliases for managed types when inside managed
code?
Feb 7 '06 #9

"James Park" <so*****@hotmail.com> wrote in message
news:ue*************@TK2MSFTNGP14.phx.gbl...
| "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
| news:OP**************@TK2MSFTNGP10.phx.gbl...
| >
| > "James Park" <so*****@hotmail.com> wrote in message
| > news:eN**************@TK2MSFTNGP15.phx.gbl...
| > | "Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
| > | news:%2****************@TK2MSFTNGP12.phx.gbl...
| > | > Cool. The code you provided works! But, it is easy to fall into the
| > | > following trap. This code doesn't work:
| > | >
| > | > char chr_a = 'a' ;
| > | > string text = "" ;
| > | > text = text->Insert(0, chr_a.ToString()) ;
| > | >
| > | > The difference here is that it invokes the 'char' version of
ToString.
| > The
| > | > result of the above is the following:
| > | >
| > | > text = "97" ;
| > | >
| > | > 97? That's weird. Not really. the ASCII value of the char ' a' is
97.
| > But
| > | > I definitiely fell into the trap a few weeks back. The reason this
| > works:
| > | >
| > | > text = text->Insert(0, Char::ToString(chr_a)) ;
| > | >
| > | > is because it uses the 'Char' version of ToString instead of the
| > 'char'.
| > | > What a difference a capital 'C' makes...
| > |
| > | If you want to use the VC++ type name for Char, it's wchar_t. You can
| > find
| > a
| > | table at
| > |
| >
http://msdn.microsoft.com/library/en...eConfusion.asp
| > |
| > |
| >
| > Which is just another native type, not the managed reference type
| > (System.Char).
|
| Don't native types just become aliases for managed types when inside
managed
| code?
|
|

Sure, my bad I missed your point completely, the native types do map to
their equivalent managed types.
That is:
wchar_t maps to System.Char
while:
char maps to System.SByte

Willy.


Feb 8 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Greg Bryant | last post: by
6 posts views Thread by John Smith | last post: by
27 posts views Thread by John Bailo | last post: by
5 posts views Thread by rdemyan via AccessMonster.com | last post: by
3 posts views Thread by Steven Blair | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.