|
You could check that the socket is readible firstly
BOOL IsSocketReadible(SOCKET socket, DWORD dwTimeout, BOOL& bReadible)
{
timeval timeout;
timeout.tv_sec = dwTimeout / 1000;
timeout.tv_usec = (dwTimeout % 1000) * 1000;
fd_set fds;
FD_ZERO(&fds);
FD_SET(socket, &fds);
int nStatus = select(0, &fds, NULL, NULL, &timeout);
if (nStatus == SOCKET_ERROR)
return FALSE;
else
{
bReadible = !(nStatus == 0);
return TRUE;
}
}
You specify a timeout for it to wait for data on the socket.
NOTE: Param 1 is ignored in windows sockets.
Ant.
|
|
|
|
|
Thanks for that code.
This is sort of unrelated to the previous question, but still about sockets...will program execution speed affect whether a socket can be read or not, for example if I send data and then try to receive on the next program line will the program most likely hit that line before the server has had time to respond?
Also would you happen to know how to connect to a POP3 server using windows sockets? I'm trying to do that but after I send the first send/recv (after connecting) the server doesn't seem to respond anymore...I even blocked on select for 20 seconds, but there was still no response from the server. Thanks for the help.
- Aaron
|
|
|
|
|
Absolutely, program execution is vastly faster than network communication. You will definately have to wait if you attempt send on one line then receive on the next.
If you are not bothered about when the data is received you can even spawn a thread to do the reciept. In fact this is not uncommon. When the thread gets the data it can post a thread message to the main application to go and do something with it.
WRT POP3 here is a great article http://www.naughter.com/pop3.html[^]
Ant.
|
|
|
|
|
Hi, i am a newbie in MS SQL Stored Procedures. I'm facing a big problem in binding the parameters when i want to access the returned output parameters from stored procedures. I can't get the output parameter if the parameter is char, varchar and datetime data type. But there is no problem for integer data type. Could anyone please giv me some guidances on how to access the parameter? Izzit different with the integer data type method? Thanks alot!!!
bamboo
|
|
|
|
|
BUILD AN MFC MDI WITH 2 FORMVIEWS THAT I CAN DISPLAY BY SELECTING IN A PULL DOWN MENU.
THE PROBLEM STARTS WHEN I CHOSE THE NEW WINDOW MENU.
I CAN STILL USE THE PULL DOWN MENU TO VIEW ONE OF THE 2 FORMVIEWS ON THE NEW WINDOW, BUT WHEN SELECT THE ORIGINAL VIEW AND USE THE PULL DOWN MENU TO SWITH TO THE OTHER FORMVIW, I GET AN ASSERTION ERROR. THE ERROR HAPPENS IN THE BASE CLASS'S SetActiveWindow() and the error pointing arrow points to IsChild(Wnd* pView).
HERE IS THE RELEVANT CODE:
*******************************
BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
/**********************************/
CMainFrame *pParentFrameWnd;
pParentFrameWnd = (CMainFrame*)this->GetParentFrame();
// pParentFrameWnd = (CMainFrame*)pApp->m_pMainWnd;
/*********************************/
CMDIPointApp* pApp = (CMDIPointApp*)AfxGetApp();
//ASSERT_KINDOF(CMDIPointApp, pApp);
CView* View;
CMDIDocTemplate* pTemplate;
POSITION pos = pApp->GetFirstDocTemplatePosition();
while(pos)
{
MessageBox(str,"CChildFrame::OnCreateClient()",MB_OK);
pTemplate = (CMDIDocTemplate*)pApp->GetNextDocTemplate(pos);
pContext->m_pNewViewClass = pTemplate->GetViewClass();
View = (CView*)CreateView(pContext);
ASSERT(View != NULL);
pTemplate->pView = View;
View->SetDlgCtrlID(0);
}
// ANY AND ALL CRICHEDITVIEW'S IN THE APP MUST BE FIRST VIEW(S) TO BE ACTIVATED
//IN ORDER FOR LAYOUT TO WORK. I ONLY HAVE ONE CRICHEDITVIEW IN MY APP
pTemplate = pApp->GetTemplate(RUNTIME_CLASS(CRICHEDITVIEW1));
if(pTemplate)
SetActiveView(pTemplate->pView);
pTemplate = pApp->GetFirstTemplate();
ActivateView(pTemplate->GetViewClass());
//DO NOT CALL CMDIChildWind::OnCreateClient since you are overriding behavior here
//return CMDIChildWnd::OnCreateClient(lpcs, pContext); //otherwise layout does not work
return TRUE;
}
void CChildFrame::ActivateView(CRuntimeClass *pViewClass)
{
CMDIPointApp* pApp = (CMDIPointApp*)AfxGetApp();
//ASSERT_KINDOF(CMDIPointApp, pApp);
CView *pActiveView = GetActiveView();
CRuntimeClass *pRun = pActiveView->GetRuntimeClass();
CMDIDocTemplate *pNewTemplate = pApp->GetTemplate(pViewClass);
CMDIDocTemplate *pActiveTemplate = pApp->GetTemplate(pRun);
//CMDIDocTemplate *pActiveTemplate = pApp->GetTemplate(pActiveView);
if(pNewTemplate == NULL) return;
if(pNewTemplate == pActiveTemplate)
{
MessageBox("NewTemplate == ActiveTemplate","");
return;
}
pActiveTemplate->pView->SetDlgCtrlID(0);
pNewTemplate->pView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
pActiveTemplate->pView->ShowWindow(SW_HIDE);
pNewTemplate->pView->ShowWindow(SW_SHOW);
SetActiveView(pNewTemplate->pView);
RecalcLayout();
}
BOOL CChildFrame::IsViewActive(CRuntimeClass *pViewClass)
{
// return(GetActiveView()->IsKindOf(pViewClass);)
CView* pActiveView = GetActiveView();
if (pActiveView == NULL) return FALSE;
return (pActiveView->GetRuntimeClass() == pViewClass);
return FALSE;
}
...js..
|
|
|
|
|
Hi I am just starting out with the whole c++ thing and was wondering if any one had any suggestions for some resources, books, online documentation, articles, websites, etc.
Three books I am looking at are:
"Practical Visual C++ 6" By Jon Bates and Tim Tompkins
and
"Thinking In C++" Vol. 1&2 By Bruce Eckel
Oh and one Last thing. Does anybody else have blisters on their right pinky from all the 0)-_=+[{}];'"\ ect.
Thanks
|
|
|
|
|
hello, I am a student I am using
"Learning C++ A Hand On Approach"
second edition
by Eric Nagler
this book is good for starter like me.
just suggestion.
from foxele
|
|
|
|
|
"The C++ LANGUAGE" from Bjarne Stroustrup
TOXCCT >>> GEII power
|
|
|
|
|
toxcct wrote:
"The C++ Programming Language" from Bjarne Stroustrup
It definitely is a very good book for people like you and me. But I don't think it quite easy to read for newbies.
Maxwell Chen
|
|
|
|
|
|
toxcct wrote:
guess what ?! i learnt C++ reading this book !!!
WOW!
toxcct wrote:
the difficulty in this book it to pass the 2 or 3 first chapters, but if you really want to, you can discover many things about C++ with it !
I agree! There are great techniques and deep philosophy within the book. But the style: *jump here and jump there so often* ... kind of flaw of this book.
Sometimes in a paragraph, for example it says: "foobar (Section 16.3.5) ...". And I moved there onto section 16.3.5, and I found nothing related.
Sometimes in the index it says that some jargon lies on page N, and I moved to that page N. I searched over and over within that page but couldn't find that word.
Maxwell Chen
|
|
|
|
|
Maxwell Chen wrote:
Sometimes in a paragraph, for example it says: "foobar (Section 16.3.5) ...". And I moved there onto section 16.3.5, and I found nothing related.
i don't know, i read a french traduction, perhaps these foo weren't traduced, or they were traduced into sometithing else.
for the links, i agree, but when i read it first, i didn't take time of going further in the book to see what he was talking about ; i said to me, "well, i'll see later..."
anyway, we do agree it is a good book
TOXCCT >>> GEII power
|
|
|
|
|
I started studying C++ with the book "C++ From The Ground Up, 2nd Edition" by Herbert Schildt. I read that book thoroughly from the beginning to the end without any skim.
But later I read Bjarne's book in the way picking topics which I haven't learned. So index plays an important key to me.
I read the English version, although I am a native Chinese speaker. I hate computer books in Chinese so much, because the translation for some jargons is bitch, hard to understand.
toxcct wrote:
a french traduction
A French translation.
traduce[^], (English):
to strongly criticize someone, especially in a way that harms their reputation.
traduction[^] (French):
translation.
When I was in university, I studied the French language. But never have a chance to use in practice. Now I've forgot all about French...
Je ne sais pas...
toxcct wrote:
i said to me, "well, i'll see later..."
Sounds like an avenger. Ha ha!
toxcct wrote:
we do agree it is a good book
Indeed!!
Maxwell Chen
|
|
|
|
|
|
Hi chaps,
Just been getting into a bit of ADO database programming and have been able to connect to a database on the same computer that my program is running on. All the resources I have read seem not to mention how to access a SQL db on a network or on a server, say the other side of the world.
The connection part of the program (in the document class) goes along these lines:
m_pConnection->Open(_bstr_t(L"Provider=Microsoft.Jet.OLEDB.3.51;Data Source=C:\\Program Files\\Microsoft Visual Studio\\VCDb.mdb;"),
_bstr_t(L""),
_bstr_t(L""),
adModeUnknown);
In this example I am connecting to a Microsoft Access DB. But supposing I want to connect to a MySQL DB running on a Linux Machine, or just simply another SQL DB on a Microsoft server ?
Apologies for the stupidity, but I am kind of new to this are of programming and am getting frustrated with poor recourses I have found.
Any help will greatly appreciated
Graham
|
|
|
|
|
May be this[^] will help
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
Is there a way to monitor if the USB port on system has had its connector removed?
|
|
|
|
|
I'm trying to draw a bitmap with a highlighted effect with the following code:
HBRUSH hSelBrush = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
DrawState(hDC, hSelBrush, NULL, MAKELPARAM(hBmp, 0), 0, x, y, ImgWidth, ImgHeight, DST_BITMAP | DSS_UNION);
DeleteObject(hSelBrush);
The problem is that it doesn't do it on the white pixels. Is there any way to fix it?
-thanks
|
|
|
|
|
Hi!
I would like to change the cursor of the entire system temporarily, so I cannot use SetSystemCursor. My goal is to hide the cursor, so I can either hide it or change it to a blank one that I load. ShowCursor(FALSE) seems to only apply to the current window.
Any help would be appreciated.
|
|
|
|
|
debacler wrote:
ShowCursor(FALSE) seems to only apply to the current window.
That's because the cursor is a shared resource. In Win32 one app isn't allowed to control such a resource since it would affect all apps running on the system.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Pinky, are you pondering what I'm pondering?
I think so Brain, but how will we fit the hamster inside the accordion?
|
|
|
|
|
You can change system wide cursor using ::SetSystemCursor() API. Then what else the problem u have. Just create a blank cursor in ur resource editor( here IDC_CURSOR1) Load it... Create another one cursor which is having ur system cursor ( here IDC_CURSOR2).
void CTestDlg::OnHideCursor()
{
HCURSOR h1 = AfxGetApp( ) -> LoadCursor ( IDC_CURSOR1 ) ;// User your blank cursor here
HCURSOR h2 = CopyCursor ( h1 ) ;
::SetSystemCursor ( h2, OCR_NORMAL ) ;
}
void CTestDlg::OnShowCursor()
{
HCURSOR h1 = AfxGetApp( ) -> LoadCursor ( IDC_CURSOR2 ) ;// User your system cursor here
HCURSOR h2 = CopyCursor ( h1 ) ;
::SetSystemCursor ( h2, OCR_NORMAL ) ;
}
Thatzaal..;)
loveablevirus
|
|
|
|
|
Thanks
The hide cursor code works great, but when I show the cursor again, I want it to be the user's cursor, not one stored in my resources. So instead of AfxGetApp()->LoadCursor(...) for the show function, I'm trying this:
HCURSOR h1=LoadCursor(0,IDC_ARROW);<br />
HCURSOR h2=CopyCursor(h1); <br />
::SetSystemCursor(h2,OCR_NORMAL);
Which doesn't work, and I have to restore the cursor otherwise. How can I restore the original cursor?
|
|
|
|
|
Ya.. I dOno why its not working... but there is another one solution to restore the system cursor (without using ur resource). Declare a HCURSOR m_h; member variable to ur dlg class.
void CTestDlg::OnHideCursor()
{
m_h=CopyCursor(LoadCursor(NULL,IDC_ARROW)); // Store system cursor in m_h
HCURSOR h1 = AfxGetApp( ) -> LoadCursor ( IDC_CURSOR1 ) ; // Load ur cursor
::SetSystemCursor ( h1, OCR_NORMAL ) ; // Change system cursor with urs
}
void CTestDlg::OnShowCursor()
{
::SetSystemCursor ( m_h, OCR_NORMAL ) ; // Restore system cursor from m_h
}
It is working well for me. Try urself.
Hava nice day;)
with regards
loveablevirus
|
|
|
|
|
That works wonderfully! Thank you very much! I tried doing something similar but mine involved copy cursor and it didn't work right, so simple and elegent.
|
|
|
|
|
I am writing a web download installer and need to make it as small as possible. A lot of MFC is a black box to me so I am not sure which pieces I can hack out and still expect the program to behave as expected.
It is currently 210 KB and I only wrote a thousand or so lines of source code (including comments). There is only 1 window and it is a dialog-based app. It does use the file open common dialog box and afxinet.h
Thanks!
//placeholder for witty verbiage
|
|
|
|