Click here to Skip to main content
15,907,492 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Different (Wrong) answers when not debugging Pin
CPallini7-Jan-10 22:09
mveCPallini7-Jan-10 22:09 
AnswerRe: Different (Wrong) answers when not debugging Pin
Brien Smith-Martinez7-Jan-10 23:06
Brien Smith-Martinez7-Jan-10 23:06 
AnswerRe: Different (Wrong) answers when not debugging Pin
KarstenK7-Jan-10 23:20
mveKarstenK7-Jan-10 23:20 
QuestionHow to save content in IPicture to JPG format? Pin
Jingcheng7-Jan-10 9:04
Jingcheng7-Jan-10 9:04 
QuestionRe: How to save content in IPicture to JPG format? Pin
David Crow7-Jan-10 11:02
David Crow7-Jan-10 11:02 
AnswerRe: How to save content in IPicture to JPG format? Pin
Jingcheng7-Jan-10 13:29
Jingcheng7-Jan-10 13:29 
GeneralRe: How to save content in IPicture to JPG format? Pin
Hamid_RT7-Jan-10 20:40
Hamid_RT7-Jan-10 20:40 
Question[Solved]Network messages not being sent to the window procedure when using asynchrnous sockets [modified] Pin
zoopp7-Jan-10 7:53
zoopp7-Jan-10 7:53 
Hello everybody!

I'm working on a small personal project which has to use async sockets. So far I've not yet finished the GUI (since I'm coding it with pure WinAPI, it's going to take some time) but i thought to give it a shot and see if it's processing all specified messages in WndProc but so far i realized that it isn't processing network messages. Here's a sample code from my project:

int WINAPI WinMain(HINSTANCE currentInst, 
				   HINSTANCE prevInst, 
				   LPSTR args, 
				   int showVar)
{
	////////////////////////////////
	//Initializing WinSock library//
	////////////////////////////////

	WSADATA wsaData;
    if(WSAStartup(0x0202, &wsaData))
    {
		MessageBox(NULL,"Call to WSAStartup() failed at line #", "Error!", MB_ICONEXCLAMATION | MB_OK);
        WSACleanup();
        return wsaFail;
    }
    else
    {
        if(wsaData.wVersion != 0x0202)
        {
			MessageBox(NULL,"Wrong socket version! at line #", "Error!", MB_ICONEXCLAMATION | MB_OK);
            WSACleanup();
            return wsaFail;
        }
    }

	////////////////////////////
	//Declaration of variables//
	////////////////////////////

	WNDCLASSEX windowClass;
	HWND handleToWindow;
	SOCKET serverSocket;
	sockaddr_in serverSockAddrIn;
	MSG Msg;

	///////////////////////////////////////////////////////////////
	//Registering the Window Class and creating an actuall window//
	///////////////////////////////////////////////////////////////

	windowClass.cbSize = sizeof(WNDCLASSEX);
	windowClass.style = CS_HREDRAW | CS_NOCLOSE | CS_VREDRAW;
	windowClass.lpfnWndProc = WndProc; //Window Procedure
	windowClass.lpszClassName = class_name;
	windowClass.cbClsExtra = 0;
	windowClass.cbWndExtra = 0;
	windowClass.hInstance = currentInst;
	windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 6);
	windowClass.lpszMenuName = NULL;
	windowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

	if(!RegisterClassEx(&windowClass))
	{
		MessageBox(NULL, "Window Registration Failed at EntryPoint.cpp line #", "Error!", MB_ICONEXCLAMATION | MB_OK);
		return windowRegistrationFail;
	}

	//Creating the window
	handleToWindow = CreateWindowEx(WS_EX_CLIENTEDGE | WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST, 
									class_name, 
									"Server Console",
									WS_OVERLAPPED| WS_VISIBLE, 
									400, 500, 800, 500, NULL, NULL, currentInst, NULL);
	
	if(handleToWindow == NULL)
	{
		MessageBox(NULL, "Window Creation Failed at line #", "Error!", MB_ICONEXCLAMATION | MB_OK);
		return windowCreationFail;
	}
	UpdateWindow(handleToWindow);
	////////////////////////
	//Seting up the scoket//
	////////////////////////

	//sockaddr_in struct
	memset(&serverSockAddrIn, 0, sizeof(serverSockAddrIn));
    serverSockAddrIn.sin_family = AF_INET;
    serverSockAddrIn.sin_port = htons(2567);
    serverSockAddrIn.sin_addr.s_addr = htonl(INADDR_ANY);
	
	//socket
	serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

	if(serverSocket == INVALID_SOCKET)
	{
		MessageBox(NULL, "Socket Creation Failed at EntryPoint.cpp line#", "Error!", MB_ICONEXCLAMATION | MB_OK);
		WSACleanup();
		return socketFail;
	}
	
	//Making it async//

	WSAAsyncSelect(serverSocket, handleToWindow, NetworkNotification, FD_ACCEPT | FD_READ | FD_WRITE | FD_CLOSE);
	//Binding it//
	if(bind(serverSocket, (sockaddr*)&serverSockAddrIn, sizeof(serverSockAddrIn)) == SOCKET_ERROR)
		return 0;
	
	while(GetMessage(&Msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	return 0;
}


So far this is the whole entry point of my program. Keep in mind that it's not finished yet. Please do not reply with coments like "You should error check at x" etc. if it's not a possible fix for my problem.

WndProc (showing only network messages):

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case NetworkNotification:
		{
			switch(WSAGETSELECTEVENT(lParam))
			{
			case FD_ACCEPT:
				{
					MessageBox(hwnd, "Success!", "Test", NULL);
					break;
				}
			case FD_READ:
				break;
			case FD_WRITE:
				break;
			case FD_CLOSE:
				break;
			}
		}
	case WM_COMMAND:
		{
                  //bla bla bla
		}
	case WM_CREATE:
		{
                  //creating controlls here
		}
	default: 
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
}


