|
Do NOT call a (pure) virtual function in a constructor or destructor. This can result in undefined behavior.
Think about it, or grab a copy of 'Stroustrup'.
--------------------------------------------------
If my messages appear curt, I apologize.
I try to be brief to save your time as well as mine.
--------------------------------------------------
|
|
|
|
|
Thanks,
Now that I think about it... Base ctor called first, pure virtual function call would open the possibility for using unconstructed subclass data...
mmm
makes me worried that Borland C++ DID compile it! Thanks again to all of you
nick
|
|
|
|
|
I found this in the MSDN online help :
Another restriction is that if the constructor for an abstract class calls a pure virtual function, either directly or indirectly, the result is undefined. http://msdn.microsoft.com/library/devprods/vs6/visualc/vclang/_pluslang_restrictions_on_using_abstract_classes.htm
Borland compiled without errors, but didn't run correctly. I added printf function calls to the constructors and destructors of both classes. When I ran the program, the printf functions didn't output anything. When I removed the call for "Load()" in the base class, all worked as it should. I guess you could say that MSVC++ works better since it doesn't allow to shoot yourself in the foot.
|
|
|
|
|
In my program I need to use some mathematical (unicode) symbols like sigma, square root, integral, and so on. For some reason only some of the unicode works while others not. For example, I have an array Names and a CCombobox m_combo, and a loop to add the strings in the array to the combo box.
static const CString Names[] ="a","=",0x221A,0x222B,0x2211,0x2212, 0x223B};
for(int i=0; i<7; i++)
m_combo.AddString(Names[i]);
The combo box correctly displayed "a", "=", square root (0x221A), integral (0x222b),sigma (0x2211), minus sign (0x2212), but it shows only a square box for 0x223b instead of showing the symbol. This only happens to many other unicode characters.
Why some symbols can be correctly displayed while others not? Also how can VC++ convert a wchar_t into a CString automatically?
bob
|
|
|
|
|
Ok, I'd be very grateful if you can help me out here...
In my main dialog window, I fire up a new one. I that new dialog I want to have a CListBox (with values in it of course). I have no problem using the CListBox.AddString(...) in my main dialog.
Whenever I try to add a line in the new dialog the program crashes... Why? How can I do this the right way? I suspect the answer is very simple, I just can't figure it out...
The error message is: Debug Assertion Failed.
Cheers,
Erik
|
|
|
|
|
Are you using the CListCtrl? If so remember that you must first have the columns present if you use a CHeaderCtrl. Once you have that you can use the following code
int iRowRet = m_LISTCONTRL.InsertItem(m_LISTCONTRL.GetItemCount(),strText);
m_LISTCONTROL.SetItemText(iRowRet,1,strText);
UpdateWindow();
|
|
|
|
|
No, im just using a CListBox, and AddString(...) to fill it with values.
This works just fine in my main dialog window. It chrashes (when using AddString(...) or any other CListBox member function) in a modal dialog initiated from my main window.
Hope you can help me now,
Erik
|
|
|
|
|
Where are you adding the strings to the dialog? in the OnInitDialog? elsewhere?
-Ben
"Its funny when you stop doing things not because they’re wrong, but because you might get caught." - Unknown
|
|
|
|
|
I've tried adding the strings from everywhere...
Constructor, OnInitDialog, though buttons... AddString to that CListBox crashes the program.
I suspect I have to initialize the dialog in some way?
Erik
|
|
|
|
|
Can you post some code or even the code that asserted would help,
Michael
|
|
|
|
|
ASSERT(::IsWindow(m_hWnd))
That's where it fails. Apparently my m_hWnd is NULL. How to fix this?
|
|
|
|
|
Trace into the MFC source and check where the assertion occurs. Any hints in the source code comments? Also check if the dialog's m_hWnd is NULL before you call AddString().
Are you trying to do something like this?
CMyDlg dlg;
dlg.m_wndList.AddString("asdf");
dlg.DoModal();
This will fail, because the dialog's window handle (and the list) hasn't actually been created yet.
--------------
"Fabricati Diem, Pvnk"
|
|
|
|
|
the assertion --> ASSERT(::IsWindow(m_hWnd))
So I guess my m_hWnd is NULL. How can I fix this?
Erik,
|
|
|
|
|
CMyDlg dlg;
dlg.DoModal();
And then, inside the dialog:
m_CListBoxVariable.AddString("Testing, testing..."); // Assertion error here!
|
|
|
|
|
This should work. And m_CListBoxVariable was added with ClassWizard? Maybe the DDX macros in DoDataExchange() have been corrupted somehow. Try removing the member and add it again.
--------------
"Fabricati Diem, Pvnk"
|
|
|
|
|
I tried removing, and adding it again. No luck.
I think the problem is somehow related to the fact that hWnd is NULL in my new dialog object. I have no clue however how to initialize hWnd.
Please, can't someone just try to make a dialog based app, and then fire up a new dialog from the main frame. And if you can assign values to variables in this new CDialog, please tell me how you did....
|
|
|
|
|
I created a small test project and it works OK. This is what I did:
1. Create a standard Dialog-based MFC app
2. Add a new dialog resource to the project (IDD_DIALOG1)
3. Put a listbox on the new dialog
4. Open ClassWizard and coose to create a new CDialog class for new dialog resource (CDialog1).
5. With ClassWizard, add a CListBox member for the list (m_wndList)
6. Add a button to the main dialog and add an OnClick handler like this:
#include "Dialog1.h"
...
void CMainDlg::OnButton1()
{
CDialog1 dlg;
dlg.DoModal();
}
7. Add a WM_INITDIALOG handler in CDialog1:
BOOL CDialog1::OnInitDialog()
{
CDialog::OnInitDialog();
m_wndList.AddString("String to add");
return TRUE;
}
Try this, and if you still get an assertion at CListBox::AddString(), something is very, very strange.
--------------
"Fabricati Diem, Pvnk"
|
|
|
|
|
Which function inside the dialog is the m_CListBoxVariable.AddString("Testing, testing..."); called. Is it in InitDialog?
Michael
|
|
|
|
|
Hello,
I'm trying to use the printer port to do some simple I/O operations in windows 2000. However, as I quickly learned direct IO is a no-no with the NT kernel. I've tried to find out how I can accomplish just reading/writing single bytes to the port but all I've managed to find is shareware device drivers that accomplish this. For my purpose a driver is overkill. I've read that I could use CreateFile() to read and write to the port, but how would I specifically read the Control and Status parts of the printer port? Reading those two ports is essential. I really appreciate any help/suggestions. Thanks a lot!
Joseph LeBlanc
unixd0od@hotmail.com
|
|
|
|
|
ok,
i'm making a chat program where the user inputs
text in a multiline edit box and it is added to a buffer
declared as a character array which is then sent
to another edit box set as read-only for display.
i need to separate messages of different users
by a line or two.
The problem is that '\n' comes out as a square.
i have tried to use ToAscii(VK_RETURN...) but the
some weird character came up. i have also tried to
send an extra VK_RETURN to the user input edit box before i
GetDlgItemText(), but for some reason it comes up
after the text is read and cleared, so the edit box
ends up blank with the cursor on the second line.
is this possible, or should i try to make my buffer
another type?
thx
-SiKLyChILd
|
|
|
|
|
Use a ListBox Using AddString() function and Ready..
Cheers...
Carlos Antollini
|
|
|
|
|
|
thanx a lot man, ive been racking by brain for days.
btw, what does the r in '\r' stand for?
just curious...
thx
SiKLyChILd
|
|
|
|
|
carrige (r)eturn
-Ben
"Its funny when you stop doing things not because they’re wrong, but because you might get caught." - Unknown
|
|
|
|
|
Anybody know where I can find a good example of creating docking windows in strait C? Cristi Posea has excellant source for MFC (http://www.codeproject.com/docking/sizecbar.asp), but I'd like to know what's going on underneath, and MFC source is kind of a pain to step through.
Thanks in advance,
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|