I have been working on my first win32 assembly
program for the past few days and I have hit a

It was mentioned on this board before, but I did
not see a solution. On a button event I am
starting a new thread to handle winsock
connections. I can get the thread to use its own
message loop, but not its own wndproc.

I would leave it there, but while testing, I am
able to stall the program the program by putting
the thread into and infinite loop. That does not
sound like a true thread to me.

Keeping it to the thread proc I am able to spin
the thread and keep the program flow (cool). I
tried using a MDI client, it would seem to work,
but it also failed.

I do not want to resort to a new process, I want
to share data.

Here is the code, it is large, little comments.
The commented-out code works, but gives "cannot
create window", you can let it resume. Also
change the hwnd to hwndServer in WSAAsyncSelect.


I would like to thank all who worked on Iczelion's
tutorials, I am finally getting Windows API.
Posted on 2002-02-26 02:33:11 by bdjames
I don't think you can use hServerProcess as an hInstance. The hInstance is the handle of the module (EXE or DLL) that "owns" the window class. You establish ownership when you register the window class.
Posted on 2002-02-26 20:32:38 by tenkey
I did simular things, but with a little bit different stratagy.
Your thread can do whatever it need and if you need
main window of react properly on events of second thread
you can just send messages from the second tread to main
For example your need to establish contact to some net resourses
and it maybe lengthy did - if you do it in the main thread it could
hung the window, cause it would respond untill the function
called for connection finish its job.
At the same time you don't want users to click some bottons
while you haven't gotten responce of the second thread about
Than you can do it this way -
in MainWindow proc
create second thread
make buttons unvisible
maybe display some avi about connection
in main window procedure you need to have code that
handling some Msg you can get from second thread
In second thread when you are done just send predefined
message to main proc
on responce of the message main proc makes buttons
visible and do whatever it needs to do after the second thread is
Posted on 2002-02-26 20:48:08 by The Svin
I did it!!!!!!!!!!!!!!!!!!


Test with socket client.
Posted on 2002-02-27 16:31:03 by bdjames
i think a thread must has one or more window(hwnd) that it can be assigned msg queue by windows os.so new thread may has no msg queue or has diff msg queue from main thread.
therefor i think use event/waitfor* is the better way.
sendmessage from new thread to mainthread or postthreadmessage is ng. postthreadmessage maybe fail and sendmessage maybe hang thread..

Posted on 2002-02-28 12:04:52 by xqterry