• 로그인 함 해보끄나?

  • Sarangnamu.net June 17, 2003
    Home Login Profile Study Open Project Q&A Google Code
    VARIANT from String
    Last Modify : 13 December, 2010(01:55)
    // Macro that calls a COM method returning HRESULT value.
    #define CHK_HR(stmt)        do { hr=(stmt); if (FAILED(hr)) throw _T("ERROR CHK_HR"); } while(0)

    // Macro to verify memory allcation.
    #define CHK_ALLOC(p)        do { if (!(p)) { hr = E_OUTOFMEMORY; throw _T("ERROR CHK_ALLOC"); } } while(0)

    // Helper function to create a VT_BSTR variant from a null terminated string.
    HRESULT VariantFromString(PCWSTR wszValue, VARIANT &Variant)
    {
        HRESULT hr = S_OK;
        BSTR bstr = SysAllocString(wszValue);
        CHK_ALLOC(bstr);

        V_VT(&Variant)   = VT_BSTR;
        V_BSTR(&Variant) = bstr;

        return hr;
    }

    int SampleCode()
    {
        VARIANT varFileName;

        try
        {
            HRESULT hr = S_OK;
            CHK_HR(VariantFromString(L"stocks.xml", varFileName));
        }
        catch (const TCHAR* szErrorMsg)
        {
            TRACE(_T("%s"), szErrorMsg);
        }

        VariantClear(&varFileName);

        return 0;
    }

    Comment


    입력하3 1508232099



    Locations of visitors to this page