|
I don't understand at all serialization and the CArchive class. I this stage I would be movre comfortable with straight "C++" concepts rather than mixing Microsoft's MFC concepts.
I really do need real life examples to learn from.
Thanks,
Larry
C++ is my favorite programming language
|
|
|
|
|
then I'd suggest you're going to have to put together code that achieves points 1 & 2 of my original post .. MFC has a class CFile thats useful - there's plenty of code around the net that will show you how to use it ..
the link :- http://www.tolland.k12.ct.us/ths/compsci/jeffmaynes/maynes3.pdf[^]
would be a starter ..
other than that, a good c++ textbook should also show you this... Since you brought the point up, I suggested the MFC way of doing it because your data class had 3 CString members/elements, CString is MFC - not pure C++ !!
points 1 and 2 apply wether you're using MFC or not, if not, you'll have to read what the alternative to CFile is
<modified>
you could also look at things 'like' http://www.codeproject.com/file/textfile.asp[^] and using that as a starting point - its not that different to what you'll need to do
</modified>
'g'
-- modified at 2:02 Monday 2nd January, 2006
|
|
|
|
|
Hi-
Here is my problem-- I am having difficulty getting the following to work properly:
//the following was implemented in VS 2003 using Console App (.NET)
<br />
string str ="*********";<br />
str.append("\n psinfo");<br />
str.append("\n*********\n");<br />
<br />
ofstream myfile("C:\\TEMP.txt");<br />
<br />
if (!myfile)<br />
{<br />
cout << "error opening file" << endl;<br />
return -1;<br />
<br />
}<br />
myfile << str << ShellExecute(NULL, "open", "Psinfo.exe",NULL, "C:\\",SW_SHOWNORMAL)<<endl;<br />
myfile.close();<br />
<br />
return 0;
It compiles and runs, its just after execution, when I open the file "Temp.txt", the output is not correct!
here is the output in notepad:
(start output)
*********
psinfo
*********
0000002A
(end output)
So I know that it is writing the string I created and I also know that the Psinfo.exe is executing cause I can see it on the dos prompt. However, the output from the Psinfo.exe is not writing to the text file "TEMP.txt"!
Could anyone shed some light as to why the Psinfo.exe information is not writing to the TEMP.txt file.
FYI- I created a batch file like so...
(start of .bat file)
<br />
@echo off<br />
<br />
rem This env variable stores the log file path.<br />
set PTH=C:\TEMP.txt<br />
<br />
rem Get basic information about the machine.<br />
<br />
echo ************* >>%PTH%<br />
echo * PSINFO -d * >>%PTH%<br />
echo ************* >>%PTH%<br />
psinfo.exe -d >>%PTH%<br />
(end of .bat file)
and when the batch file is executed, the "TEMP.txt" file opened in notepad is similar to the following output:
(start of output)
*************
* PSINFO -d *
*************
System information for
Uptime:
Kernel version:
Product type:
Product version:
Service pack:
Kernel build number:
Registered organization:
Registered owner:
Install date:
Activation status:
IE version:
System root:
Processors:
Processor speed:
Processor type:
Physical memory:
Video driver:
Volume Type Format Label Size Free Free
(end output)
Which is exactly the output I am trying to get in the TEMP.txt file when implemented in VC++!
Thank you for your time.
|
|
|
|
|
Why dont you shellexecute the batch file instead?
It is bit more complex in getting the output of the PSINFO.EXE when executed using the shell execute.
You need to redirect the console output
check this article for additional information Here[^]
-Prakash
|
|
|
|
|
Klerik82 wrote: myfile << str << ShellExecute(NULL, "open", "Psinfo.exe",NULL, "C:\\",SW_SHOWNORMAL)<<endl;< blockquote="">
That writes the return value of ShellExecute() to the file, which is exactly what you're seeing. It doesn't magically know you want to redirect the other program's input to your own file object (which wouldn't work anyway, since they're different processes).
Since this is a console app, you can use popen() to capture the output. Or more generally, you can set up a pipe to the file and use CreateProcess() to tell psinfo the pipe handle.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
"Just because the box has 2 gigabytes of memory doesn't mean you get to use it all!"
-- Rico Mariani, CLR perf guy
|
|
|
|
|
I am very new to VC++, so I thank you for ur direction and assistance!
Happy New Year to all!
|
|
|
|
|
I'm sure the answer is obvious but I can't seem to work it out.
I have a created a class (called Cemu) which is tagged as serializable via MFC's macros. Now in Cemu there consist a couple of CString's which I want to serialize. To complicate matters I have a list of Cemu entries stored in CemuList. What I have done when I want to dump the list to the file is loop through CemuList and call the serialize() method I created in Cemu which in turn writes out the CStrings I want to a file. That process seems to work just fine by examining the file afterwards. What I'm have trouble with is de-serializing. My initial stab at it is below but that doesn't work.
while (file.GetPosition() < file.GetLength()) {
client = new Cemu;
client->Serialize(archive);
CemulList.AddTail(*client);
}
The file containing the data has 2 Cemu serialised entries and what I'm finding is that only one gets read in. My interpretation was that the act of serializing the Cemu would move the file pointer along correctly, ie a total of 2 times but I'm missing something. Can point me in the right direction?
Cheers!
|
|
|
|
|
jbem wrote: Can point me in the right direction?
See this[^] article.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Nice work Ravi - Ive just pointed your work out to a Larry Mills, 2 posts above this one
'g'
-- modified at 21:35 Friday 30th December, 2005
|
|
|
|
|
Thanks Ravi. I initially saw these primers and had a bit of a read through all 3 of them so thanks for putting the effort in to write them up.
The thing I have a problem and which I was trying to avoid was having to store the number of items in the actual file. It seemed rather logical to me that if you know the way you stored data for a class you should be able to serialize chunks which would automatically walk the file in the right increments via the archive buffer till EOF on deserialization. I guess not.
So the thing I get out of all this is that if you have a list of objects of a type that you want to serialize then there is no other way than to store the number of objects as the first item if you ever want to recreate that list of objects ever again. I guess CArchive has no concept, that is exposed to the user, of file position based on what it has serialized just more like a buffer position internally.
|
|
|
|
|
jbem wrote: avoid was having to store the number of items in the actual file
This is a VBT (very bad thing ) because it enforces the dependency that the collection be the last (or only) data stored in the file.
jbem wrote: CArchive has no concept, that is exposed to the user, of file position based on what it has serialized just more like a buffer position internally
Correct. And nor should it, since it's really just a stream (that may be part of another stream). That's where the power of object oriented serialization comes in. If you later choose to embed your collection in another object, you don't need to change your collection serialization code as it's location agnostic.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
One of the ways that I've gotten around this is by outputting the number of elements in the list before outputting the list. Then reading that number at load time to see how many elements are getting ready to get read:
int numElements;
if( ar.IsStoring() )
{
numElements = _yourList.GetCount();
ar << numElements;
POSITION pos = _yourList.GetHeadPosition();
while( pos )
{
YourType currElement = _yourList.GetNext( pos );
currElement.Serialize( ar );
}
}
else
{
_yourList.RemoveAll();
ar >> numElements;
for( int i = 0; i < numElements; ++i )
{
YourType newElement;
newElement.Serialize( ar );
_yourList.AddTail( newElement );
}
}
That's untested code, but you should get the idea.
-- modified at 15:34 Friday 30th December, 2005
|
|
|
|
|
Thanks ToxickZero. Same solution as Ravi offered also and works fine as I just implemented it. Pity you need to keep track of the number of elements when serializing. Wish it could be done in a more dynamic fashion but it seems as it is not to be.
|
|
|
|
|
Hi jbem
I'm not sure that your conclusion that you have to keep track of the number of items in the list is correct.
The list classes contain Serialize functions, and if you use these they keep track for you.
A while back I was builiding a simulator that contained a recursive structure of models and submodels, similar to your Cemu class. My class was CModel, of type CModelObject. It contained a list, m_ModelList, pointing to the submodels (also of type CModel).
m_ModelList was of type CModelList, declared as follows:
typedef CTypedPtrList<CObList, CModelObject*> CModelList;
And the CModel Serialize function was:
void CModel::Serialize(CArchive & ar)<br />
{<br />
CModelObject::Serialize(ar);<br />
<br />
m_ModelList.Serialize(ar);<br />
<br />
if (ar.IsStoring())<br />
{<br />
ar << m_Name<br />
<< m_Notes<br />
<< m_AtomOrMacroNotes;<br />
}<br />
else<br />
{<br />
ar >> m_Name<br />
>> m_Notes<br />
>> m_AtomOrMacroNotes;<br />
}<br />
}
The function saves the properties of the particular CModel object, m_Name, m_Notes, etc., and those defined in the base clase, CModelObject - and it saves the submodels by calling m_ModelList.Serialise(ar). When de-serializing, this call reinstates the list and all its associated objects.
I've stripped a lot of detail out of the example, but amongst the model properties there were also pointers to other models - so there were very many mutually recursive references, and I remember being concerned about how to tie all this back together on de-serialization. I was pleasantly suprised to find that the serialization mechanism looked after all of this for me automatically. I think it is an elegant system and a credit to its designers. It seems that all the user has to do is make sure that things are serialized and de-serialized in the same order.
Best Regards
Cliff
-- modified at 6:58 Sunday 1st January, 2006
|
|
|
|
|
It just occurred to me that I may have misread your question. I thought you meant that your Cemulist was a member of Cemu, comprising a recursive structure. Apologies if I have caused any confusion.
I would still suggest the same solution though. You could try calling the list's Serialize function from within the Serialize function of whatever object contains the Cemulist, in the same way as I did with m_ModelList.
The serialize functions of the list classes invoke the serialize functions of all the things the list points to, so they save the whole structure. I imagine they also write out the number of items, but this is unseen by the user.
|
|
|
|
|
I have developed one MDI application.
I created one child window or it comes as default.
but it size is smaller than the mainframe window
how to fit it with parent window
|| ART OF LIVING ||
|
|
|
|
|
You need to rethink your quesiton. A child windows will (almost) always be smaller than the mainframe window size, as it needs to fit within the client area of the mainframe window.
There is a flag you can set that will make the new window/view/child window maximized on creation (fill client area), but I forget what it is. You'll just need to look it up like the rest of us.
INTP
Every thing is relative...
|
|
|
|
|
hi ;
i am doing a proj(vc6) which include file transfer in lan the code i used is
......send
byte* data = new byte[4096];
file.Open("filename",CFile::modeRead|CFile::typeBinary);
do
{
dwRead = file.Read(data,4096);
sock.Send(data,dwRead);
}
while (dwRead>0);
delete data;
file.Close();
.........rec
byte* data = new byte[4096];
file.Open("filename",CFile::modeWrite|CFile::typeBinary);
do
{
dwRead = sock.Recive(data,4096);
file.Write(data,dwRead);
}
while (dwRead>0);
delete data;
file.Close();
..............
the prblm i am facing is that i got transer sound and some other stuffs,which is clear and perfectly working i am able to do that but while in file transer it take lot of time ie abt 30 sec for 500kb of data i got 100 mbps network so i think it should take around few sec ie 1-2 sec anyone got a solution for this do reply
Happy New Programming Year
joby
jobythomas24@gmail.com
|
|
|
|
|
Try asyncronouse sockets (not straight forward), synchronous data transfers are always slow.
-Prakash
|
|
|
|
|
How do i check the minimum PC configuration that is required to run an application that i have written in VC++.
By PC configuration i mean the processor speed, memory, hard disc space etc.
My application captures video from usb port and tv tuner and process about 30 frames/sec.
I am sorry if this is not the right forum to ask.
Regards,
Nripun
|
|
|
|
|
|
|
i am not looking for a VC++ program which returns the PC configuration.
for that matter i am not looking for any program.
I have written an application. When i deliver this application i have to mention in the catlogue the minimun PC requirement. Can u please tell me how to check if it will run in a P3 and not in a P2 processor
-- modified at 8:43 Friday 30th December, 2005
|
|
|
|
|
What I understood know is that ur application is hardware dependent.If I m right then it is not a simple application but a device driver or system programming sort of thing u have done.
never say die
-- modified at 8:59 Friday 30th December, 2005
|
|
|
|
|
i shudnt have mentioned the usb and tuners in my post. that created the confusion. Let me try and make it a lil more simple.
I wrote an application.
Will in work fine on a P1/P2/P3 processors?
How can i find tat out?
Do i have to keep trying on older pcs until i find one in which it doesnt run??
I hope there is a better way
-- modified at 11:24 Friday 30th December, 2005
|
|
|
|