|
All you've done is create a file with a .docx extension, not a true Word 2007 document.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am creating an application in VC++4 on Win CE5. The application is for a smart device with ARMV4I CPU. The code is compiled under the device SDK.
In the below code, I try to write all objects passed in an CArray object. The error that I get is also mentioned below.
void DbOperations::WriteDepartments(CArray<DeptDetails, DeptDetails&> dptArr)
{
HANDLE hFile = CreateFile(DEPT_FILE,
GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Error OPeniong File"));
else {
CFile myfile((int)hFile);
CArchive ar(&myfile, CArchive::store);
if (dptArr.GetSize() == 0)
return;
for (int pos=0; pos < dptArr.GetSize(); pos++) {
DeptDetails& ddt = dptArr.ElementAt(pos);
ddt.Serialize(ar);
ddt.~DeptDetails();
}
myfile.Close();
}
return;
}
ERROR: c:\program files\windows ce tools\wce500\mc1000c50\mfc\include\afxtempl.h(855) : error C2582: 'DeptDetails' : 'operator =' function is unavailable
c:\program files\windows ce tools\wce500\mc1000c50\mfc\include\afxtempl.h(1578) : while compiling class-template member function 'struct __POSITION *__cdecl CList<class DeptDetails,class DeptDetails &>::AddTail(class DeptDetails &)'
Error executing clarm.exe.
I also tried the above with CMapStringToPtr
void DbOperations::WriteDepartments(CMapStringToPtr dptMap)
{
HANDLE hFile = CreateFile(DEPT_FILE,
GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Error OPeniong File"));
else {
CFile myfile((int)hFile);
CString key;
DeptDetails* dd;
CArchive ar(&myfile, CArchive::store);
for (POSITION pos = dptMap.GetStartPosition(); pos != NULL;) {
dptMap.GetNextAssoc(pos, key, (DeptDetails*&)dd );
dd->Serialize(ar);
}
key.Empty();
dd->~DeptDetails();
myfile.Close();
}
return;
}
ERROR : : error C2664: 'GetNextAssoc' : cannot convert parameter 3 from 'class DeptDetails *' to 'void *& '
A reference that is not to 'const' cannot be bound to a non-lvalue
Error executing clarm.exe.
Also, if I don't comment the code of CMap, I don't get any errot of CArray; only error of CMap else of CArray.
Does anyone has any idea where I am going wrong. Please help me out.
Thanks
Terry
|
|
|
|
|
What does the declaration of DeptDetails look like?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Trupti Mehta wrote: ERROR: c:\program files\windows ce tools\wce500\mc1000c50\mfc\include\afxtempl.h(855) : error C2582: 'DeptDetails' : 'operator =' function is unavailable
c:\program files\windows ce tools\wce500\mc1000c50\mfc\include\afxtempl.h(1578) : while compiling class-template member function 'struct __POSITION *__cdecl CList<class deptdetails,class="" deptdetails="" &="">::AddTail(class DeptDetails & [Wink] '
Error executing clarm.exe.
I think DeptDetails is derived from CObject , because you are serializing it. If your class is derived from CObject, the compiler won't generate default copy constructor and assignment operator for your derived class. So you should provide it. For more info - http://msdn.microsoft.com/en-us/library/ccb3dh5c.aspx[^]
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Yes you are absolutely correct, DeptDetails is derived from CObject & IMPLEMENT_SERIAL(DeptDetails, CObject, 1);
is added as expected.
Thanks for your help.
Based on your link, I added both constructor/method :
public:
DeptDetails(const DeptDetails &d);
DeptDetails& operator=(const DeptDetails &d);
And implemented as :
DeptDetails::DeptDetails(const DeptDetails &d) {
deptNo = d.deptNo;
deptName = d.deptName;
vat = d.vat;
}
DeptDetails& operator=(const DeptDetails &d) {
deptNo = d.GetDeptNo();
deptName = d.GetDeptName();
vat = d.GetVat();
return *this;
}
Copy constructor is perfect, but operator assignment gives 8 error :
eptDetails.cpp
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(28) : error C2801: 'operator =' must be a <Unknown> member
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(29) : error C2065: 'deptNo' : undeclared identifier
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(29) : error C2662: 'GetDeptNo' : cannot convert 'this' pointer from 'const class DeptDetails' to 'class DeptDetails &'
Conversion loses qualifiers
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(30) : error C2065: 'deptName' : undeclared identifier
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(30) : error C2662: 'GetDeptName' : cannot convert 'this' pointer from 'const class DeptDetails' to 'class DeptDetails &'
Conversion loses qualifiers
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(31) : error C2065: 'vat' : undeclared identifier
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(31) : error C2662: 'GetVat' : cannot convert 'this' pointer from 'const class DeptDetails' to 'class DeptDetails &'
Conversion loses qualifiers
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(33) : error C2673: '=' : global functions do not have 'this' pointers
Error executing clarm.exe.
DeptDetails.obj - 8 error(s), 0 warning(s)
I tried a lot, and understand that their is a simple minute mistake which is causing so many errors, but couldn't trap the mistake.
Can please help me know the mistake and resolve the errors.
I appreciate your help.
Thanks
Terry
|
|
|
|
|
Trupti Mehta wrote: // Assignment operator
DeptDetails& operator=(const DeptDetails &d) {
deptNo = d.GetDeptNo();
deptName = d.GetDeptName();
vat = d.GetVat();
return *this;
}
Did you forget to add DeptDetails:: while copy pasting the function signature from header to cpp?
DeptDetails& DeptDetails::operator=(const DeptDetails &d)
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Thanks Jijo,
But this didn't solve the Map error of the followng function:
void DbOperations::WriteDepartments(CMapStringToPtr dptMap)
{
HANDLE hFile = CreateFile(DEPT_FILE,
GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Error OPeniong File"));
else {
CFile myfile((int)hFile);
CString key;
DeptDetails* dd;
CArchive ar(&myfile, CArchive::store);
for (POSITION pos = dptMap.GetStartPosition(); pos != NULL;) {
dptMap.GetNextAssoc(pos, key, (DeptDetails&)dd );
dd->Serialize(ar);
}
key.Empty();
dd->~DeptDetails();
myfile.Close();
}
return;
}
On GetNextAssoc method, I still get :
error C2664: 'GetNextAssoc' : cannot convert parameter 3 from 'class DeptDetails *' to 'void *& '
A reference that is not to 'const' cannot be bound to a non-lvalue
Error executing clarm.exe.
How to resolve this error yet? Do i have to write another operator= for DeptDetails*. Can you let me know the code so I don't make mistake again.
I highly appreciate for your quick and helpful responses.
One more query I have:
I wanted to store deptNo (int) as key & DeptDetails as value in a Map. I looked at CMap but couldn't find any method to iterate the map contents, hence selected CMapStringToPtr seemed to be best suited to store deptNo in the form of CString. Is this decision correct or should I approach some other class of CMap.
Thanks
Terry
|
|
|
|
|
Buddy, sorry for the late reply. I went to city with my friend to buy a brand new helmet. So back to your problem,
Trupti Mehta wrote: dptMap.GetNextAssoc(pos, key, (DeptDetails& [Wink] dd ); //.GetNextAssoc(pos, key, (DeptDetails*& [Wink] dd);
The reason for your last error is - 3ed parameter of GetNextAssoc() expects CObject*& . Rewrite the code snippet as follows,
DeptDetails* dd;
...
dptMap.GetNextAssoc(pos, key, ((CObject*&)dd);
Trupti Mehta wrote: How to resolve this error yet? Do i have to write another operator= for DeptDetails*. Can you let me know the code so I don't make mistake again.
I hope everything will be solved by this fix. Yep, I've posted the code snippet!
Trupti Mehta wrote: One more query I have:
I wanted to store deptNo (int) as key & DeptDetails as value in a Map. I looked at CMap but couldn't find any method to iterate the map contents, hence selected CMapStringToPtr seemed to be best suited to store deptNo in the form of CString. Is this decision correct or should I approach some other class of CMap.
1) You can iterate CMap by using GetStartPosition() and GetNextAssoc() .
2) Since your intention is to keep int as key, instead of CMapStringToPtr , CMapWordToPtr will be more suitable, because it have mapkey as word by default and you can avoid that DepartNo to CString conversion.
Feel free to ask more doubts, if you have.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
No Jijo,
This is what I had tried earlier and tried again on your code snppet. But still no change.
DeptDetails implements Serialization, so IMPLEMENT_SERIAL & DYNAMIC_SErial are added in .h & .cpp files. CMapStrToPtr & CMapWordToPtr both needs DYNAMIC.
I commented DYNAMIC SERIAL in both files & tried again but still same error
ERROR :
Cannot convert (CObject*) to void*&
I am implementing in Win CE 5, just if this info bes any help to u. Help says CMAP & respective sub types supports Win Ce 1 & further.
Thanks
Terry
|
|
|
|
|
Terry,
If that still throws and error, then the reason might be something different. Could you post the full code snippet of DeptDetails class? the header and cpp. I'll try to isolate the issue.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
class DeptDetails : public CObject
{
DECLARE_SERIAL(DeptDetails);
public:
DeptDetails(void);
DeptDetails(int dno, CString name, float vat);
DeptDetails(const DeptDetails &d);
DeptDetails& operator=(const DeptDetails &d);
IMPLEMENT_SERIAL(DeptDetails, CObject, 1);
DeptDetails::DeptDetails(void)
: deptNo(0)
, deptName(_T(""))
, vat(0)
{
}
DeptDetails::DeptDetails(int dno, CString name, float vat) {
deptNo = dno;
deptName = name;
this->vat = vat;
}
DeptDetails::DeptDetails(const DeptDetails &d) {
deptNo = d.deptNo;
deptName = d.deptName;
vat = d.vat;
}
DeptDetails& DeptDetails::operator=(const DeptDetails &d) {
deptNo = d.deptNo;
deptName = d.deptName;
vat = d.vat;
return *this;
}
class DbOperations
{
public:
CMap<int, int, DeptDetails, DeptDetails> deptMap;
void WriteOperators(CMap<int, int, OperatorDetails, OperatorDetails> opdtMap);
void DbOperations::WriteDepartments(CMap<int, int, DeptDetails, DeptDetails> dptMap)
{
HANDLE hFile = CreateFile(DEPT_FILE,
GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Error OPeniong File"));
else {
CFile myfile((int)hFile);
int key;
DeptDetails dd;
CArchive ar(&myfile, CArchive::store);
for (POSITION pos = dptMap.GetStartPosition(); pos != NULL;) {
dptMap.GetNextAssoc(pos, key, dd );
ar.WriteObject(&dd);
}
dd.~DeptDetails();
ar.Close();
myfile.Close();
}
return;
}
CMap<int, int, DeptDetails, DeptDetails> DbOperations::ReadDepartments()
{
if(deptMap.IsEmpty() == false)
deptMap.RemoveAll();
HANDLE hFile = CreateFile(DEPT_FILE,
GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Error OPeniong File"));
else {
CFile myfile((int)hFile);
int key;
DeptDetails* dd;
int i;
myfile.SeekToBegin();
CArchive ar(&myfile, CArchive::load);
dd = (DeptDetails*) ar.ReadObject( RUNTIME_CLASS(DeptDetails) );
delete dd;
dd->~DeptDetails();
myfile.Close();
}
return deptMap;
}
Regardingly, for all CMap... DYNAMIC_SERIAL objectS ARE NOT supported, its only CMap where the object can be of DYNAMIC_SERIAL/IMPLEMENT_SERIAL. CMap was my first inital preference but by looking at other CMap classes, I opted them, but not on returning to CMap things are fine. I mean 0 errors 0 warnings. I only get error at SetAt in ReadDepartments(). Have I implemented the CArchive correctly in Write & Read Departments. Please check out that.
I have come back in VC++ after long time, so many things are new and many out of the mind also. Hope to get this woring correctly at the earliest.
Thanks
Terry
|
|
|
|
|
Terry your map is CMap < int, int, DeptDetails, DeptDetails > where you are supposed to insert an object of DeptDetails .
Trupti Mehta wrote: // deptMap.SetAt(i, dd);
But dd, which you're inserting is a pointer where object is expected. So you should use it like as follows,
deptMap.SetAt(i, *dd);
Trupti Mehta wrote: Have I implemented the CArchive correctly in Write & Read Departments. Please check out that.
Seems Fine by looking with my eyes.
Trupti Mehta wrote: I have come back in VC++ after long time, so many things are new and many out of the mind also. Hope to get this woring correctly at the earliest.
No probs buddy. Feel free to shoot any doubts.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Thanks Jijo for all your help and efforts.
I am able to write data to the file from map, but couldn't check the dat file.
As I am working on CE, couldn't even read the data as after closing the Enumarator, the files are deleted. But the file is writing correctly so I hope reading will also perform correctly only.
Now, I have problem of communicating between parent & child dialogs & on child dialog's message parent should hide that child and show another child dialog. As this question is out of this topic so am creating a new one. Hope will get help from you in that topic too.
Once again thanks.
Thanks
Terry
|
|
|
|
|
Trupti Mehta wrote: But the file is writing correctly so I hope reading will also perform correctly only.
So happy to hear the good news!
Trupti Mehta wrote: Hope will get help from you in that topic too.
Sure. I'll have a look at it.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
I have been working on VS2005 for the past one month now. I am working on an MFC application which runs fine when run through code. When I try to run the exe of my application from the debug/release folder, a runtime error with a message "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information".
When I use Dependency Walker, I see that the exe makes a reference to DWMAPI.dll. I searched on Google and found out that DWMAPI.dll is not available on WindowsXP. Some other people had mentioned about the same problem, suspecting that IE7 might be the cause for the problem. I uninstalled IE7 and the exe still could not be run. After uninstalling IE7, the Dependency Walker says that it could not find IEUI.exe along with DWMAPI.dll. So, I think IE7 was not the cause for the problem.
I have been trying to solve it since past two days, but with no success. I had never had that error popping up when I used to write applications in VS2003. Had anyone come across this problem before? If yes, what did you do to solve it.
Regards,
Vijay.
|
|
|
|
|
vijay7173 wrote: When I use Dependency Walker, I see that the exe makes a reference to DWMAPI.dll.
With and without the IDE?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You're missing that DWMAPI.DLL is a delay-loaded DLL and will only be loaded by IEFRAME.DLL if a referenced function is actually called (which it won't be because it's not running on Windows Vista).
This message is displayed whenever abort() is called. You may be allowing a C++ exception to go unhandled, which I believe ultimately calls abort.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
Hi to all,
I know it is a stupid question, but I couldn't find any function that deletes a directory and all its contents.
I've tried to use Directory.Remove() but for some reason my compiler does not recognise System as a valid namespace.
Thanks for the help
|
|
|
|
|
Are you sure that is a Visual C++ / MFC question?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Well... I would thought so, as I want to do it programmatically in my C++ application.
Am I wrong?
|
|
|
|
|
System namespace belongs to the .NET Framework .
See [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Ok, I didn't know that, sorry.
|
|
|
|
|
You can delete any directory using RemoveDirectory() function, provided that the directory which is being deleted is empty. So, you will first have to delete all the files of the directory (by using DeleteFile() function) and then use RemoveDirectory() to delete it.
Regards,
Vijay.
|
|
|
|
|
|
piul wrote: I know it is a stupid question, but I couldn't find any function that deletes a directory and all its contents.
Use SHFileOperation() .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|