Results 1 to 4 of 4

Thread: ALT/COM and createthread question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Okinawa, Japan
    Posts
    271

    ALT/COM and createthread question

    Problem:

    Ok, Ive created COM through the Wizard and added one method and one connection point.

    When the method gets called im doing createthread to static function and doing a createevent with RegNotifyChangeKeyValue.
    Once the event is received im trying to raise an event via a connectionpoint.

    This is my static function:
    static DWORD WINAPI CThread(CTestMe *pthis)
    { DWORD dwFilter = REG_NOTIFY_CHANGE_NAME |
    REG_NOTIFY_CHANGE_ATTRIBUTES |
    REG_NOTIFY_CHANGE_LAST_SET |
    REG_NOTIFY_CHANGE_SECURITY;

    HKEY hMainKey;


    lErrorCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",0, KEY_NOTIFY, &hKey);
    if (lErrorCode != ERROR_SUCCESS)
    {

    return -1;
    }

    // Create an event.
    hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (hEvent == NULL)
    {

    return -1;
    }


    // Watch the registry key for a change of value.
    lErrorCode = RegNotifyChangeKeyValue(hKey,
    TRUE,
    dwFilter,
    hEvent,
    TRUE);
    if (lErrorCode != ERROR_SUCCESS)
    {

    return -1;
    }


    if (WaitForSingleObject(hEvent, INFINITE) == WAIT_FAILED)
    {
    return -1;
    }


    lErrorCode = RegCloseKey(hKey);
    if (lErrorCode != ERROR_SUCCESS)
    {
    return -1;
    }
    if (!pthis)
    {
    MessageBox( NULL, "null ptr", "main", MB_OK );
    }
    pthis->Fire_Done(0); //this causes app to crash.

    return 0;
    }

    here is my method:
    STDMETHODIMP CTestMe::AddNums(int x, int y)
    {

    HANDLE hThread;
    char szMsg[80];

    hThread=CreateThread(NULL,0, (LPTHREAD_START_ROUTINE)CThread,this,0,(LPDWORD)&d_threadID );

    if (hThread==NULL)
    {
    wsprintf( szMsg, "CreateThread failed." );
    MessageBox( NULL, szMsg, "main", MB_OK );
    return S_FALSE;
    }

    return S_OK;
    }

    Im passing the this pointer to my createthread function. If I add another method, I can call it via my passed ptr. But it fails when I try calling the event.

    Any clues on what im doing wrong??

    Thanks

    PacketVB

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Okinawa, Japan
    Posts
    271
    CornedBee,
    Oh knowledgable one, where are you


    But really, got an idea's?

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Haven't ever worked with GUI ActiveX controls, only invisible ActiveX utility objects. Sorry.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Have you stepped through it with a debugger? Does the function call itself cause the crash or something inside? Maybe Fire_Done has an error somewhere.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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