CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    1

    Code Design To Utilise Sockets from within DLL

    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.
    Last edited by aingham; March 11th, 2009 at 07:47 PM.

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: Code Design To Utilise Sockets from within DLL

    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.
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured