Executing a function from another thread.

This is a discussion on Executing a function from another thread. within the C Programming forums, part of the General Programming Boards category; Hey guys, first post here so I hope you can help Basically i'm making a simple Instant Messanger program for ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    6

    Executing a function from another thread.

    Hey guys, first post here so I hope you can help

    Basically i'm making a simple Instant Messanger program for a data communication projects. I didn't really know anything about socket/thread programming prior to this so i'm trying to work my way through just to get it finished in time. The program works great except that I wanted to add functionality that would load a window when a message is received from a user [as typical messangers do]. I have the window designed and everything works when I load it from the application, however I have a seperate thread listening for incoming connections/data, parsing, and executing commands based on the messages. If I try to pop up a chat window from inside the socket thread it ends up crashing the program whenever I try to interact with it. I'm pretty sure this is because the socket thread doesn't have the win32 messages loop stuff that's required to get feedback from windows.

    In short: I'd like to find a way to call a function from the main program by sending some short of message back from the thread doing the socket information. That way the window should load without programs and be able to have interaction from the user.

    Does anyone know of a simple way to implement this?

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I think you could use postthreadmessage with getcurrentthreadid which is equivalent to postmessage with the hwnd identifier set to null. Then you can respond to the message and open a window or stab the user in the face or something.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  2. Object Creation in thread function
    By sl4nted in forum Windows Programming
    Replies: 18
    Last Post: 10-11-2008, 03:37 PM
  3. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  4. Thread Synchronization in Win32
    By passionate_guy in forum C Programming
    Replies: 0
    Last Post: 02-06-2006, 05:34 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21