|
Consider Shutdown(). Another solution is to set the LINGER structure to 0 and use setsockopt() to instruct the socket to close immediately.
Kuphryn
|
|
|
|
|
Thanks for the reply.. I have been trying to use the SO_LINGER but it doesn't seem to be working.. here's what I'm trying..
First create.. then
linger m_linger;
m_linger.l_onoff = 1; // Turn linger on
m_linger.l_linger = 0; // Set time to ZERO
s.SetSockOpt(SO_LINGER, &m_linger, sizeof(m_linger),SOL_SOCKET);
This isn't working, am I doing this wrong?
Thanks,
Rob
|
|
|
|
|
No. Your solution looks okay. What happens when you set the time to greater than 0?
Kuphryn
|
|
|
|
|
I think I found the problem.. I was using API then I switched to using CAsyncSocket then to CSocket.. Just found out that SO_LINGER doesnt work with CSocket so I'm going to go back to either CAsync or straight API (if thats what you call it)..
Any way .. Thanks,
Rob
|
|
|
|
|
Hi everyone,
I have a thread. The function that keeps this thread alive contains a while loop. The while loop is true while a boolean variable is maintained true. When the thread has to terminate, the boolean value is modified to false and the thread dies. This boolean variable is global. I am using a Mutex to control access to this global value.
I would like to know if it is necessary to control global variables with a Mutex when one is just reading the value? Or does one only control the global variable when one is going to modify its value?
This one depends on the previous question. How does one manage something like:
while ( g_bGlobal_Variable )
{
}
How does one apply a mutex object to the above case. Because I cannot do
dwWait = ::WaitForSingleObject();
if ( dwWait == 0 )
{
while ( g_bGlobal_Variable )
{
}
}
Otherwise this implies that the thread always has control over the Mutex object while alive.
Thanks and excuse the ignorance
Regards
|
|
|
|
|
First, if you're going to use a synhcronization object to
protect a flag, use the synchronization object as the flag.
i.e. Use an Event whose state is checked as a condition to exit
the thread. (better yet use two events.. one to signal work to
be done, the other to exit. wait (WaitForMultipleObjects) on both
and then react appropriately.. that way your work thread won't
waste cycles running through loops pointlessly.)
Second, yes. Even access to resources should be protected (generally)
since you want to ensure that the resource is not being modified while
you are reading it. (or whatever)
That said, some types of resources (small register-sized variables
generally) can be read/written without the need of a protecting
synchronization object. Check out the Interlocked_______ functions
in win32.
|
|
|
|
|
Thanks Scott
I am sorry for the anonymous that was an error.
Rui
|
|
|
|
|
Here's a code sample:
HANDLE hWorkToBeDone=CreateEvent(0,FALSE,FALSE,0);
HANDLE hTimeToQuit=CreateEvent(0,TRUE,FALSE,0);
HANDLE Waitables[]={hTimeToQuit,hWorkToBeDone};
for (DWORD W=~WAIT_OBJECT_0;W!=WAIT_OBJECT_0;)
{
switch (W=WaitForMultipleObjects(2,Waitables,FALSE,INFINITE))
{
case WAIT_FAILED:
break;
case WAIT_OBJECT_0:
break;
case WAIT_OBJECT_0+1:
;
break;
case WAIT_TIMEOUT:
default:
ASSERT(FALSE);
}
}
|
|
|
|
|
|
I have an animation control on a dialog box that displays an AVI file while some processing is taking place. I create the animation control and play it from my WM_INITDIALOG handler. However, sometimes I notice that the animation takes a second or two to start playing. Any suggestions on what I can do to make sure this animation comes up all the time?
Brigg Thorp
Software Engineer
Timex Corporation
|
|
|
|
|
Hmm, never used that control before.
Can you create the hosting dialog as a hidden
modeless dialog (some time before ever
needed) and just pop it up, disabling
the main window, when needed? (Call animation
control's Seek method when creating dialog,
and Play in you OnShowWindow handler)
That way, hopefully the animation is ready to
play when you need it.
|
|
|
|
|
Hello all,
This is a basic question in MFC, but for some odd reason I can't figure out how to do it. I want to be able to specify the size of the main window when it comes up, and would like to be able to save this information (via .ini file I suppose). I thought that by modifying the CreateStruct in the OnCreate or the OnPreCreate would handle this setting the initiail size of the main window, but it does not work. Any suggestions on how to do this, and could anyone point me in the right direction to "save" this window information so when it comes up again I can use the last position/size information.
Thank you in advance.
Dan
|
|
|
|
|
There are some articles on how to do this somewhere on this very site...
When I am king, you will be first against the wall.
|
|
|
|
|
|
add this in CMainFrame::OnCreate() :
SetWindowPos(NULL, 0,0, 600,350,SWP_NOZORDER|SWP_NOMOVE);
|
|
|
|
|
In addition to S.Rod.'s answer you can also use
MoveWindow(200,100,450,300,TRUE);
This will change the size and move it around the screen
Also,
GetClientRect(&rcClient); // get size of client area
m_cyClient = rcClient.bottom-rcClient.top; // only the 'y' length
Will get the size of the window.
To get the left and right sides you can rcClient.Right-rcClien.Right
Jeff Patterson
Programmers speak in Code.
www.anti-dmca.org
|
|
|
|
|
Hello all
I have a VC7 dialog based application.
Basically one dialog with
an edit box
IDC_EDIT
and 2 buttons
IDC_READ_MYFILE
IDC_CANCEL
when I press the IDC_READ_MYFILE button i want to open a standard File Open Dialog, managed by the message_map entry, something like this:
ON_BN_CLICKED(IDC_READ_MYFILE, OnReadMyfile)
...
void CMyAppDlg::OnReadMyfile()
{
// TODO: Add your control notification handler code here
static CString szFilter = "DXF Files (*.dxf)|*.dxf||";
CFileDialog fileDialog(TRUE, "dxf", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, NULL );
if(fileDialog.DoModal() == IDOK)
{
CString sDXF_FileName;
sDXF_FileName = fileDialog.GetPathName();
... do some processing on this file
UpdateData(FALSE);
}
}
Tested under windows XP it *works fine* (opening the File Dialog and processing the selected file as needed) but under windows 98 it works but when pressing on the IDC_READ_MYFILE button nothing happens (the File Open dialog is not open) while the close button works and also the about message box works (called inside the dialog top left System menu)
By the way I have checked the resources IDs and there isn't any conflict
any help/tips will be greatly appreciated
thanks in advance!
best regards
|
|
|
|
|
This is an MFC7 bug I'm afraid. There is an MSDN article on this I think (you'll get the same problem on Win95 and older versions of NT4).
The fix is to pass zero as the last param, e.g.:
CFileDialog fileDialog(TRUE, "dxf", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, NULL, 0);
When I am king, you will be first against the wall.
|
|
|
|
|
thank you very much!
i was getting crazy finding out which reasons could be causing that strange behaviour
best regards
|
|
|
|
|
Hi, i am making a MDI application and i am trying to add some splitters to it.
I want two splitters to divide the Frame/MDICLIENT window into tree panes/views and i want all views to show the same view-class.
Below is a clip of my code where i make the splitters :
if (!m_wndSplitter.CreateStatic(this,2,1))
{
TRACE(_T("failed to create the splitter"));
return FALSE;
}
if (!m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CAPecc2View),CSize(200, 200), pContext))
{
TRACE(_T("failed to create view in second pane"));
return FALSE;
}
// add the second splitter pane - which is a nested splitter with 2 rows
if (!m_wndSplitter2.CreateStatic(&m_wndSplitter,1,2))
{
TRACE0("Failed to create nested splitter\n");
return FALSE;
}
if (!m_wndSplitter2.CreateView(0,0,RUNTIME_CLASS(CAPecc2View),CSize(200, 200), pContext))
{
TRACE(_T("failed to create view in second pane"));
return FALSE;
}
if (!m_wndSplitter2.CreateView(0,1,RUNTIME_CLASS(CAPecc2View),CSize(200, 200), pContext))
{
TRACE(_T("failed to create view in second pane"));
return FALSE;
}
the problem i get is an assert in the following code :
CAPecc2Doc* CAPecc2View::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAPecc2Doc))); //NB, HERE is the problem???
return (CAPecc2Doc*)m_pDocument;
}
I did the same for a SDI application and i worked fine there, so i don't have a clue why it doesen't work for this application.
I hope there is someone who can help me, cause i am really stucked .
best regards
Bjørnar Skogseth
|
|
|
|
|
I'm not sure, maybe CDocument::AddView will help you. Try to add your views to document manually.
Dmitry Timin
|
|
|
|
|
Try this for a start: www.sockets.com
|
|
|
|
|
I need to use a CTreeCtrl in a CDialogBar window but
I have problems when I try to perform any operation
in the tree control. All operation fails so I have found
that the m_hWnd related to the TreeCtrl is 0x00000000.
Does someone knows which is the problem ??
Can the CTreeCtrl be used in a CDialogBar ??
|
|
|
|
|
Anthiny B. wrote:
Can the CTreeCtrl be used in a CDialogBar ??
Of course!
1) Check the block of code, which creates your TreeCtrl. What value is returned with Create function? What about GetLastError?
2) It may be a "race condition" - you might use a TreeCtrl when it has not been created yet. For example, it may be a WM_SIZE handler of your DialogBar
|
|
|
|
|
I don't create the TreeCtrl with the Create method !!!
I have created a class derived from CDialogBar and I manage
the TreeCtrl in that class using a CTreeCtrl member variable
created through Class Wizard. I'm sure to don't use that
variable before the window creation but I don not know how to
verify the creation of the Tree control !!!
|
|
|
|