Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2005

Tip: Looking for answers? Try searching our database.

Conversion Question: C# -> C++ CLI

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
karch - 25 Oct 2005 00:53 GMT
I am beginning to write my first applications with C++/CLI and was wondering
if someone could demonstrate the proper way to convert a sample piece of
code. I just need some help understanding the new syntax for handles and
iterating, etc. Thanks in advance for the help.

SoapFormatter formatter = new SoapFormatter();
byte[] buffer = new byte[dept.Capacity];
MemoryStream stream = new MemoryStream(buffer);

foreach (object o in dept) {
   formatter.Serialize(stream, o);
}
Tomas Restrepo (MVP) - 25 Oct 2005 02:17 GMT
Karch,

>I am beginning to write my first applications with C++/CLI and was
>wondering if someone could demonstrate the proper way to convert a sample
[quoted text clipped - 8 lines]
>    formatter.Serialize(stream, o);
> }

[not tested]

SoapFormatter^ formatter = gcnew SoapFormatter();
array<Byte>^ buffer = gcnew array<Byte>(dept.Capacity);
MemoryStream^ stream = gcnew MemoryStream(buffer);

for each (Object^ o in dept) {
   formatter->Serialize(stream, o);
}

Signature

Tomas Restrepo
tomasr@mvps.org
http://www.winterdom.com/

karch - 25 Oct 2005 02:24 GMT
Excellent! Worked perfectly, and I'm understanding how the new syntax works
(I think). One more question (I was experimenting while I waited for your
answer).

In this case, dept is an ArrayList:

formatter->Serialize(stream, dept);

but how do I cast dept to an Object^ (which is what the method is
expecting)? This is valid in C#, but having a problem in C++/CLI.

Thanks again.

> Karch,
>
[quoted text clipped - 20 lines]
>    formatter->Serialize(stream, o);
> }
Tomas Restrepo (MVP) - 25 Oct 2005 03:38 GMT
Karch,

> Excellent! Worked perfectly, and I'm understanding how the new syntax
> works (I think). One more question (I was experimenting while I waited for
[quoted text clipped - 6 lines]
> but how do I cast dept to an Object^ (which is what the method is
> expecting)? This is valid in C#, but having a problem in C++/CLI.

You shouldn't need to cast, since all objects have an implicit cast to
Object^.
What specific error are you getting?

Signature

Tomas Restrepo
tomasr@mvps.org
http://www.winterdom.com/

karch - 25 Oct 2005 03:51 GMT
"Cannot convert parameter 2 from 'System::Collections::ArrayList' to
'System::Object^'"

> Karch,
>
[quoted text clipped - 12 lines]
> Object^.
> What specific error are you getting?
Marcus Heege - 25 Oct 2005 06:55 GMT
I assume you have done something like this:

ArrayList al;
al.Add(1);
...

gcnew SoapFormatter()->Serialize(al);

This needs some explanation, since you have used a special C++/CLI feature
here: implicitly dereferenced variables. Read my post on the thread "using
C# when adding new feature" from yesterday for more details.

Marcus Heege
www.heege.net

> "Cannot convert parameter 2 from 'System::Collections::ArrayList' to
> 'System::Object^'"
[quoted text clipped - 15 lines]
>> Object^.
>> What specific error are you getting?
David Anton - 25 Oct 2005 14:05 GMT
If you're doing much conversion from C# to C++/CLI, download the demo of our
C# to C++ converter (www.tangiblesoftwaresolutions.com).

Signature

David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter

> I am beginning to write my first applications with C++/CLI and was wondering
> if someone could demonstrate the proper way to convert a sample piece of
[quoted text clipped - 8 lines]
>     formatter.Serialize(stream, o);
> }

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.