locked
Calling .Net COM object from credential provider.... RRS feed

  • Question

  • Currently I am working with one of the sample credential providers from the Windows SDK (SampleCredentialProvider).

    I've modified the code a bit to attempt to call a function from a dll written in VB.Net. This call fails with a return of:

    "hr = 0x80070002 The system cannot find the file specified. "

    Now, I have been successful calling the exact same function from a native C++ app but I now want to try and call it successfully from a credential provider.

    If anyone can advise on what the error indicates, or how I can better debug this I would appreciate it.

    From what I have read, mixing the credential providers with managed code is not the way to go, but I want to see if I can do it.

    Below is a copy of my modification to the SampleCredentialProvider project. Specifically in CSampleCredential::Advise.

    My code is between the comments and I have a comment just prior to the call that throws the error.

    HRESULT CSampleCredential::Advise(
        __in ICredentialProviderCredentialEvents* pcpce
        )
    {
        if (_pCredProvCredentialEvents != NULL)
        {
            _pCredProvCredentialEvents->Release();
        }
        _pCredProvCredentialEvents = pcpce;
        _pCredProvCredentialEvents->AddRef();

        ///////////////////////////////Attempt to call managed code///////////////////////////////////////////////////////
        HRESULT hr;

        IID iid;
        hr = IIDFromString(L"{11CFF0B6-69BA-3BBA-A4A1-AFEC52B63307}", &iid);

        CLSID clsid;
        hr = CLSIDFromString(L"{E1044C72-0DAB-3B05-B80F-0F9030574856}", &clsid);

        hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

        TestCOMLib::IMyManagedInterface *pManagedInterface = NULL;
        hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, reinterpret_cast<void**>(&pManagedInterface));
        
        if (S_OK == hr)
        {  
            VARIANT_BOOL retVal;

            //ERROR occurs on this call:  /////////////////////////////////////////////////
            hr = pManagedInterface->raw_ShowSmileyFace(&retVal);

            pManagedInterface->Release();
        }

        CoUninitialize();
        ///////////////////////////////////////////////////////////////////////////////////////

        return S_OK;
    }

    Also, please direct this to the correct forum...thanks.

    Tuesday, July 10, 2012 2:46 PM

Answers

All replies