|
IPEndPoint is a serializable class. In addition, I can't even serialize IPEndPoint itself using xml of course.
m_xmlsSerializer = new XmlSerializer( __typeof ( IPEndPoint) );
Any other ideas?
|
|
|
|
|
Michael Mac wrote:
I can't even serialize IPEndPoint itself using xml of course.
Does it have a public constructor? The exception normally gives the detail reason of what is missing from the class
|
|
|
|
|
The code shown below
XmlSerializer* xml = new XmlSerializer ( __typeof( IPEndPoint ) );
returns an exception with the message: "There was an error reflecting 'System.Net.IPEndPoint'".
So I think it's impossible to serialize IPEndPoint class using XML. The alternatives are BinaryFormatter and SoapFormatter.
43 68 65 65 72 73 2c
4d 69 63 68 61 65 6c
|
|
|
|
|
Correct; unfortunately MS didn't document this topic very well. The XmlSerializer doesn't use any of the other serialization stuff, no Serializable attribute nor ISerializable; I think its a shame myself.
The XmlSerializer works by using the reflection.emit classes to construct a class that will place all the public fields/property's in an XML document; when it deserializes it tries to access the nodes in the document as the field/property name to place the value back in. When it does this it creates an instance of the object using the default constructor.
It DOES let you control some functionality by using Attributes and the OverrideAttributes class; but I don't like that solution very well.
James
|
|
|
|
|
Suppose I have an old application with unmanaged code and I adding some .NET classes that are of course managed.
The question is: Will my unmanaged code be compiled as native code and the managed code will be CLR metadata? I am asking this, because I want my old, unmanaged part of application to be very fast, not a MSIL that is at first run (?) compiled into native code.
Best regards,
Alexandru Savescu
|
|
|
|
|
Use #pragma unmanaged to specify that the following code is to be compiled to native code and #pragma managed when you end the native stuff
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
|
Thanks Nish!
However what if I want to declare a managed type inside of an existing class? Will then my whole class be managed? (This is something that I would not like )
Best regards,
Alexandru Savescu
|
|
|
|
|
Alexpro wrote:
Will then my whole class be managed? (This is something that I would not like )
No. If you want to use a managed type inside say your CDialog class, then you'll have to only add #pragma managed for the function in the class, where you use the managed type. That was how it was in Beta 2. I didn't chk to see if it allows you to have a managed line of code inside an unmanaged marked function. I should think not!
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
|
Nish - Native CPian wrote:
if it allows you to have a managed line of code inside an unmanaged marked function. I should think not!
It doesn't!
Best regards,
Alexandru Savescu
|
|
|
|
|
Alexpro wrote:
It doesn't!
Well, at least, they granularised at the function level instead of at the class level which would have been horrible.
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
|
Hi everyone,
I need advice regardin my problem, here's my problem:
I have a Text File(serves as my database) with 3 colums fixed length, example
Name Address Age
AAA 123 Anywhere 12
BBB .... ...
Joseph 345 Somewhere 15
Rosie 098 Cool DC 20
I need to search this Text File, in the real world this Text File migh contain 1 Million records as soon as we populate our database.
My question is... what is the fastest way to search for a particular string in this text file. Note: I only search for the name, If I find the name... I need to get the enrite line and process it.
I will really appreciate any help that you can give me.
Thanks/Regards
Sidney
|
|
|
|
|
I will give you a fast, but memeory consuming solution.
Use a std::map to store the name as keys and you make a struct to store the address. Read the whole file and fill the map. Then, when you search the name you will use std::map::find that will do a binary search.
At the end of the program you iterate through the map and write it to the file.
If you have multiple entries with the same name you may consider multimap. Since you post it to the Manage C++ you may also consider hash_map.
Best regards,
Alexandru Savescu
|
|
|
|
|
Thanks Alexandru! I'll see if I can do this, do you have sample code that used STL Map? if you have would you be so kind to share it with me? And by the way just for info... the fields are of Fixed length, example
Field Name Position Length
Fld1 1 10
Fld2 11 21
etc...
Thanks/Regards
Sidney
|
|
|
|
|
You can look at the article on CP about STL here. Also you can read MSDN (the one that comes with .NET is nicer than the VC6.0's one), or the SGI documentation.
Best regards,
Alexandru Savescu
|
|
|
|
|
Hi Alexandru,
I get an error in my code when I try to use the multimap, the error is "Cannot open include file: 'multimap' C++" can you help me?
here's my code:
#include <string>
#include <iostream>
#include <multimap>
using namespace std;
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
int main()
{
multimap<const char*,="" int,="" ltstr=""> m;
m.insert(pair<const char*="" const,="" int="">("a", 1));
m.insert(pair<const char*="" const,="" int="">("c", 2));
m.insert(pair<const char*="" const,="" int="">("b", 3));
m.insert(pair<const char*="" const,="" int="">("b", 4));
m.insert(pair<const char*="" const,="" int="">("a", 5));
m.insert(pair<const char*="" const,="" int="">("b", 6));
cout << "Number of elements with key a: " << m.count("a") << endl;
cout << "Number of elements with key b: " << m.count("b") << endl;
cout << "Number of elements with key c: " << m.count("c") << endl;
cout << "Elements in m: " << endl;
for (multimap<const char*,="" int,="" ltstr="">::iterator it = m.begin();
it != m.end();
++it)
cout << " [" << (*it).first << ", " << (*it).second << "]" << endl;
}
Thanks/Regards
Sidney
|
|
|
|
|
Hello sidney
The < and > tags were stripped by the html parser. Please send the code between <pre> and </pre> so I can see what you include and what include not. However this code sould work
#include <multimap>
using namespace std;
....
Best regards,
Alexandru Savescu
|
|
|
|
|
Here's the code:
#include <string>
#include <iostream>
#include <multimap>
using namespace std;
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
int main()
{
multimap<const char*, int, ltstr> m;
m.insert(pair<const char* const, int>("a", 1));
m.insert(pair<const char* const, int>("c", 2));
m.insert(pair<const char* const, int>("b", 3));
m.insert(pair<const char* const, int>("b", 4));
m.insert(pair<const char* const, int>("a", 5));
m.insert(pair<const char* const, int>("b", 6));
cout << "Number of elements with key a: " << m.count("a") << endl;
cout << "Number of elements with key b: " << m.count("b") << endl;
cout << "Number of elements with key c: " << m.count("c") << endl;
cout << "Elements in m: " << endl;
for (multimap<const char*, int, ltstr>::iterator it = m.begin();
it != m.end();
++it)
cout << " [" << (*it).first << ", " << (*it).second << "]" << endl;
}
Thanks/Regards
Sidney
|
|
|
|
|
Well, the multimap header does not exists. Include <map> and it will work;
#include <map>
using namespace std;
etc.
Best regards,
Alexandru Savescu
|
|
|
|
|
And also, I just want to make it clear... if I have same name in my name field I can use the STD::MAP? if so how can I use the multimap? and is Hash_map fast too? can I also have more info about it?
Thanks/Regards
Sidney
|
|
|
|
|
Hi everyone,
i tried to use the multimap(STL) but I got an error "fatal error: Cannot open include file: 'multimap' C++" I alread installed the all the files that I got from sgi... STL Version 3.3, I installed it in "C:\Program Files\Microsoft Visual Studio\VC98\Include"
What could be the problem?
Thanks/Regards
Sidney
|
|
|
|
|
I think you need not replace the STL that comes with Visual C with the SGI implementation.
Best regards,
Alexandru Savescu
|
|
|
|
|
Again with some newbie question.
I have started a C# windows application and it look really nice with all those new controls and the WinForms stuff (looks much more to Delphi than VB 6 though ). I was wondering how I can use WinForms in MC++? I mean draging and dropping WinForms components on the managed form and stuff like that.
Thanks
Best regards,
Alexandru Savescu
|
|
|
|
|
You can't
MC++ lacks the CodeDOM support which is required for a visual designer to write the neccesary code.
James
Simplicity Rules!
|
|
|
|
|
Check this out. If you have VB6 you can use the designer. I have not yet tried it.
http://www.gotdotnet.com/userfiles/toml/VBWinForms.zip
|
|
|
|
|
http://www.codeproject.com/useritems/mcppwinforms01.asp
http://www.codeproject.com/managedcpp/mcppwinforms02.asp
http://www.codeproject.com/useritems/mcppoutlookgui.asp
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|