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

    MFC Bug or My Bug

    I've written a very simple MFC Dialog Program
    A dialog contain a OK Button and a edit control
    then i write the following code

    UINT TestThread(LPVOID lpParam)
    {
    CSocket s;
    s.Create(0,SOCK_DGRAM);
    while (1) {
    //...
    Sleep(1000);
    }
    }

    void CTestDialog::OnOK()
    {
    AfxSocketInit(NULL);
    AfxBeginThread(TestThread,0);
    }

    when the thread start, all things seems well, but when i want to shift another input method in the edit box, the mainthread is hang~

    What's the problem in my code .
    Any advice will be appreciate

  2. #2
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: MFC Bug or My Bug

    Call the AfxInitSocket() function only once in your CWinApp::InitInstance.
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

  3. #3
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: MFC Bug or My Bug

    Also specify the lpszSockAddress (third parameter in Create function) as a pointer to a string containing the network address of the connected socket.
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

  4. #4
    Join Date
    Mar 2001
    Posts
    39

    Re: MFC Bug or My Bug

    thanks amarcode, but i've try your way before, and the error still~

    when i Replace all the CSocket Function with SOCKET function , the whole scenario work very well.

    but it really a problem that confused me for 2 days .

    i think the core thing is:
    when i use a MFC Class with MessageQueue in a Thread, Something happen but i do not know.

    any new advice?

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: MFC Bug or My Bug

    [ Moved thread ]

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