|
I found a article on another site that talked about my problem.. here is a little blurb from the article...
If the terminating socket has been closed, calling Flush on the CArchive will raise an exception (so will calling Close). In the previous case, before the exception is handled, CArchive goes out of scope and its destructor calls Close. Close throws another exception and all hell breaks loose. Never throw exceptions from destructors.
You will need nested try / catch blocks ... [Article^]
My problem with the exceptions is fixed but I still have a memory leak.. Any ideas??
void CMainFrame::OnSend(CClientSocket *pSocket, CString strMsg)
{
if(*pSocket != INVALID_SOCKET)
{
try
{
sendObject(pSocket, strMsg);
}
catch (CException* pEx)
{
pEx->Delete();
}
}
}
BOOL CMainFrame::sendObject(CClientSocket *pSocket, CString strMsg)
{
BOOL bRet = TRUE;
CSocketFile sf(pSocket);
CArchive ar_send(&sf, CArchive::store);
try
{
ar_send << strMsg;
ar_send.Flush();
ar_send.Close();
sf.Close();
}
catch (CException* pEx)
{
bRet = FALSE;
pEx->Delete();
}
return bRet;
}
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
i'm tryin to do this program and i don't know how to go about doing it. i tried it one way but it didn't work.
The goal of the program is to encode input messages using the following encryption strategy:
The message sender iputs a four letter word , CCCC, and another for letter word XXXX. The message sender then inputs the message to be sent. The program scans the message one character at a time and each character is pushed in the stack until either the scanned character is in the word CCCC or the end of message is encountered. When the scanned characters in CCCC, print that charcater until the stack is empty or the chracter at the top is one of the chracters XXXX. Whne the end of the message is encountered, print the chracter at the top of the stack and continue to pop and print the stack top until the stack is empty.
for example:
word 1 = GOOD
word 2 = LUCK
message to be encoded = SOUNDS SIMPLE TO ME
encoded message = OSDNOT EEM LPMIS SU
this is what i have so far:
#include <cctype>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
class stack
{
private:
char stacks[50];
int top;
public:
void push(char);
char pop(char &);
bool empty();
bool full();
stack()
{
top=0;
}
};
bool stack::empty()
{
if (top==0)
return true;
else
return false;
}
bool stack::full()
{
if (top==50)
return true;
else
return false;
}
void stack::push(char x)
{
if (full())
exit(1);
else
top++;
stacks[top]=x;
}
char stack::pop(char &x)
{
if (empty())
exit(1);
else
x=stacks[top];
top--;
return (x);
}
int main()
{
stack s1;
char word1[5];
char word2[5];
char message[50];
int len;
char catchvar;
cout<<"Enter Encryption word 1 : ";
cin.getline(word1,5);
cout<<"Enter Encryption word 2 : ";
cin.getline(word2,5);
cout<<"Enter message to be encypted : ";
cin.getline(message,50);
len=strlen(message);
cout<< "Encypted message is : ";
for (int i=0; i<5; i++)
{
for(int j=0; j
|
|
|
|
|
whats with the © copyright notice?
is this your code?
"there is no spoon" biz stuff about me
|
|
|
|
|
|
I found in several examples the function _mbstowcsz, but I don't find anywhere it's explanation.
Does anyone know exactly why on a certain place this will be used instead of mbstowcs?
|
|
|
|
|
i would imagine (guessing here) that the z on the end indicates it would be used with a zero terminated string?
"there is no spoon" biz stuff about me
|
|
|
|
|
The mbstowcs function does convert a NULL of the source string and stops there.
It IS possible, that mbstowcsz appends a zero even if it has not found any in the source string.
My point is, that this function is not documented even in the online MSDN (it appears only in two examples), and people are following this blindly.
Do you use a function, because you BELIEVE that it will work a certain way? (It is a rhetorical question.)
|
|
|
|
|
_mbstowcsz is defined in AtlMisc.h in WTL, also in CStringT.h in MFC7.
In both cases the function calls ::MultiByteToWideChar() and then sets the last character in the string to a NULL.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Thanx.
_mbstowcsz is defined in AFX.H of VC6, but a definition is not a documentation (there is nothing about it in Visual Studio 6).
I am a bit upset by the lemmings, who are coding and copying code without having an idea of the implications.
|
|
|
|
|
Vancouver wrote:
_mbstowcsz is defined in AFX.H of VC6, but a definition is not a documentation (there is nothing about it in Visual Studio 6).
It is declared in AFX.h, and it is defined in StrCore.cpp.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks. Probably I made a search only in ".h".
|
|
|
|
|
Hi
Maybe wrong forum but here goes anyway...I was asked 5 questions in a telephone interview. Anybody give their thinking on the following two....
1) Why would passing a parameter into a copy constructor by value be a waste of time
2) When would you use private inheritance
if you're still reading...
3) 3 main differences between a class and a struct. (I said classes are private by default, structs are public. Structs are value based, classes are referenced base (read that somewhere), classes can use polymorphism, late binding etc). Anywhere near?
Thanks for your time.;P
Regards
Angel
===========================================================
The sooner you fall behind, the longer you have to catch up
|
|
|
|
|
Angel1058 wrote:
2) When would you use private inheritance
When you need the public and protected members of the base class to be private in the derived class. In the past 11 years, I've never had the need.
Angel1058 wrote:
3) 3 main differences between a class and a struct.
I only know of one main one. While others might exist, they are probably insignificant in comparison.
Angel1058 wrote:
...classes can use polymorphism
So can struct s:
struct Auto
{
public:
virtual void Engine(){}
};
struct Car : public Auto
{
public:
void Engine(){}
};
struct Truck : public Auto
{
public:
void Engine(){}
};
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
DavidCrow wrote:
2) When would you use private inheritance
When you need the public and protected members of the base class to be private in the derived class. In the past 11 years, I've never had the need.
I answered the same, but said all members to be private, which is effectively what you're saying. He wasn't happy - he wanted an example of when you would use private inheritance!
DavidCrow wrote:
3) 3 main differences between a class and a struct.
I only know of one main one. While others might exist, they are probably insignificant in comparison.
What is your main one?
DavidCrow wrote:
...classes can use polymorphism
So can structs:
Didn't know that!
Thanks for your time.
Regards
Angel.
===========================================================
The sooner you fall behind, the longer you have to catch up
|
|
|
|
|
Angel1058 wrote:
What is your main one?
The same one you noted.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi,
I have an application where the mainframe consists of a list control in the view. I update and display values here. On Exiting the application I need to do some stuff here.
I tried writing a function that handles the WM_CLOSE message... the function gets called for the mainframe, but not for the view. Looking into the MainFrame, I don't see an instance of the view being created and consequently can't invoke the function directly. what should i do?
HelpWanted!
|
|
|
|
|
help_wanted wrote:
On Exiting the application I need to do some stuff here.
Have you considered the app's ExitInstance() method?
help_wanted wrote:
Looking into the MainFrame, I don't see an instance of the view being created...
Probably because it is not created in the frame. The document, frame and view are all created in the app's InitInstance() method.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
DavidCrow wrote:
Have you considered the app's ExitInstance() method?
Is this called without destroying the view etc?
DavidCrow wrote:
Probably because it is not created in the frame. The document, frame and view are all created in the app's InitInstance() method.
Yeah it is. Thanks!
|
|
|
|
|
help_wanted wrote:
Is this called without destroying the view etc?
See here.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Situation is quite ordinary: I have a main window class(for example derived from CDialog) and call a modal dialog from it's method. Choosing some settings from within it affects data of the main window class. So what is the most elegant way to establish communication between these two dialogs? How is it implemented more often in practice? One solution I see is to pass a pointer of the main class as an argument to constructor or any other method of this "settings" dialog and manipulate all tha data directly. Or I can save all changes in some kind of mediums such as global variables or object with static members and then when this secondary dialog is about to be destroyed it sends message to the main window class in order to read data from these transitional variables and update it's data. Or perhaps there is another way to do it?
|
|
|
|
|
Something like:
CMainDlg::OnButtonClick()
{
CChildDlg dlg(&some_data_here);
if (dlg.DoModal() == IDOK)
...
} If you don't want to do it via the constructor, try:
CMainDlg::OnButtonClick()
{
CChildDlg dlg;
dlg.m_some_data = m_some_data;
if (dlg.DoModal() == IDOK)
m_some_data = dlg.m_some_data;
}
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
ok, but, if we do the second method, you consider that DoModal() returns IDOK before destroying the CChildDlg . Don't DoModal() return it value when the dialog's closed ?
what about passing to the CChildDlg directly a pointer to the "parent dialog" instead of a pointer to a some data ?
thx for your answer
TOXCCT >>> GEII power
|
|
|
|
|
toxcct wrote:
DoModal() returns IDOK before destroying the CChildDlg . Don't DoModal() return it value when the dialog's closed ?
The CChildDlg object exists after the dialog it was associated with has been destroyed. This is why you can access CChildDlg member variables after the dialog has been dismissed.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Imho, the most elegant way would be to package your data in an object that exists in your main window, and pass that object to the modal dialog.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|