I repeat...it's not the whole WndProc here. Unless it's really needed i wouldn't like to post it all.

As far as I'm aware, it should show the message box when a client is trying to connect, but of course.. since i'm not calling accept() the client won't be able to connect but it still should trigger a FD_ACCEPT event...right ?

Ahh...i almost forgot..

#define NetworkEvent (WM_USER + 5)


modified on Friday, January 8, 2010 8:32 AM

AnswerRe: Network messages not being sent to the window procedure when using asynchrnous sockets Pin
Richard MacCutchan7-Jan-10 9:05
mveRichard MacCutchan7-Jan-10 9:05 
AnswerRe: Network messages not being sent to the window procedure when using asynchrnous sockets Pin
Moak7-Jan-10 9:44
Moak7-Jan-10 9:44 
GeneralRe: Network messages not being sent to the window procedure when using asynchrnous sockets Pin
zoopp8-Jan-10 2:32
zoopp8-Jan-10 2:32 
QuestionScanline Polygon Fill Algorithm ??? Pin
a04.lqd7-Jan-10 7:48
a04.lqd7-Jan-10 7:48 
AnswerRe: Scanline Polygon Fill Algorithm ??? Pin
Nelek7-Jan-10 7:53
protectorNelek7-Jan-10 7:53 
GeneralRe: Scanline Polygon Fill Algorithm ??? Pin
a04.lqd7-Jan-10 7:55
a04.lqd7-Jan-10 7:55 
RantRe: Scanline Polygon Fill Algorithm ??? Pin
Nelek7-Jan-10 8:07
protectorNelek7-Jan-10 8:07 
GeneralRe: Scanline Polygon Fill Algorithm ??? Pin
a04.lqd7-Jan-10 8:36
a04.lqd7-Jan-10 8:36 
JokeRe: Scanline Polygon Fill Algorithm ??? Pin
Richard MacCutchan7-Jan-10 9:06
mveRichard MacCutchan7-Jan-10 9:06 
GeneralRe: Scanline Polygon Fill Algorithm ??? Pin
josda10007-Jan-10 10:03
josda10007-Jan-10 10:03 
GeneralRe: Scanline Polygon Fill Algorithm ??? Pin
Luc Pattyn7-Jan-10 13:13
sitebuilderLuc Pattyn7-Jan-10 13:13 
GeneralRe: Scanline Polygon Fill Algorithm ??? Pin
CPallini7-Jan-10 12:13
mveCPallini7-Jan-10 12:13 
GeneralRe: Scanline Polygon Fill Algorithm ??? Pin
Nelek7-Jan-10 20:39
protectorNelek7-Jan-10 20:39 
GeneralRe: Scanline Polygon Fill Algorithm ??? Pin
Tim Craig7-Jan-10 8:57
Tim Craig7-Jan-10 8:57 
GeneralRe: Scanline Polygon Fill Algorithm ??? Pin
josda10007-Jan-10 10:04
josda10007-Jan-10 10:04 
GeneralRe: Scanline Polygon Fill Algorithm ??? Pin
CPallini7-Jan-10 11:52
mveCPallini7-Jan-10 11:52 
GeneralRe: Scanline Polygon Fill Algorithm ??? Pin
Tim Craig7-Jan-10 17:17
Tim Craig7-Jan-10 17:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.