Click to See Complete Forum and Search --> : Code Design To Utilise Sockets from within DLL


aingham
March 11th, 2009, 07:44 PM
I am having major troubles trying to come up with a code design for what I need to do. My situation is this:

I have two applications that I want to communicate to each other using sockets.
The program that I need to be the server uses a program specific programming language and so I have no socket API to utilise.
The program does however allow you to call a DLL and execute a DLL function.
I have tried calling my socket code from the DLL but the calling program hangs because within the socket code I am calling a continuous loop that does not return control back to the calling program.
The callling program states in its help that any process that is expected to take a long time should be started as a separate Windows thread.

The concept I am trying to grasp is hw can I continuously monitor the socket using a DLL function whilst still returning control to the calling application?

I have tried starting a new thread from within the DLL but I am not exactly sure how this works, if I return control to the calling program does this "kill" the new thread I have started? If not how do I communicate with the thread if say there is some information coming in from the socket?

Any help would be much appreciated.

_Superman_
March 12th, 2009, 12:22 AM
Threads execute independent of each other.
Once a thread is created it executes on its own.

So create a thread from within your DLL function.
You could pass a function pointer to your DLL function.

When the thread finished executing, call the function using the passed in function pointer.
This way you main module can be notified that the thread has finished execution.

Or you can use the Windows Event mechanism.