|
To avoid confusion, in the original snippet the class declared in the CreateWindow is "Static", and not "Label" as stated . Sorry for the mistake .
|
|
|
|
|
You cannot simply use typecasting.
Try L"Static" .
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
hLabelPath = CreateWindow ((LPCWSTR)"LABEL", ...
You cannot use a cast to convert an ASCII string to Unicode. Use the correct form, either L"string value" or TEXT("string value") .
|
|
|
|
|
Thank you both Superman and Richard ... now the Static appears correctly ...
|
|
|
|
|
how to replace \n with alt+enter while exporting to .CSV
HI,
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
CSting temp;
temp.Replace("\n", ""));
Thanks
SMA
|
|
|
|
|
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.
|
|
|
|
|
Normally, I code using win32 API. I just moved to MFC.
I wrote this MFC code for a wizard but keep getting exceptions thrown. A first chance exception to be precise.
My wizard is contained in an MFC extension dll.
The wizard is lunch from an handler of CMainFrame.
The CMainFrame from which the wizard is lunched is:
void CMainFrame::OnAddClassInfo()
{
CWinApp *pWinApp = AfxGetApp();
FirstPage firstPage;
ClassNameA className;
ClassTerm classTerm;
ClassSubjects classSubjects;
ClassStaff classStaff;
StopPage stopPage;
className.SetAccess(m_szAccessUsername,m_szAccessPassword);
className.SetClassInfo(m_iClassTypeID, m_iClassID);
stopPage.SetClassInfoCombo(&m_wndToolBar.m_ArmName,&m_wndToolBar.m_ClassName,&m_wndToolBar.m_Session);
CString stWizard;
stWizard.LoadString(pWinApp->m_hInstance,IDS_CLASSINFO_WIZARD,(WORD)LANGUAGE);
ClassInfo ClassInfoWizard(stWizard,this);
firstPage.SetPointer(reinterpret_cast<ULONG_PTR>(&ClassInfoWizard));
className.SetPointer(reinterpret_cast<ULONG_PTR>(&ClassInfoWizard));
classTerm.SetPointer(reinterpret_cast<ULONG_PTR>(&ClassInfoWizard));
classSubjects.SetPointer(reinterpret_cast<ULONG_PTR>(&ClassInfoWizard));
classStaff.SetPointer(reinterpret_cast<ULONG_PTR>(&ClassInfoWizard));
stopPage.SetPointer(reinterpret_cast<ULONG_PTR>(&ClassInfoWizard));
ClassInfoWizard.AddPage(&firstPage);
ClassInfoWizard.AddPage(&className);
ClassInfoWizard.AddPage(&classTerm);
ClassInfoWizard.AddPage(&classSubjects);
ClassInfoWizard.AddPage(&classStaff);
ClassInfoWizard.AddPage(&stopPage);
ClassInfoWizard.SetWizardMode();
if(ClassInfoWizard.DoModal() == ID_WIZFINISH)
{
m_eClassInfoView_State = ENABLE;
m_eClassInfoChange_State = ENABLE;
m_eStudentInfoAdd_State = ENABLE;
m_eGradeInfoAdd_State = ENABLE;
}
}
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 '[1456] SchPedestal.exe: Native' has exited with code -1073741819 (0xc0000005).
Note:
ClassInfo inherits from CPropertySheet, while the other objects inherit from CPropertyPage.
modified 11-Dec-14 6:33am.
|
|
|
|
|
Please edit your post and remove at least the repeated lines, or better all message lines except the first two exceptions. The other lines are not related to your problem.
|
|
|
|
|
How do I edit my post? I'd like to but do not know how to go about it.
|
|
|
|
|
Below each post are some links like Reply, Email, ....
If you are on your own post, there are two additional links: Edit and Delete.
|
|
|
|
|
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.
|
|
|
|
|
Your page variables (i.e., the ones used by AddPage() ) should be members of CMainFrame , not local to OnAddClassInfo() . What type of object is ClassInfo ?
Other than that, you need to step through the code using the debugger.
You might be better served by letting the MFC framework create a wizard-based app for you. You can customize it from there.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
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:
int ClassName::LoadSchoolName()
{
CComboBox *pSchoolName = (CComboBox *)GetDlgItem(IDC_COMBO1);
char szString[100];
TCHAR szString1[100];
INT_PTR iSchInfoID;
try
{
char szDatabaseFile[100];
GetDatabaseA(szDatabaseFile,sizeof(szDatabaseFile));
CppA::CppSQLite3DB db;
db.open(szDatabaseFile);
StringCbCopyA(szString,sizeof(szString),"SELECT SchInfoID,SchName,SchCity,SchState,SchCountry FROM SchInfo");
CppA::CppSQLite3Query q = db.execQuery(szString);
if(q.fieldIsNull(0))
{
return 0;
}
size_t size;
const char *p;
while (!q.eof())
{
TCHAR szMySchName[50],szMySchCity[20],szMySchState[20],szMySchCountry[20];
long long iSchoolInfoID;
for (int fld = 0; fld < q.numFields(); fld++)
{
switch(fld)
{
case 0:
{
iSchoolInfoID = q.getInt64Field(0);
}
break;
case 1:
{
p = q.getStringField(1);
DecryptString(const_cast<char *>(p),szString);
mbstowcs_s(&size,szString1,sizeof szString1,szString,lstrlenA(szString));
StringCbCopy(szMySchName,sizeof(szMySchName),szString1);
}
break;
case 2:
{
p = q.getStringField(2);
DecryptString(const_cast<char *>(p),szString);
mbstowcs_s(&size,szString1,sizeof(szString1),szString,lstrlenA(szString));
StringCbCopy(szMySchCity,sizeof(szMySchCity),szString1);
}
break;
case 3:
{
p = q.getStringField(3);
DecryptString(const_cast<char *>(p),szString);
mbstowcs_s(&size,szString1,sizeof(szString1),szString,lstrlenA(szString));
StringCbCopy(szMySchState,sizeof(szMySchState),szString1);
}
break;
case 4:
{
p = q.getStringField(4);
DecryptString(const_cast<char *>(p),szString);
mbstowcs_s(&size,szString1,sizeof(szString1),szString,lstrlenA(szString));
StringCbCopy(szMySchCountry,sizeof(szMySchCountry),szString1);
}
break;
}
}
TCHAR szSchoolName[100];
StringCbPrintf(szSchoolName,sizeof szSchoolName,_T("%s,%s,%s,%s"),szMySchName,szMySchCity,szMySchState,szMySchCountry);
int i = pSchoolName->AddString(szSchoolName);
pSchoolName->SetItemData(i,(DWORD_PTR)iSchoolInfoID);
q.nextRow();
}
pSchoolName->SetCurSel(0);
return 1;
}
catch(CppA::CppSQLite3Exception & e)
{
char szString[100];
StringCbPrintfA(szString,sizeof(szString),"Error Code: %d\n Error Mesage: %s",e.errorCode(),e.errorMessage());
MessageBoxA(NULL,szString,"Load shc name Error",MB_OK);
return 0;
}
catch(double dError)
{
return 0;
}
return 0;
}
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:
BOOL ClassName::OnInitDialog()
{
CPropertyPage::OnInitDialog();
ClassInfo * pPropertySheet = (ClassInfo *)m_Pointer;
LoadSchoolName();
CComboBox *pCombo2 = (CComboBox *)GetDlgItem(IDC_COMBO2);
int i = 0;
while(*szClassType[i])
{
pCombo2->AddString(szClassType[i]);
i++;
}
pCombo2->SetCurSel(0);
return TRUE; }
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
CArray<ULONG_PTR> 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
<ULONG_PTR>.Add( ).
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.
Can some one here, help?
|
|
|
|
|
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[99] = 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.
|
|
|
|
|
You seem to be mixing char and TCHAR somewhat indiscriminately, and you should not be using TCHAR as the destination of mbstowcs_s . This may well be where you are going wrong.
|
|
|
|
|
I found out the problem. I passed the size of the wide-char buffer in bytes to mbstowcs_s rather than the size in WORDS.
Immediately I corrected this, everything started working fine.
Thanks a lot.
|
|
|
|
|
Hi,
I read that i can set a variable in flash memory like this (PIC32):
uint8 Gain_factor_Den_17[128] __attribute__((space(prog), section(".table_flash_control")));
But what happens when i change that variable, flash has some requirements (e.g. need to erase page before writing etc). Who will handle that?
|
|
|
|
|
The variable is read only for your program. It is up to you to handle writing to it.
See the Microchip article Data EEPROM Emulation for PIC18, PIC24, dsPIC, PIC32[^]. There is also a library that emulates an EEPROM using the program flash memory.
But you should take care of the limited write endurance of your PIC device. If you need to change the variable frequently, you should use an external EEPROM.
|
|
|
|
|
Thanks for the response, but i am still a little confused.
Just theoretically, what happens if i were to write:
uint8 Table[128] __attribute__((space(prog), section(".table_flash_control"))); ...
Table[0] = 13;
Unfortunately i cannot try it, just trying to understand the logic. I am aware that the flash memory has only some certain write lifespan.
|
|
|
|
|
The flash memory of the PIC controllers is the program memory where code is stored. You can initialize the variable at compile time and it will be written together with the program code.
To write to the program memory by the running program you need to execute special instructions. For the PIC 32 see section 5. Flash Programming[^ PDF] of the PIC32 Family Reference Manual.
A compiler or assembler may provide functions or macros to perform the writing or compilers may have built-in support for writing. So the answer if the value is written depends on the used compiler. But if the compiler does not support writing to flash memory, you will get an error at compile time.
|
|
|
|
|
Thanks, that clears it up!
|
|
|
|
|
I noticed in the microsoft windows library they had two versions of what i assumed with similar files.
filename.h/filename.cpp and filenameEx.h/filenameEx.cpp
Anyone know how this "Ex" suffix is used? and what the relationship if any between the non-Ex and the "Ex" version?
Kind regards,
David
|
|
|
|
|
it really depends on the company/implementation - I doubt there's any 'standard' meaning, eg 'Example', 'Extension' - the only way to know for sure is a side-by-side comparison using [insert name of your favourite diff/compare tool here]
|
|
|
|
|
david21742 wrote: Anyone know how this "Ex" suffix is used? and what the relationship if any between the non-Ex and the "Ex" version? I always interpreted it as an "extended" version.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Basically it stands for an extended version.
Microsoft follows 2 conventions for extensions or newer versions of files / APIs / classes.
MFC has a CDialog class which is now extended to CDialogEx .
CDialogEx exists in a file called AfxDialogEx.h
There are several extended versions of APIs that follow this convention -
CreateWindow - CreateWindowEx
RegOpenKey - RegOpenKeyEx
The other convention that is followed is to add the numbers 2, 3, 4 ... to the end of the name.
Files that follow this convention are -
AfxPriv.h , AfxPriv2.h
AfxCmn.inl , AfxCmn2.inl , AfxCmn3.inl
This convention is followed by the COM interfaces -
IClassFactory , IClassFactory2
IPersistFolder , IPersistFolder2 , IPersistFolder3
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|