|
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
|
|
|
|
|
using SYSTEM.IO; can help
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hi,
I am using Visual C++ 2005 Pro IDE with SP1 for developing a MFC application. In my application there is a header file which contains application constants inside a namespace like
In file AppCommon.h
namespace APP_CONSTANTS
{
const int MAX_BUFFER_SIZE = 100;
const CString appStartupMsg = _T("Welcome to application");
....
};
Now when I use this header file and try accessing the variable as
APP_CONTANTS:: then the auto complete feature of Visual Studio always shows only the first defined variable. Can someone pleasae tell me how do I get the intellisense to display the other defined variables inside the namespace when trying to use auto complete feature?
I have tried deleting all the extra files (ncb, sbr etc...) and tried rebuilding the application for no success.
Thanks and Regards
|
|
|
|
|
VS intellisense is bad bad bad.
personlay i shifted to using Visual Assist X product.
you can get an eval of it.
first instal then when u open ur proj, giv it some time to parse evrything.(lokk at the status bar when it finished)
if after that it failed to give you completion regarding this namespace..then open the file code, and enter the menu and choose the reparse this file command.
..
perhaps somebody else could help you how to force VS intellisence to parse that namespace file...
Our Philosophy, Mohammed Baqir Al Sadr
|
|
|
|
|
psychedelic_fur wrote: Now when I use this header file and try accessing the variable as
APP_CONTANTS:: then the auto complete feature of Visual Studio always shows only the first defined variable.
What happens if you swap the order of MAX_BUFFER_SIZE and appStartupMsg ?
"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
|
|
|
|
|
Hi,
I am facing a problem with Japanese font - MS UI Gothic ,regular,16.. We have a function for handling Japanese strings.. But as per current implementation.. after user types any text onto a dialog and presses enter or minimizes the dialog then the entered text is turning bold. Our current implementation is
DWORD DrawJapaneseString( HWND hWnd, PSTR str, LPRECT lpR)
{
HDC hDC;
DWORD dwExt;
int xStart = 0;
HFONT htempFont;
RECT charRect;
HideCaret( hWnd );
hDC = GetDC( hWnd );
dwExt = GetTextBoundingSize( hDC, (LPSTR) str, textLen, &xStart );
if( GetSystemMetrics(SM_DBCSENABLED)) {
SetRect( (LPRECT) &charRect,
textStart.x,textStart.y,
textStart.x+LOWORD(dwExt), textStart.y+ HIWORD(dwExt));
// AppRedraw expands rectangle by 10 anyway...
AppRedraw( hWnd, &charRect );
SetTextColor( hDC, textPen.lopnColor );
int nmode = SetBkMode( hDC, TRANSPARENT );
DrawText(hDC,str,textLen,&charRect,DT_LEFT);
SetBkMode( hDC, nmode);
textLoc.x = charRect.right;
}
ReleaseDC( hWnd, hDC );
ShowCaret( hWnd );
return( dwExt );
}
Can I know how to stop the text turning to bold.
Thanks.
|
|
|
|
|