Thread: SHAutoComplete/COM Problems

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

    SHAutoComplete/COM Problems

    Hi all.
    I've been having trouble for the past few days trying to get SHAutoComplete to work in my program. Basically, I've implemented it dynamically (LoadLibrary/GetProcAddress) but when my app reaches the end, two threads (i presume created by the two calls to SHAutoComplete) remain active and my app never exits. Here is my code for COM and SHAutoComplete. If i remove this code, the app terminates when expected and I've also tried initializing COM as multithreaded (CoInitializeEx) which failed entirely. If anyone could take a look at it and see what I'm missing I would really appreciate it.

    Thanks in advance, Ehtyar.

    [edit]
    I've also tried moving the calls to Co(Un)Initialize to the inside of the calls to LoadLibrary/FreeLibrary with no success.
    [/edit]
    Last edited by Ehtyar; 06-02-2007 at 07:21 PM. Reason: Addition.

  2. #2
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    I normally use LoadLibrary before the messsage loop begins and call FreeLibrary after the message loop.
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    12
    I do......
    Code:
    //Before Dialog Creation: AKA before CreateDialogParam
    <snip>
    hShlwapi = LoadLibrary("shlwapi.dll");

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Your app should exit either when you return from WinMain or when you call ExitProcess, regardless of any threads still running. Are you sure that one of these things is happening?

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    12
    I didn't necessarily mean that the threads are what's preventing the app from exiting, i just assume they have something to do with it because when i remove the Co* code, they're no longer there before the app exits as it should.
    At the moment, I am getting around this problem by calling ExitProcess before returning from my entry point (i don't use WinMain), but it's an ugly hack, and i shouldn't be doing it, and since it is clearly my accessing COM that is causing this problem, I'm assuming I'm doing something wrong.

    Ehtyar.

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    It sounds like you adhere to the old-fashioned theory on how processes exit.

    ExitProcess should be called to exit a process. Typically, this is done by the wrapper code for main or WinMain. If you define your own entry function, it is your responsibility.

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    12
    Is it just me, or did m$ forget to notify us "old-fasioned" ones of this marvelous new idea? Thanks for the replies anonytmouse, seems i was doing the right thing after all

    Ehtyar.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM