#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    25
    Rep Power
    0

    CoCreateInstance Fails in Windows XP


    I am calling CoCreateInstance to create a shortcut in Windows using C++. My program compiles find, but when I run it in XP, it encounters an error and closes. I run it in Compatability Mode in Windows 98/ME and it works just fine. What do I need to do to make it compatable with XP?
  2. #2
  3. No Profile Picture
    status unknown
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    262
    Rep Power
    11
    What error do you get when you run it in XP?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    25
    Rep Power
    0
    The error message is:
    "My Program has encountered a problem and needs to close. We are sorry for the inconvenience."
    It allows you to debug, send an error report, or don't send an error report.
  6. #4
  7. No Profile Picture
    status unknown
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    262
    Rep Power
    11
    Do you know whether CoCreateInstance itself succeeds, do you test the return value? Have you been able to determine what point your program gets to before you get the error?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    25
    Rep Power
    0
    It fails when I try to use the pointer to set a path for my shortcut. The pointer equals NULL. Here's my code:

    IShellLink* psl;
    hres=CoCreateInstance(
    CLSID_ShellLink,
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_IShellLink,
    (LPVOID*)&psl
    );
    if (!SUCCEEDED(hres) || psl==NULL)
    {
    CoUninitialize();
    }
    IPersistFile* ppf;
    psl->SetPath("C:\\Program Files\\My Program\\program.exe");
    psl->SetDescription("Launch Program");
    psl->SetIconLocation("C:\\Program Files\\My Program\\program.exe", 0);
    psl->QueryInterface(IID_IPersistFile,(LPVOID*)&ppf);
    ppf->Save(wLinkPath, FALSE);
    ppf->Release();
    CoUninitialize();

IMN logo majestic logo threadwatch logo seochat tools logo