|
I am processing data in a worker thread and calling a member function (of Doc) which performs a file write.
I pass a pointer to CMyAppDoc into the worker thread which I use to access a member function of CMyAppDoc when the thread is created.
The worker thread processes data and stores and stores data in CMyAppDoc using the Doc pointer
pDoc->StorageArray[i] = something;
A little later in this thread when the processing is finished I try to write the data to a file. The function and data are members of CMyAppDoc but the file pointer (myFileFmt) is created within the worker thread. The call is made in the worker thread
pDoc->WriteFmtL15Data(myFileFmt);
The WriteFmtL15 Data does somthing like:
void CLOPCDoc::WriteFmtL15Data(CFile &file)
{
CString sL1("L1"), sL2("L2"), sL3("L3"), sL4("L4"), sL5("L5");
CString tmp("");
for(int a=0; a<=31; a++)
{
tmp.Format(" %d", vecL14[a]);
sL1 += tmp;
}
sL1 += ('\n');
file.Write(sL1, strlen(sL1));
}
When it enters the file writing routine it raises an error:
Unhandled exception in MyApp.exe(MFC42D.DLL): 0xC0000005: Access Violation.
and if I debug the error it bring me to a line in WINCORE.CPP
lResult = pWnd->WindowProc(nMsg, wParam, lParam);
???????????????
|
|
|
|
|
I don't think the problem has to do with myFileFmt being created in the worker thread. To rule this out, you can try (just for the sake of testing) using in WriteFmtL15Data a global CFile object created in the main thread (say in InitInstance ), instead of the one passed in.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
if you know the answer to this one you can probably jump to the last paragraph, others might want to know more...
I have run into a problem. I wanted to create an ActiveX control based on an existing one. So I took the entire Visual Studio project and copied it. Renamed all files (and names therein). And I modifed and registered the new control under the new name. No problem so far. Alas, I then noticed that the original control was gone. As soon as I registered the old or new control the other one was gone. I figured that the UUID was the problem here, (looks like this)
//const GUID CDECL BASED_CODE _tlid =
//{ 0x6fe77b28, 0x50c9, 0x4f53, { 0xb4, 0xe7, 0x13, 0x85, 0xe1, 0x4, 0x4b, 0x76 } };
These IDs are numerous in each project and in at least four different files, and sometimes they appear to refer to each other. I started to make new codes with GUIDGEN.EXE, but gave up because of the cross-referencing which was a bit obscure.
My next idea was to create a new empty activeX project and copy all the IDs. The control registered nicely after a premature attempts, it does not delete the the other control, but fails to load into the test container.
So, I have to create new IDs somehow. Either I made a mistake (despite double-checking) when copying from the empty project, or the IDs themselves contain implicit information about the control. If the ids contain no such info nor checksums and such stuff the best thing would be to back up to the previous working version and just change a single digit. Is this possible? Or, perhaps another problem is that my faulty attemps have left garbage in the registry (2K) which perhaps needs to be cleaned.
I would be truly gratful for any help.
Cheers,
Adam
_____________________________________
Action without thought is not action
Action without emotion is not life
|
|
|
|
|
Perhaps the easiest solution would be to create a new ActiveX Control project from scratch, then add in all the files from your old project and tie them in to your new ActiveX "wrapper".
(I have had to do this myself)
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
Hio.. i am trying to store a CObArray into my document class.. but not having any luck.. I have another class i have written myself which serializes a CObArray into a file, but i can't seem to figure out the correct way to do it in a CDocument as it is not possible to put ar >> CObArrayVar ..
any suggestions? for example, if i want a user to enter in any number of strings, and be able to save it to a document and open it back up, how would i handle the dynamic size?
thanks for any suggestions!
-dz
|
|
|
|
|
See "Serializing a homogenous collection class" in this article.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
i hate to seem dense.. BUT...
ok, i should serialize the signature, then the version, then i should store the number of items in the CObArray.. then i should store each of the CObjects? you say serialize the object, then serialize the data members.. i should be able to just serialize my CObject derived class right? i shouldn't have to specify every data member of it right?
oh ya, im assuming i should do a for loop to CObArray.GetSize() to store each item?
thanks for all of your help lately!
-dz
|
|
|
|
|
dazinith wrote:
i should be able to just serialize my CObject derived class right? i shouldn't have to specify every data member of it right?
Yes, you should serialize the signature, version, size of the CObArray , and each object in the CObArray . The objects in turn should serialize themselves by writing out their signature, version and data members.
Part 3 of my tutorial is crying out for code examples. I haven't had the time to post them but definitely plan to do this when I have some spare time.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
well, i got it to work where i store each of the members of the class in the loop, but i would much rather just store the CObject derived object directly.. the problem is that if i try to do:
ar << objMyObject
it tells me there is nothing that can handle the << . My CObject derived class has the serialization function. I have tried casting it to a CObject and storing that, but i think im storing the pointer value and not the actual data.. i think i got it to save, but when i load it gives errors for unexpected file format.. i have left out the versioning just for simplicity.. i just need to know how to load and store all of the values from the m_oaStringList (which is of CObArray type)
if (ar.IsStoring())
{
ar << m_oaStringList.GetSize(); // store the size of the array
// loop through and store all data members
for (i = 0; i < m_oaStringList.GetSize(); i++)
{
CObject* pObj = m_oaStringList.GetAt(i);
ar << (&pObj);
}
}
else // is loading
{
int n; // load the size of the array
ar >> n;
// loop through and load all data members
for (i = 0; i < n; i++)
{
CObject* pObj = (CObject*)new CTestObj();
ar >> pObj;
}
}
thanks!
-dz
|
|
|
|
|
You're close. There are 2 changes I suggest you make:
- Write a
serialize (CArchive& ar) method for your object. The method will simply serialize the data members of the object (using the << and >> operators). Call this serialize() method instead of doing "ar << pObj" or "ar >≶ pObj". In other words, do "pObj->serialize (ar);" instead.
- When deserializing (reading in), you should set the size of the CObArray before adding members to it. Then, as you deserialize each object (again by simply calling its
serialize() method to read itself in), put the object in the CObArray's appropriate slot.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
thank you so much for your help today.. i got the code to do what i want.. and thats be able to store and load a document based off of CObArray.. I just did a simple object, but now i feel i could use it for a much larger object.. here is the finished code if you want to use it to update that article.. again thanks for the help!
p.s. if you do use this as an example you might want to change the var's as m_oaStringList seems like a CStringArray, but is a CObArray.. thanks so much!
void CDocumentTestDoc::Serialize(CArchive& ar)
{
int i;
if (ar.IsStoring())
{
// store the size of the array
int n = m_oaStringList.GetSize();
ar << n;
// loop through and store all data members
for (i = 0; i < m_oaStringList.GetSize(); i++)
{
CTestObj* pObj = (CTestObj*)m_oaStringList.GetAt(i);
pObj->Serialize(ar);
}
}
else // is loading
{
// load the size of the array
int n;
ar >> n;
m_oaStringList.SetSize(n);
// loop through and load all data members
for (i = 0; i < n; i++)
{
CTestObj* pObj = new CTestObj();
pObj->Serialize(ar);
m_oaStringList.SetAt(i,pObj);
}
}
}
-dz
|
|
|
|
|
dazinith wrote:
i got the code to do what i want..
Excellent!! Glad I could be of help! Now I really must get off my posterior and update the article!
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
is it possible to use these same ideas to store a CObArray inside of another CObArray? for example, if the CObArray im serializing now contains a data variable which is also a CObArray with its own serialize function, when the top level CObArray gets serialized does this in turn call the serialization of the lower object?
-dz
|
|
|
|
|
Absolutely!
The top level CObArray doesn't know how to serialize its content objects. It just tells each one "go serialize yourself". If the content object is another CObArray, it goes about serializing itself by storing its signature, version, item count, and then asks each of its objects to serialize themselves.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
i have a Cedit control that hold phone#.
i can create a display mask to show the phone # like(111)111-1111.
but how can i create this as an imput mask for automatically place the () and- while typing and also not let them type alpha char?
thank you.
|
|
|
|
|
try looking in the Edit Controls section of this site. there are probably five or six of them there.
-c
"Do you mind if I smoke?"
"Madam, I don't care if you burn."
-Oscar Wilde
Smaller Animals Software, Inc.
|
|
|
|
|
http://www.codeproject.com/editctrl/maskededit.asp
im using this control, its pretty k-rad, but it seems to have a problem when tabbing from field to field (doesn't highlight the field)..
btw, the typo in the title made me laugh
-dz
|
|
|
|
|
What the hell is "k-rad" ? is it kEwl sPeEK ??
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
somethin like that
-dz
|
|
|
|
|
Hi guys
Does anyone know how to change the icon of an executable? I could really do with a handy application or something.
Cheers
Tom
|
|
|
|
|
In your project's ResourceView, click on Icon, you will find IDR_MAINFRAME, that's the icons used for your executable. Remember to change both the Standard (32x32) and Small (16x16).
|
|
|
|
|
The icon shown for an executable by Explorer is the one with the lowest ID. If you have VS, you can edit the resources for any program; just open it as a resource file.
Sometimes i only remember, The days when i was young Nowadays no one remembers when they were young and stupid... ADEMA, The Way You Like It
|
|
|
|
|
If you don't have the source, try ResHacker.
/moliate
|
|
|
|
|
Here's a simple program I wrote just now:
#include "iostream.h"
#include "fstream.h"
void main()
{
int array;
ifstream infile ("binga");
infile >> array;
cout << array << endl;
}
the file binga looks like this:
1,2,3,4,5,6
a,b,c,d,e,f
one,two,three,four,five,six
So when I run the program, why do get the output as
-858993460
shouldn't the output just be
1
|
|
|
|
|
Your program does the equivalent of atoi("1,2,3,4,5,6") when enters infile>>array. You have to use space or CR to separate the numbers, not commas.
rechi
|
|
|
|
|