|
I have a client application that works fine provided that the user hits the connect/disconnect button. If the connection gets severed, my application will detect this and notify the user and allow them to reconnect by hitting the connect/disconnect button.
I have a requirement to have my application reconnect automatically, which will be used on an un-manned test later on.
I have one class that inherits from CAsyncSocket and a class for the dialog that contains the GUI/data that needs to be sent to the server. I have been trying to use this code:
int error = pSocket->Send( (char*)&CServerMsg, sizeof( CServerMsg));
if(error == SOCKET_ERROR )
{
m_pMainApp = ::AfxGetApp();
CMainDlg* dlg;
dlg = (CMainDlg *) m_pMainApp->GetMainWnd();
dlg->m_ConnectButton.SetCheck(TRUE);
dlg->OnConnectButton();
}
but I keep getting an error that causes my app to die. I stepped through and it dies on the socket Create() method in my OnConnectButton, which is the same method I call when the user hits the connect button. It then throws me to the method
void* CMapPtrToPtr::GetValueAt(void* key) const
When I do a GetLastError(), I get the error code 10038 which says I am performing a socket operation on a non-socket.
The strange thing is that the send works perfectly fine if the server doesn't go down and I am connected to the server the entire time.
Please help, this has been driving me crazy for 3 days! Thanks!
|
|
|
|
|
I think the error would come depending on how you are calling the Send method. Do you use a thread, or a timer etc?
My suggestion would be to call the function using PostMessage(...). Like:
PostMessage(WM_COMMAND,MAKEWPARAM(IDC_BUTTON1,0),0);
(If it is sent from the dialog's thread.)
Where the code for Send is written in the Button1's press event.
this is this.
|
|
|
|
|
Two suggestions:
- create a socket only once and call Close();Connect() in your OnConnectButton() method. I am using my own network class, but I think to remember that am instance of CAsyncSocket needs to be closed before it can be reopened again.
- consider making your reconnect logic timer driven, e.g. allow only delayed reconnects and set a top limit for number of reconnects per hour. Best is to work out a reconnect policy, something like reconnect only if the server was at least identified once in current session, etc. This will prevent harming the network with reconnects going berzerk.
Hope it helps.
|
|
|
|
|
I have added a picture control in my dialog. While moving mouse over the picture I want to change the control style to "ModalFrame". In Classwizard I could see only WM_CLICK message for this control. So I want ot know, How to enable mouse move message handling function for the picture control?
Vel
|
|
|
|
|
To receive notifications static controls must have the style...
SS_NOTIFY
Change the ID of the static control from IDC_STATIC to something else.
Nibu thomas
Software Developer
|
|
|
|
|
Hi
Is Gdiplus image will take any image as color image. Please help me.
thanks in advance
|
|
|
|
|
Hello all,
I have a LogIn Form which should close and destroy itself upon verification of password and username.
How can I link the text inputed to be verified from an Access file?.
Also,I want the logIn form to be closed and load a diferent Form (Not CDialog form). Any help is highly appreciated. Tks
---------------------------------------------------------
new to Visual C++, bt we gonna make it catch-a-fi-er
|
|
|
|
|
My friend was going through an interview the other day, and he came up with a interview question: find at lease 8 problems out of the following code snippet.
#define max (1*1024*1024)
int main()
{
char *f;
char tmp[max];
int i,j;
f = "In the second season, the show's writers introduce numerous new storylines for";
for(i=0;i<=max;i++)
{
if(f[i]='\n')
{
tmp[j++]=f[i];
tmp[j]=0;
printf(tmp);
j=0;
}
else
{
tmp[j++]=f[i];
}
}
return 0;
}
when I trying to debug, I was confronted with "stack overflow" initially, I wonder what's wrong with 'f'
all the comments are my answers, but it doesn't anywhere near to 8 problems, so what do you think where the other problems lie and why.
-- modified at 9:16 Tuesday 14th March, 2006
|
|
|
|
|
1. Should be char *f = "In the second season, the show\'s writers introduce numerous new storylines for"; . Initialize f immediately.
2. Note the escaped single quote in the string constant.
3. The for statement is commented out. The statements inside the braces are executed once.
4. for(i=0;i<=max;i++) will overflow the bounds of the tmp string.
5. for(i=0;i<=max;i++) may overflow the bounds of the f string. Would be better to use
i = 0;
while (f[i]) {
6. if(f='\n') : assignment within an if condition.
7. tmp[j++] : j is never initialized.
Software Zen: delete this;
|
|
|
|
|
Gary R. Wheeler wrote: The for statement is commented out. The statements inside the braces are executed once.
really ?
~RaGE();
|
|
|
|
|
He's updated the post. The original one had the for statement commented out.
Software Zen: delete this;
|
|
|
|
|
LiYS wrote: f = "In the second season, the show's writers introduce numerous new storylines for";
better use a strcpy in this case, such an assignment cannot work.
~RaGE();
|
|
|
|
|
Actually, it does. f is defined as char *f , so assigning a constant string is perfectly valid. strcpy(f,...) would work only if you had allocated memory to f previously in the code.
Software Zen: delete this;
|
|
|
|
|
8. The line tmp[j++]=f[i]; is in both branches of the if , so you might as well move it above the if .
Software Zen: delete this;
|
|
|
|
|
Gary R. Wheeler wrote: The line tmp[j++]=f[i];
sorry, I don't see any problem with that. or if you could be more specific.
|
|
|
|
|
It's not so much an error, as it's redundant. Since the same line appears in both branches of the if statement, it doesn't depend upon the condition. You should move the statement above the if in this case.
Software Zen: delete this;
|
|
|
|
|
In addition to what has already been mentioned:
max is not declared.
Missing <stdio.h> .
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: max is not declared.
Sorry!I forgot to add the original
#define max (1*1024*1024)
DavidCrow wrote: Missing <stdio.h>
It counts, Thanks!
-- modified at 9:15 Tuesday 14th March, 2006
|
|
|
|
|
LiYS wrote: char tmp[max];
worst thing to do , i.e. allocating 1mb of memory on the stack. That is why it overflowed.
-Prakash
|
|
|
|
|
BOOL CPerformanceGraph::ReadFromFile()
{
CFile fp;
CPtrList tempList;
CString szFileName= "c:\\PerfGraph.txt";
if(!fp.Open(szFileName,CFile::modeRead))
{
MessageBox( "Unable to open file for Performance Graph Configuration");
return FALSE;
}
pGraphList.RemoveAll();
CPerfGraph *oPerfGraph = new CPerfGraph();
while(fp.Read( oPerfGraph, sizeof( class CPerfGraph )))
{
//for checking
int n;
n=oPerfGraph->No_of_Points;
char temp[10];
strcpy(temp,oPerfGraph->Id);
strcpy(temp,oPerfGraph->TagX);
//end of checking
tempList.AddTail(oPerfGraph);
}
POSITION Pos = tempList.GetHeadPosition();
while(Pos)
{
CPerfGraph *oTemp=(CPerfGraph *)tempList.GetAt(Pos); //for checking
CString mTagX = oTemp->TagX;
CString mTagY = oTemp->TagY;
//end of checking
tempList.GetNext(Pos);
}
fp.Close();
return TRUE;
}
This is my coding...Im reading datas from File and put it into CPtrList.But It doesn't get adding properly.
I have two set of values as graph1 and graph 2.
But it adds only the last Graph2 value.
How can i get the Graph 1 value.
I think im using the correct way to add the file data in to List.
Kindly give me solution...
|
|
|
|
|
BOOL CPerformanceGraph::ReadFromFile()
{
CFile fp;
CPtrList tempList;
CString szFileName= "c:\\PerfGraph.txt";
if(!fp.Open(szFileName,CFile::modeRead))
{
MessageBox( "Unable to open file for Performance Graph Configuration");
return FALSE;
}
pGraphList.RemoveAll();
CPerfGraph *oPerfGraph = new CPerfGraph();
while(fp.Read( oPerfGraph, sizeof( class CPerfGraph )))
{
int n;
n=oPerfGraph->No_of_Points;
char temp[10];
strcpy(temp,oPerfGraph->Id);
strcpy(temp,oPerfGraph->TagX);
tempList.AddTail(oPerfGraph);
oPerfGraph = new CPerfGraph();
}
if (oPerfGraph != NULL) delete OPerfGraph;
POSITION Pos = tempList.GetHeadPosition();
while(Pos)
{
CPerfGraph *oTemp=(CPerfGraph *)tempList.GetNext(Pos);
CString mTagX = oTemp->TagX;
CString mTagY = oTemp->TagY;
}
fp.Close();
return TRUE;
} Check out the two bold lines of code. After you add an entry to the list, you need to allocate a new one for the next entry. The second line, outside the read loop, deletes the last entry. The loop terminates on a failed read, which means the last allocated entry isn't needed. Minor style note when using the CPtrList class: the GetNext function retrieve the entry in the list at the position value, and advances the position value, in one step.
Software Zen: delete this;
|
|
|
|
|
Anu_Bala wrote: CPerfGraph *oPerfGraph = new CPerfGraph();
This will need to be inside of the while loop.
Anu_Bala wrote: strcpy(temp,oPerfGraph->Id);
strcpy(temp,oPerfGraph->TagX);
The second call to strcpy() will overwrite the first. Perhaps you meant to use strcat() instead.
Anu_Bala wrote: fp.Close();
It's a good idea to close the file as soon as you are done with it.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hi All,
I need to implement Drag and drop of files between my namespace extension and windows desktop folders. When the user drags a file from a desktop folder and drops it on a folder in my namespace, I need to show the user a dialog box for user I/P. On the drop event when I do DoModal(), the dialog box just appears momentarily and disappears.
Can anyone please indicate where the problem could be?
Thanks and Regards,
Anil
-- modified at 7:10 Tuesday 14th March, 2006
|
|
|
|
|
A drag-drop operation is run by a modal message loop (possibly cross-process) inside OLE32. I imagine that trying to start another modal UI loop is causing the problem.
In your OnDrop() handler, collect whatever data is necessary and store it somewhere. Post yourself a window message and do your UI in the message handler.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hi Michael,
I tried this approach.... but its crashing there too.
Any other suggestions?
Thanks and Regards,
Anil
|
|
|
|