|
Do you want to know about try/catch?
|
|
|
|
|
Thanks Hamid,
I want to know how to understand the following comments from Bjarne about exception specification.
--------------------
(section 14.6.1 Checking Exception Specifications)
The way to think about exception-specifications is to assume that a function will throw any exception it can. The rules for compile-time checking exception-specifications outlaw easily detected absurdities.
--------------------
regards,
George
|
|
|
|
|
I think he wants to tell that you can control exceptions when your program is running.
|
|
|
|
|
Thanks Hamid,
What do you mean "control exceptions"?
regards,
George
|
|
|
|
|
for example you have an runtime error like file not found so if you didnt have any code for it,your program will be producting an error and finish your progra,.
|
|
|
|
|
Hi Hamid,
Does your reply relates to my original question?
regards,
George
|
|
|
|
|
|
Hi Hamid,
I am wondering how do you understand the statements, why "The way to think about exception-specifications is to assume that a function will throw any exception it can"?
--------------------
(section 14.6.1 Checking Exception Specifications)
The way to think about exception-specifications is to assume that a function will throw any exception it can. The rules for compile-time checking exception-specifications outlaw easily detected absurdities.
--------------------
regards,
George
|
|
|
|
|
Hello everyone,
I usually check whether there is bad_alloc thrown to identify whether the allocation is success or not.
My question is,
Is there a way to disable bad_alloc and just to check the returned pointer NULL or not to identify allocation success or not -- which from function point of view, is as correct as the way to catch bad_alloc? Windows platform/Visual Studio is ok. I always see code does not check bad_alloc and just check the return pointer.
(My solution is to select Enable C++ Exception to No in Code Generation option in Visual Studio, not sure whether it is the most correct way.)
thanks in advance,
George
|
|
|
|
|
Did you try like this
int * m_pInt;
m_pInt = new (nothrow) int [10];
|
|
|
|
|
|
I have a float number in a varable (Ex: float m_fNumber;) that is assigned a number(ie, m_fNumber = 12.32;). How can I use SetDlgItem????(ID_FNUM,???); into the editbox?
the following error is received by using CString: ie, : str.Format("%f",m_fNumber);
error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *'
I thought I could format the CString and then use SetDlgItemTextW(...,....) to put it in the editbox.
Does anyone know a solution? HELP
A C++ programming language novice, but striving to learn
|
|
|
|
|
You are doing a unicode build so the Format() function is expecting a wide string as it's formating parameter. Use the _T() macro to change the string to a wide string when building a unicode app.
str.Format(_T("%f"), m_fNumber);
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Yes I did use _T("%f"),f_number); and got that error. I solved it this way:
#if !define ID_FLOAT
#define ID_FLOAT "%F"
#endif
str.Format(_T(ID_FLOAT),f_number);
A C++ programming language novice, but striving to learn
|
|
|
|
|
|
I need to open / read a URL that has PostData. The PostData is long (ASP.Net, so includes the __VIEWSTATE). I just dont know how to send a post back to the server. I am sure its simple, but I have searched and cant find anthing.
An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
www.mpic3.com - My PIC based MP3 player project
|
|
|
|
|
The following refers to an application I am writing in VC++ 6.
I want to add some items to a list box in a dialog. I understand that this involves something called DDX, which, as far as I am aware is something that the IDE sorts out for me.
I have added a public variable to the dialog class via the Class Wizard to be associated with the List box - m_listGTTimeUnits.
Now, the application is a Windows Explorer style application and the dialog appears when I right-click over the right hand pane.
I have tried a couple of ways to add values to the list box, both of which allow the code to compile but cause the program to crash with the message "Debug assertion failed" when the dialog is called...
Firstly...
<br />
void CRightView::OnRightmenuEditnode() <br />
{<br />
...<br />
CEditNodeDlg dlg;<br />
dlg.m_listGTTimeUnits.AddString("days");<br />
...
and secondly
<br />
void CRightView::OnRightmenuEditnode() <br />
{<br />
... <br />
CListBox * pList = (CListBox*) dlg.GetDlgItem(IDC_LISTLTTIMEUNITS);<br />
pList->AddString("days");<br />
...<br />
If anyone has any idea of what it is that I am doing wrong, I would be very glad to hear!
Thanks,
Ben.
modified on Saturday, January 26, 2008 10:47:25 AM
|
|
|
|
|
Ben Aldhouse wrote: CEditNodeDlg dlg;
dlg.m_listGTTimeUnits.AddString("days");
Ben Aldhouse wrote: void CRightView::OnRightmenuEditnode()
{
...
CListBox * pList = (CListBox*) dlg.GetDlgItem(IDC_LISTLTTIMEUNITS);
pList->AddString("days");
...
In the above handlers, you created an instance of your dialog but you never created the dialog window.
Why do you need to update the list box from the view? Cannot you update it from the dialog itself?
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.
[my articles]
|
|
|
|
|
These are just snippets, I have the following lines later on
<br />
<br />
if (dlg.DoModal () == IDOK)<br />
{ <br />
myPNode->SetNodeDescr(dlg.m_strNodeDesc);<br />
<br />
<br />
if (dlg.m_strNodeDesc != oldDesc)<br />
pDoc->SetModifiedFlag();<br />
}<br />
I wouldn't mind adding the items to the list box in the dialog itself if I knew how to. I've tried adding them in the dialog class constructor but this doesn't work, either. I am beginning to think that I should overload the base classes 'OnInitDialog' function. I've just tried to creating this in the dialog...
<br />
<br />
bool CEditNodeDlg::OnInitDialog()<br />
{<br />
m_listGTTimeUnits.AddString("days");<br />
<br />
}<br />
<br />
but I am getting 'error C2555: 'CEditNodeDlg::OnInitDialog' : overriding virtual function differs from 'CDialog::OnInitDialog' only by return type or calling convention' and I'm not sure what to do about this.<br />
<br />
|
|
|
|
|
Ben Aldhouse wrote: I am beginning to think that I should overload the base classes 'OnInitDialog' function. I've just tried to creating this in the dialog...
This is the way to go.
Ben Aldhouse wrote: bool CEditNodeDlg::OnInitDialog()
Replace bool with BOOL .
BTW Why don't you make the Visual Studio make the work for you (select your dialog on class explorer, right click and choose Add Windows Message Handler item)?
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.
[my articles]
|
|
|
|
|
|
I've got it! Thanks for your help! Basically I needed to change 'bool' to 'BOOL'.
<br />
BOOL CEditNodeDlg::OnInitDialog()<br />
{<br />
CDialog::OnInitDialog();<br />
m_listGTTimeUnits.AddString("days");<br />
<br />
return TRUE;<br />
}<br />
|
|
|
|
|
Hi all, i found this example on MSDN. Im trying to find out how i can accomplish what im trying to do, and thats monitor the events of a application.
So here's the code...
<br />
#include <windows.h><br />
<br />
int main(){<br />
HOOKPROC hkprcSysMsg;<br />
static HINSTANCE hinstDLL;<br />
static HHOOK hhookSysMsg;<br />
<br />
hinstDLL = LoadLibrary((LPCTSTR) "c:\\windows\\notepad.dll");<br />
hkprcSysMsg = (HOOKPROC)GetProcAddress(hinstDLL, "SysMessageProc");<br />
hhookSysMsg = SetWindowsHookEx(WH_SYSMSGFILTER,hkprcSysMsg,hinstDLL,0);<br />
return 0;<br />
}<br />
</windows.h>
I've noticed that i dont have notepad.dll - It may not be new to some but it is to me seeing how i've never had to look for it. So what would i have to do to monitor notepads events? Also, what char would i dump the messages from to a fstream .txt file? Thanx in advance!
|
|
|
|
|
dellthinker wrote: I've noticed that i dont have notepad.dll
You have to build it (of course you don't need to call it notepad.dll): if you need a global hook (and you need a global one to hook another process like notepad) the you have to create a DLL hosting your hook procedure.
I strongly suggest you to read MSDN documentation about hooks [^].
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.
[my articles]
|
|
|
|
|
Hi CPallini,
I developing an application that hooks the Open/Save dialog for getting the selected file path. currently am able to hook the common dialog but it's not working on office Open/Save dialog. On Searching i found that Office is using separate Open/Save dialog. Can anyone help me to identify the Office Open/Save dialog messags equivalent that of common dialog's
CDN_INITDONE
CDN_FILEOK
CDM_GETFILEPATH
CDM_GETFOLDERIDLIST
CDM_GETFOLDERPATH
CDM_GETSPEC
CDM_HIDECONTROL
CDM_SETCONTROLTEXT
CDM_SETDEFEXT
.
I think you can help me to solve this out.
thanks
Nitheesh
|
|
|
|