c++skypeskype4com

Initializing ISkypeClientPtr


I've racked my brain over this for some hours: pClient is always NULL (0x000000). pClient doesn't seem to initialize the same way as ISkypePtr, IUserCollectionPtr, and IUserPtr?

ISkypePtr pSkype(__uuidof(Skype));
while (TRUE){
    IUserCollectionPtr pResults = pSkype->SearchForUsers("john doe");
    for (int i = 1; i <= pResults->Count; ++i){
        IUserPtr pUser = pResults->GetItem(i); _bstr_t handle = pUser->GetHandle(); 
        IClientPtr pClient;
        pClient->OpenAddContactDialog(handle);
        Sleep(30000);
    }
}

Solution

  • You're not making any effort to initialise pClient: in the other two cases you're giving it a CLSID to instantiate and you're assigning it from a COM object pointer you received back. I'd guess you want the following:

    // Start client
    IClientPtr pClient = pSkype->GetClient();
    if (pClient->IsRunning == VARIANT_FALSE)
        pClient->Start(VARIANT_FALSE, VARIANT_FALSE);
    

    (taken from this project on GoogleCode). This won't need to be in the while loop assuming you're not planning to close the client after each contact request.

    But please use this responsibly and not for generating spam contact requests. Thanks.