|
hello everyone,
I am trying to read in a list structure which is serialized as
m_DataPointerList.Serialize( ar );
where m_DataPointerList is defined as :
CTypedPtrList m_DataPointerList;
and class CDataPointer is declared as:
class CDataPointer : public CObject
{
public:
CDataPointer();
protected:
DECLARE_SERIAL(CDataPointer)
protected:
public:
unsigned long Time; unsigned char Channel;
unsigned char Rate;
public:
virtual void Serialize(CArchive& ar);
};
and defined as:
IMPLEMENT_SERIAL(CDataPointer, CObject, 1)
CDataPointer::CDataPointer()
{
}
void CDataPointer::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << Time;
ar << Channel;
ar << Rate;
}
else
{
ar >> Time;
ar >> Channel;
ar >> Rate;
}
}
I am having some difficulties( i donno why?) in reading it in using the same serializing command ie:
m_DataPointerList.Serialize( ar );
is there any thing i am overlooking while i am doing this??
on the other hand,
I try to read this using a 'for' loop
which iterates for the number of occurances of CDataPointer. but i have to add an offset at the end of every iteration if I were to read the next iteration correctly.
something like
nDataCounter=ar.ReadCount();
for(i=0;i
{
ar>>Time[i];
ar>>Channel[i];
ar>>Rate[i];
ar.Flush();
pFile->Seek(offSET, CFile::current);
}
i dont understand why i have to provide this offset.and i have trouble choosing the correct offSET as it varies for different lists. again is there something i am doing wrong ?
Can please you give me some insight into these two issues??
Thanks a lot
|
|
|
|
|
sorry m_DataPointerList has to be defined as
CTypedPtrList<coblist,cdatapointer*> m_DataPointerList;
and not as typed wrongly
|
|
|
|
|
|
i am not serializing each variable but the list as a whole like
m_DataPointerList.Serialize();
i donno why i am not able to make the deserialization code work if i do
m_DataPointerList.Serialize() during deserialization.
I debugged at what's going wrong at the instant when I call: m_DataPointerList.Serialize() . The error I get is
Warning: Cannot load CDataPointer from archive. Class not defined.
CArchive exception: badClass.
When i further debug as to why this is happening I think this is where it is getting wrong. It goes into this class(code shown below) with lpszClassName = CDataPointer and tries to compare with pClass->m_lpszClassName, in the for loop where it searches classes in shared DLL's. I get some classes in pClass->m_lpszClassName but not CDataPointer. eventually since it couldnt find a matching class this function returns NULL.
CRuntimeClass* PASCAL CRuntimeClass::FromName(LPCSTR lpszClassName)
{
CRuntimeClass* pClass;
// search app specific classes
AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
AfxLockGlobals(CRIT_RUNTIMECLASSLIST);
// this for loop is skipped
for (pClass = pModuleState->m_classList; pClass != NULL;
pClass = pClass->m_pNextClass)
{
if (lstrcmpA(lpszClassName, pClass->m_lpszClassName) == 0)
{
AfxUnlockGlobals(CRIT_RUNTIMECLASSLIST);
return pClass;
}
}
AfxUnlockGlobals(CRIT_RUNTIMECLASSLIST);
#ifdef _AFXDLL
// search classes in shared DLLs
AfxLockGlobals(CRIT_DYNLINKLIST);
//enters this for loop
for (CDynLinkLibrary* pDLL = pModuleState->m_libraryList; pDLL != NULL;
pDLL = pDLL->m_pNextDLL)
{
for (pClass = pDLL->m_classList; pClass != NULL;
pClass = pClass->m_pNextClass)
{
//comparison is done here
if (lstrcmpA(lpszClassName, pClass->m_lpszClassName) == 0)
{
AfxUnlockGlobals(CRIT_DYNLINKLIST);
return pClass;
}
}
}
AfxUnlockGlobals(CRIT_DYNLINKLIST);
#endif
return NULL; // not found
}
I really dont know how i can tackle pClass->m_lpszClassName so that it picks up the name of m_lpszClassName (here CDataPointer)
Also i can read in the values using the for loop but i need to provide some offset at the end of each iteration which is quite tricky for me.Please give me some suggestions on this
|
|
|
|
|
1) From Programming MFC book by Jeff Prosise...
WriteObject ultimately calls the object's Serialize function to serialize the object's data members, but before it does, it writes additional information to the archive that identifies the class from which the object was created.
For example, suppose the object being serialized is an instance of CLine. The very first time it serializes a CLine to the archive, WriteObject inserts a new class tag—a 16-bit integer whose value is -1, or 0xFFFF—into the archive, followed by the object's 16-bit schema number, a 16-bit value denoting the number of characters in the class name, and finally the class name itself. WriteObject then calls the CLine's Serialize function to serialize the CLine's data members.
If a second CLine is written to the archive, WriteObject behaves differently. When it writes a new class tag to the archive, WriteObject adds the class name to an in-memory database (actually, an instance of CMapPtrToPtr) and assigns the class a unique identifier that is in reality an index into the database. If no other classes have been written to the archive, the first CLine written to disk is assigned an index of 1. When asked to write a second CLine to the archive, WriteObject checks the database, sees that CLine is already recorded, and instead of writing redundant information to the archive, writes a 16-bit value that consists of the class index ORed with an old class tag (0x8000). It then calls the CLine's Serialize function as before. Thus, the first instance of a class written to an archive is marked with a new class tag, a schema number, and a class name; subsequent instances are tagged with 16-bit values whose lower 15 bits identify a previously recorded schema number and class name.
So, assuming you have 2 objects in your list, both of which have zero for all their member variable values, the file should look like this...
<br />
Bytes Description<br />
(Hex)<br />
----- -----------<br />
02 00 Number of objects in list (WORD)<br />
<br />
FF FF New class tag (WORD)<br />
01 00 Schema number (WORD)<br />
0C 00 Length of "CDataPointer" (WORD)<br />
43 44 61 74 61 50 6F 69 6E 74 65 72 "CDataPointer" (char)<br />
00 00 00 00 Time value for 1st object (DWORD)<br />
00 Channel value for 1st object (BYTE)<br />
00 Rate value for 1st object (BYTE)<br />
<br />
01 80 Class tag for 2nd object (WORD)<br />
00 00 00 00 Time value for 2nd object (DWORD)<br />
00 Channel value for 2nd object (BYTE)<br />
00 Rate value for 2nd object (BYTE)<br />
<br />
Note: See CArchive::ReadCount code in your Visual Studio folder for explanation as to why the count is a WORD value in this case. <br />
So now you know what those offsets are.
2) The only thing I can think of concerning a bad class name error, is that you've renamed the class (or changed something else in the class) since the last time it was written to the file. For example, if your class was originally called CDataPointer, the serialization process will have written "CDataPointer" to file when it's saved. When the file is read back in, the serialization process finds "CDataPointer" in the file, and thus tries to create an object of type CDataPointer, which it can't do since it's been renamed to CChangedClassName.
You should download a Hex editor, then you can open the file up, and see if the data is as expected.
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
I have done an COM library that using VC++6.0, there is "Logon" interface was contained and detail codes below:
<br />
NETRESOURCE nr;<br />
::memset(&nr, NULL, sizeof(NETRESOURCE));<br />
<br />
nr.dwType = RESOURCETYPE_ANY;<br />
nr.lpRemoteName = str.LockBuffer();<br />
nr.lpProvider = _T("Microsoft Windows Network");<br />
nr.dwDisplayType = RESOURCEDISPLAYTYPE_SERVER;<br />
<br />
DWORD dwResult = ::WNetAddConnection2(&nr, _T("password"), _T("username"), CONNECT_UPDATE_PROFILE);<br />
the "Logon" interface is successful to return "NO_ERROR" which are invoked by VB. but while the "Logon" interface is invoked by ASP(Active Service Page), however results is to return a error that's:
<br />
ERROR_NO_SUCH_LOGON_SESSION<br />
to search into "Winerror.h" that have some description about the error:
<br />
via Google to search about the "ERROR_NO_SUCH_LOGON_SESSION", Unfortunate nothing can hele me ((
|
|
|
|
|
This is a bit of a guess, but I would imagine that the problem stems from the security context that the ASP page is running under. Under XP and 2003, network access for the web server is severely limited. The CONNECT_UPDATE_PROFILE flag might also be causing the problem - I'm not sure that the relevant security context has a "profile" to be updated.
|
|
|
|
|
Firstly, Appreciate for lots of help. to refer your advice I succeeded to run it under Win2000
However XP and 2003 havn't still exist that don't connect throughout, if the problem is from the security context of the ASP page, could you give a solution to me?
Another, I used CONNECT_TEMPORARY instead of CONNECT_UPDATE_PROFILE flag under XP and 2003, the result don't any change.
|
|
|
|
|
Hello Sir!!
IphlPapi.h is very well documented , you have to just search for it your local copy of MSDN
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
I had been to ur website. and wanted to post a suggestiong but could not find a place over there.
The site is on the right hand side, i.e. Right justified, I would suggest you to make it left justified or center justified, coz on my wide monitor the page is on the wrong end of the screen.
-prakash
|
|
|
|
|
I had been to ur website. and wanted to post a suggestiong but could not find a place over there.
The site is on the right hand side, i.e. Right justified, I would suggest you to make it left justified or center justified, coz on my wide monitor the page is on the wrong end of the screen.
-prakash
|
|
|
|
|
Sir,
thanks for suggestion,actually i created that webpage on 15 inch monitor,so really i don't know how's it look like on Wide Screen Monitor.i will try to imporve it as easrly as possible. juts like to know any more sugeestion related my site.
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Please dont call me sir.
-prakash
|
|
|
|
|
Mr.Prakash wrote:
Please dont call me sir.
Why , I am just giving you respect
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
where can i dl ipexport.h?
what is ti use?
thanx
|
|
|
|
|
hi all,
I am doing a MFC Application using Dialog Wizard.
I have added a Menu to Dialog.
Now I want to change the Color of Menu..I tried it but it is difficult to me.
If any one know this please ,reply me ..
I can change the Color of static controls,edit boxes..But I don't know to change the Color of Menues..
Thanks in advance..
|
|
|
|
|
Frustration!
I am trying to assign the value of a character array char my_array[99]; to a combo box but am just getting cryptic messages about boxing and __gc / __value.
I know that this should be very simple, I have found many examples using comboBox1->Items->Add(S"some text") but cannot seem to get it to use the contents of my variables
Please help, not much hair left!
|
|
|
|
|
The AddString() method takes a pointer to a null-terminated string, not a single character, which is what my_array[99] refers to. In other words, this will not work:
m_combobox.AddString(my_array[99]); but this will:
CString str = my_array[99];
m_combobox.AddString(str); You could also do something like:
char c[2] = {0};
c[0] = my_array[99];
m_combobox.AddString(c);
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks for the suggestion.
Still having problems - I hope I am missing something obvious
These are the build errors I get from the code snippet above.
AddString' : is not a member of 'System::Windows::Forms::ComboBox'
stdafx.cpp(0) : see declaration of 'System::Windows::Forms::ComboBox'
error C2065: 'Cstring' : undeclared identifier
etc.
I am using Microsoft Visual C++ .NET
|
|
|
|
|
Rich Wright wrote:
AddString' : is not a member of 'System::Windows::Forms::ComboBox'
Perhaps you need to use the AddItemsCore() method.
Rich Wright wrote:
I am using Microsoft Visual C++ .NET
I've not ever used this. Plenty of others here have, however.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
it is because you are not programing with MFC...
... and the string class is CString, not Cstring (the 'S' in upper case), but here again, not sure that it works if you are not with MFC...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
you could cast your my_array into something more manageable.
me think that you should not use character array in C++ or Managed C++.
or post in the Managed C++ forum, because it's a .net specific question.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Maximilien wrote:
me think that you should not use character array in C++
why ??? arrays are very useful, even char ones !!! of course, there are very performant classes that manage strings instead of the legendary C char* , but sometimes, you cannot do without...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi I need alot of help in trying to do this coursework. Can anyone give me help in this. here what is to be done.
The system he requires is very simple; he needs to have the ability to renew the membership of existing clients, to enrol new clients and to generate letters to remind clients whose membership is about to lapse
The progam should:
define appropriate user-defined data types (enumerations and/or structs) to model the data of the application.
read the client data from the data file and store it in a convenient form.
enrol new clients.
renew membership of clients.
perform a search through the data for clients whose membership is about to run out and generate a reminder letter.
save the client data to a data file.
I have tried to attempt it but never got past the first stage.
Cheers
|
|
|
|
|
Flame123 wrote:
I have tried to attempt it but never got past the first stage.
Show us the code you do have and we can probably steer you in the right direction.
Where is the membership information stored?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|