This code is written in VC++.NET. I have a windows form that display data from a socket port using callbacks. I have main.cpp that calls Application::Run(new Form1). The socket processing code is currently in the Form's file. I want to separate the Form1 from the socket processing code. Put the socket processing code in main.cpp. But it seems that the call to Application::Run doesn't return until Form1 is closed. Is there another way of launching Form1 so timers may be set after Form1 is up? Thanks.

That's correct. If I have a global function in main that is "SendMessage" to socket, will I be able to call it from a class? My instance of the GUI class is not allowed to be global. How would I get around this? My callbacks needs to use some functions in the class.

That's correct. If I have a global function in main that is "SendMessage" to socket, will I be able to call it from a class? My instance of the GUI class is not allowed to be global. How would I get around this? My callbacks needs to use some functions in the class.

Hmm, it sounds like you are using windows async sockets by using overlapped io (anyway that is the only way I know of to do it, it might very well be there are other ways)...
When I yerked around with it some years ago I figured the easiet way to get an pointer to the calling class is to just add the overlapped struct data to the top of the class and send the object pointer as overlapped argument... Not nice, but works if you are careful not to delete memory to early when canceling results (had a bunch of those)... A better way is probably to put the pointer in the hEvent variable since it is not used when lpOverlapped is not null... Either you could put the pointer directly, or try some indirect table index / handle to avoid instances were you delete the object before the callback happens (as I said, had a bunch of those)...

*Edit, Ok I just read the original post and to me it does not seem to have anything at all to do with what I read into the second post... Well since its bad to leave an empty message I guess I'll just leave this post here anyway.

This article has been dead for over six months. Start a new discussion instead.