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);
} 6 2147
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 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); }
[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);
}
--
Tomas Restrepo to****@mvps.org http://www.winterdom.com/
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.
"Tomas Restrepo (MVP)" <to****@mvps.org> wrote in message
news:eM**************@TK2MSFTNGP12.phx.gbl... 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 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); }
[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); }
-- Tomas Restrepo to****@mvps.org http://www.winterdom.com/
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 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.
You shouldn't need to cast, since all objects have an implicit cast to
Object^.
What specific error are you getting?
--
Tomas Restrepo to****@mvps.org http://www.winterdom.com/
"Cannot convert parameter 2 from 'System::Collections::ArrayList' to
'System::Object^'"
"Tomas Restrepo (MVP)" <to****@mvps.org> wrote in message
news:uF**************@TK2MSFTNGP12.phx.gbl... 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 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.
You shouldn't need to cast, since all objects have an implicit cast to Object^. What specific error are you getting?
-- Tomas Restrepo to****@mvps.org http://www.winterdom.com/
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
"karch" <no****@spamu.com> wrote in message
news:uf*************@TK2MSFTNGP10.phx.gbl... "Cannot convert parameter 2 from 'System::Collections::ArrayList' to 'System::Object^'"
"Tomas Restrepo (MVP)" <to****@mvps.org> wrote in message news:uF**************@TK2MSFTNGP12.phx.gbl... 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 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.
You shouldn't need to cast, since all objects have an implicit cast to Object^. What specific error are you getting?
-- Tomas Restrepo to****@mvps.org http://www.winterdom.com/
If you're doing much conversion from C# to C++/CLI, download the demo of our
C# to C++ converter ( www.tangiblesoftwaresolutions.com).
--
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
"karch" wrote: 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); } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Russell Reagan |
last post by:
In a newer version of a chess program I am writing, I have created classes
that are (more or less) drop in replacements for things that used to be
plain old integer or enumerated variables (colors,...
|
by: Vijai Kalyan |
last post by:
Hello,
I have come back to C++ after a couple of years with Java so I am quite
rusty and this question may seem poor:
My platform is Windows XP with MSVC 7.1.
I have a class with a...
|
by: Michael Lehn |
last post by:
Hi,
I have a question regarding the conversion of objects. When is the
conversion done by the constructor and when by the operator. My feeling
tells me that the constructor is preferred. But...
|
by: David W. Fenton |
last post by:
A client is panicking about their large Access application, which
has been running smoothly with 100s of thousands of records for
quite some time. They have a big project in the next year that will...
|
by: Bjørn Augestad |
last post by:
Below is a program which converts a double to an integer in two
different ways, giving me two different values for the int. The basic
expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
|
by: Nikhil Patel |
last post by:
Hi all,
I am a VB6 programmer and learning C#. I am currently reading a chapter
on types. I have question regarding enums. Why do we need to convert enum
members to the value that they represent?...
|
by: Alex Sedow |
last post by:
Why explicit conversion from SomeType* to IntPtr is not ambiguous (according
to standart)?
Example:
// System.IntPtr
class IntPtr
{
public static explicit System.IntPtr (int);
public...
|
by: rawCoder |
last post by:
Hi,
Just wanted to know if there is any speed difference between
VB conversion Keywords like CInt, Clng, CStr, CDbl, CBool etc.
..NETs Convert.To<...> methods.
And which is better to be...
|
by: hunter hou |
last post by:
Hello,Please look at the following code(from C++ in a nutshell) and my
questions.Thanks,***Hunter...
typedef void (*strproc)(const char*);
void print(const char* str)
{
std::cout << "const...
|
by: REH |
last post by:
It it permissible to use the constructor style cast with primitives
such as "unsigned long"? One of my compilers accepts this syntax, the
other does not. The failing one chokes on the fact that the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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: 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...
| |