Separating socket code from GUI code

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2005
Posts: 69
Reputation: DotNetUser is an unknown quantity at this point 
Solved Threads: 0
DotNetUser DotNetUser is offline Offline
Junior Poster in Training

Separating socket code from GUI code

 
0
  #1
Nov 22nd, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: Separating socket code from GUI code

 
0
  #2
Nov 25th, 2005
You just want to move source code from one file to another?
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 69
Reputation: DotNetUser is an unknown quantity at this point 
Solved Threads: 0
DotNetUser DotNetUser is offline Offline
Junior Poster in Training

Re: Separating socket code from GUI code

 
0
  #3
Nov 28th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 78
Reputation: perniciosus is an unknown quantity at this point 
Solved Threads: 4
perniciosus's Avatar
perniciosus perniciosus is offline Offline
Junior Poster in Training

Re: Separating socket code from GUI code

 
0
  #4
Nov 29th, 2005
Originally Posted by DotNetUser
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.
/pern.*/i

Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. Albert Einstein
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC