I have been using controls in VC++ 6.0 for years without any particular problem.
This time I wanted to shift to VC++ under VS2008, using unmanaged code .
I thought the same code that creates a trivial main window, and then the simplest Static control in the main window, would work well with VS2008 too.
It doesn't seem so .
I am wondering what's wrong with the following snippet :
I can see the main window appearing with the menu and all the rest, but the Static control doesn't appear.
I get a NULL handle as a return from its CreateWindow (). The error code is 1407, appearently meaning that the control class ("Static") is unknown.
I have been seaching all the MSDN documentation without finding an useful hint.
What's even stranger , the above code works perfectly under VC++ 6.0.
Any idea ?
how to replace \n with alt+enter while exporting to .CSV
I am writing line by line to a file(.CSV). If the string is having "\n" in between then the multiline is not possible for a single cell and it is coming to the next line of Excel .
Can anyone help me to replace the "\n" with "Alt+Enter" equivalent?
I am using CSting to collect the entire line at a tiime.
I am trying as below
Let the line feed in place and enclose the cell content by double quotes. This should be accepted by Excel when rows are terminated by carriage return - line feed pairs. So your CSV file should look like:
Row1:Col1, "Row1:Col2\n with new line"\r\n
Row2:Col1, "Row2:Col2, with comma"\r\n
Row3:Col1, "Row3:Col2 with "" esacped quote"\r\n
Row4:Col1, " Row4:Col2 begins and/or ends with space "\r\n
As an alternative you may write HTML files using tables. These can be also imported by Excel.
The output window show the following error messages:
First-chance exception at 0xfefefefe in SchPedestal.exe: 0xC0000005: Access violation.
Unhandled exception at 0xfefefefe in SchPedestal.exe: 0xC0000005: Access violation.
The program ' SchPedestal.exe: Native' has exited with code -1073741819 (0xc0000005).
ClassInfo inherits from CPropertySheet, while the other objects inherit from CPropertyPage.
If you expect the error to be in the posted code, set a breakpoint on top and use the debugger to step through the instructions until the error occurs. Then check your variables to find out which is generating the access violation.
ClassInfo inherits from CPropertyPage, while the other objects inherit from CPropertyPage.
The program successfully displays the wizards start page, but once I click next, this access violation occurs
Debugging shows that the access violation occurred in the following function:
CComboBox *pSchoolName = (CComboBox *)GetDlgItem(IDC_COMBO1);
//Get database path
StringCbCopyA(szString,sizeof(szString),"SELECT SchInfoID,SchName,SchCity,SchState,SchCountry FROM SchInfo");
CppA::CppSQLite3Query q = db.execQuery(szString);
//Gets first row
for (int fld = 0; fld < q.numFields(); fld++)
iSchoolInfoID = q.getInt64Field(0);
p = q.getStringField(1);
p = q.getStringField(2);
p = q.getStringField(3);
p = q.getStringField(4);
int i = pSchoolName->AddString(szSchoolName);//This is where the access violation occurred.
catch(CppA::CppSQLite3Exception & e)
StringCbPrintfA(szString,sizeof(szString),"Error Code: %d\n Error Mesage: %s",e.errorCode(),e.errorMessage());
MessageBoxA(NULL,szString,"Load shc name Error",MB_OK);
Actually, at the start the property page objects were members of the PropertySheet object.
Also, initially, the LoadSchoolName function was part of a win32 dll( I made it so for maintenace purpose) which the MFC extension dll ClassInfo.dll load or links with.
But when access violation kept occuring at that location of the function, I decided to make the function a member function in the MFC extension DLL, rather that a win32 dll.
Well, that did not solve the problem. So, I read through msdn and saw that example on DoModal() did not make the property pages member of the propertysheet object, so I decided to try that next, but still the same problem.
Shown below is the function that calls the LoadSchoolName function:
ClassInfo * pPropertySheet = (ClassInfo *)m_Pointer;
CComboBox *pCombo2 = (CComboBox *)GetDlgItem(IDC_COMBO2);
int i = 0;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
The OnInitDialog function loads various school names from data base and uses them to fill the stated combobox. Like I said the wizard displays the wizard's start page , but each time I click next, the the access violation occurs.
If I comment out the LoadSchoolName function, the wizard successfully load the next Property page , but with an empty combobox.
So I decided to replace the combobox pointer in the LoadSchoolName function with a
Object( I cast each SchoolName TCHAR pointer to ULONG_PTR using a reinterpret_cast. So that I call add the strings to the combobox from the CArray object.
On doing this , access violation occures at the point in the code where I call CArray
It appears thar whetther I try to add the string to a combobox or an array, each time I attempt to addd the school name string, access violation occurs. I don't just understand why.
You are formatting quite a lot of things into the school name. Maybe you create more than 100 characters and the StringCbPrintf() doesn't add the terminating \0 character in that case. You could try
szSchoolName = 0;
before calling AddString() and see if that changes anything.
The good thing about pessimism is, that you are always either right or pleasently surprised.