当前位置: 首页>>代码示例>>C++>>正文


C++ VariantClear函数代码示例

本文整理汇总了C++中VariantClear函数的典型用法代码示例。如果您正苦于以下问题:C++ VariantClear函数的具体用法?C++ VariantClear怎么用?C++ VariantClear使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了VariantClear函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CoCreateInstance

BOOL CEnumerateSerial::UsingWMI(CSimpleArray<UINT>& ports, CSimpleArray<CString>& friendlyNames)
#endif
{
  //Make sure we clear out any elements which may already be in the array(s)
#if defined CENUMERATESERIAL_USE_STL
  ports.clear();
  friendlyNames.clear();
#else
  ports.RemoveAll();
  friendlyNames.RemoveAll();
#endif  

  //What will be the return value
  BOOL bSuccess = FALSE;

  //Create the WBEM locator
  IWbemLocator* pLocator = NULL;
  HRESULT hr = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, IID_IWbemLocator, reinterpret_cast<void**>(&pLocator));
  if (SUCCEEDED(hr))
  {
    IWbemServices* pServices = NULL;
    hr = pLocator->ConnectServer(_bstr_t("\\\\.\\root\\cimv2"), NULL, NULL, NULL, 0, NULL, NULL, &pServices);
    if (SUCCEEDED(hr))
    {
      //Execute the query
      IEnumWbemClassObject* pClassObject = NULL;
      hr = pServices->CreateInstanceEnum(_bstr_t("Win32_SerialPort"), WBEM_FLAG_RETURN_WBEM_COMPLETE, NULL, &pClassObject);
      if (SUCCEEDED(hr))
      {
        bSuccess = TRUE;

        //Now enumerate all the ports
        hr = WBEM_S_NO_ERROR;

        //Final Next will return WBEM_S_FALSE
        while (hr == WBEM_S_NO_ERROR)
        {
          ULONG uReturned = 0;
          IWbemClassObject* apObj[10];
          memset(apObj, 0, sizeof(apObj));
          hr = pClassObject->Next(WBEM_INFINITE, 10, reinterpret_cast<IWbemClassObject**>(apObj), &uReturned);
          if (SUCCEEDED(hr))
          {
            for (ULONG n=0; n<uReturned; n++)
            {
              VARIANT varProperty1;
              VariantInit(&varProperty1);
              HRESULT hrGet = apObj[n]->Get(L"DeviceID", 0, &varProperty1, NULL, NULL);
              if (SUCCEEDED(hrGet) && (varProperty1.vt == VT_BSTR) && (wcslen(varProperty1.bstrVal) > 3))
              {
                //If it looks like "COMX" then add it to the array which will be returned
                if ((_wcsnicmp(varProperty1.bstrVal, L"COM", 3) == 0) && IsNumeric(&(varProperty1.bstrVal[3]), TRUE))
                {
                  //Work out the port number
                  int nPort = _wtoi(&(varProperty1.bstrVal[3]));
                #if defined CENUMERATESERIAL_USE_STL
                  ports.push_back(nPort);
                #else
                  ports.Add(nPort);
                #endif

                  //Also get the friendly name of the port
                  VARIANT varProperty2;
                  VariantInit(&varProperty2);
                  if (SUCCEEDED(apObj[n]->Get(L"Name", 0, &varProperty2, NULL, NULL)) && (varProperty2.vt == VT_BSTR))
                  {  
                #if defined CENUMERATESERIAL_USE_STL
                  #if defined _UNICODE  
                    std::wstring szName(varProperty2.bstrVal);
                  #else
                    CAutoHeapAlloc szAsciiValue;
                    int nLengthA = WideCharToMultiByte(CP_ACP, 0, varProperty2.bstrVal, -1, NULL, 0, NULL, NULL);
                    if (nLengthA)
                    {
                      if (szAsciiValue.Allocate(nLengthA))
                        WideCharToMultiByte(CP_ACP, 0, varProperty2.bstrVal, -1, static_cast<LPSTR>(szAsciiValue.m_pData), nLengthA, NULL, NULL);
                    }

                    std::string szName(static_cast<LPSTR>(szAsciiValue.m_pData));
                  #endif
                    friendlyNames.push_back(szName);
                  #else
                    friendlyNames.Add(CString(varProperty2.bstrVal));    
                  #endif
                  }
                  else
                  {
                  #if defined CENUMERATESERIAL_USE_STL
                    friendlyNames.push_back(_T(""));
                  #else
                    friendlyNames.Add(_T(""));
                  #endif  
                  }

                  //Free up the variant;
                  VariantClear(&varProperty2);
                }
              }

              //Free up the variant;
//.........这里部分代码省略.........
开发者ID:gdijaejung,项目名称:Common,代码行数:101,代码来源:enumser.cpp

示例2: main

int main(int argc, char* argv[])
{
    IADs             *pNS = NULL,
                     *pRoot=NULL,
                     *pAuth=NULL;
    
    IADsOpenDSObject *pDSObj=NULL;

    VARIANT varDSRoot;

    TCHAR   adspath[MAX_PATH],username[255],password[255];

    HRESULT hr;

	hr = CoInitialize(NULL);
	
	//  Get the name of the root container for this domain.  
	//  Read the Root DSE from the default DS,  which will be the DS for 
	//  the local domain.  This will get us the name of the schema container,
	//  which is stored in the "defaultNamingContext" operational attribute.

    hr = ADsGetObject(TEXT("LDAP://RootDSE"),
                      IID_IADs,
                      (void**)&pRoot);

	if ( FAILED(hr) )
	{
		::CoUninitialize();
		_tprintf(TEXT("\nError in ADsGetObject"));
		return 1;
	}


   	hr = pRoot->Get(TEXT("defaultNamingContext"),&varDSRoot);

	if ( FAILED(hr) )
	{
		::CoUninitialize();
		pRoot->Release();
		_tprintf(TEXT("\nError in reading defaultNamingContext"));
		return 1;

	}

	_tprintf(TEXT("\nDomain Name is :%s\n"),varDSRoot.bstrVal);
    pRoot->Release();

    _tcscpy_s(adspath,MAX_PATH, TEXT("LDAP://"));
	// get the remaining buffer size; make sure it copies, avoid buffer overrun
	int rem =  (sizeof(adspath)/sizeof(TCHAR)) - _tcslen(adspath) -1; //-1 is for NULL
	int len = wcslen(varDSRoot.bstrVal);

	if ( rem >= len )
	{
		_tcsncat_s(adspath,MAX_PATH,varDSRoot.bstrVal, len);
	}
	else
	{
		pRoot->Release();
		VariantClear(&varDSRoot);
		return 1;
	}


     

    hr = ADsGetObject(TEXT("LDAP:"),
                      IID_IADs,
                      (void**)&pNS);
	if ( FAILED(hr) )
	{
		::CoUninitialize();
		_tprintf(TEXT("\nError in ADsGetObject"));
		return 1;
	}

    hr = pNS->QueryInterface(IID_IADsOpenDSObject,(void**)&pDSObj);

	if ( FAILED(hr) )
	{
		::CoUninitialize();
		pNS->Release();
		_tprintf(TEXT("\nError in QueryInterface"));
		return 1;
	}
    //
    // Collect the username and password and bind to the Domain using these.
    //

    if SUCCEEDED(hr) 
	{
        pNS->Release();
        _tprintf(TEXT("\nusername:"));
        _fgetts(username,sizeof(username)/sizeof(TCHAR),stdin);
		username[_tcslen(username)-1] = '\0';
        _tprintf(TEXT("\"%s\""), username);
		_tprintf(TEXT("\npassword:"));
        _fgetts(password, sizeof(password)/sizeof(TCHAR), stdin);
		password[_tcslen(password)-1] = '\0';
        hr = pDSObj->OpenDSObject(adspath,username,password,ADS_SECURE_AUTHENTICATION,(IDispatch**)&pAuth);
//.........这里部分代码省略.........
开发者ID:AbdoSalem95,项目名称:WindowsSDK7-Samples,代码行数:101,代码来源:Credentials.cpp

示例3: assert

// Read merit and version information
HRESULT MainDialog::GetMerit(IPropertyBag *pPropBag, DWORD *pdwMerit)
{
    HRESULT hr;
    IAMFilterData *pData = NULL;

    VARIANT varFilData={0};
    varFilData.vt = VT_UI1 | VT_ARRAY;
    varFilData.parray = 0;     // docs say to zero this

    BYTE *pbFilterData = 0;    // 0 if not read
    DWORD dwcbFilterDAta = 0;  // 0 if not read

    // Read compressed filter data from the property bag with a variant
    hr = pPropBag->Read(L"FilterData", &varFilData, 0);
    if (SUCCEEDED(hr))
    {
        assert(varFilData.vt == (VT_UI1 | VT_ARRAY));
        dwcbFilterDAta = varFilData.parray->rgsabound[0].cElements;

        // Access the filter data
        hr = SafeArrayAccessData(varFilData.parray, (void **)&pbFilterData);
    }

    // Get the IAMFilterData interface for parsing the filter data
	if (SUCCEEDED(hr))
	{
	    hr = m_pMapper->QueryInterface(__uuidof(IAMFilterData), (void **)&pData);
	}

    if (SUCCEEDED(hr))
    {
        BYTE *pb=0;

        // Use a helper method to parse the binary filter data.  Pass in
        // the pointer to the filter data, its size, and a buffer to fill with
        // the resulting data.  The "pb" buffer is allocated with CoTaskMemAlloc,
        // so it must be correspondingly freed by the caller.
        hr = pData->ParseFilterData(pbFilterData, dwcbFilterDAta, &pb);
        if(SUCCEEDED(hr))
        {
            REGFILTER2 *pFil = ((REGFILTER2 **)pb)[0];


            // Assign the merit value from the REGFILTER2 structure
            if (pFil)
			{
                *pdwMerit = pFil->dwMerit;

                 // Free the memory allocated by ParseFilterData
                 CoTaskMemFree(pFil);
			}
        }
    }

	if (pbFilterData)
	{
		SafeArrayUnaccessData(varFilData.parray);
		VariantClear(&varFilData);
	}

	// Release the IAMFilterData interface
	SAFE_RELEASE(pData);

    return hr;
}
开发者ID:AbdoSalem95,项目名称:WindowsSDK7-Samples,代码行数:66,代码来源:maindialog.cpp

示例4: test_mxwriter_startendelement

static void test_mxwriter_startendelement(void)
{
    static const char winehqA[] = "http://winehq.org";
    ISAXContentHandler *content;
    IMXWriter *writer;
    VARIANT dest;
    HRESULT hr;

    hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
            &IID_IMXWriter, (void**)&writer);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);

    hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
    ok(hr == S_OK, "got %08x\n", hr);

    hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
    ok(hr == S_OK, "got %08x\n", hr);

    hr = ISAXContentHandler_startDocument(content);
    ok(hr == S_OK, "got %08x\n", hr);

    /* qualified name without defined namespace */
    hr = ISAXContentHandler_startElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3, NULL);
    ok(hr == E_INVALIDARG, "got %08x\n", hr);

    hr = ISAXContentHandler_startElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3, NULL);
    ok(hr == E_INVALIDARG, "got %08x\n", hr);

    /* only local name is an error too */
    hr = ISAXContentHandler_startElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0, NULL);
    ok(hr == E_INVALIDARG, "got %08x\n", hr);

    /* only local name is an error too */
    hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_("b"), 1, NULL, 0, NULL);
    ok(hr == E_INVALIDARG, "got %08x\n", hr);

    /* all string pointers should be not null */
    hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_("b"), 1, _bstr_(""), 0, NULL);
    ok(hr == S_OK, "got %08x\n", hr);

    V_VT(&dest) = VT_EMPTY;
    hr = IMXWriter_get_output(writer, &dest);
    ok(hr == S_OK, "got %08x\n", hr);
    ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
    ok(!lstrcmpW(_bstr_("<>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
    VariantClear(&dest);

    hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1, NULL);
    ok(hr == S_OK, "got %08x\n", hr);

    V_VT(&dest) = VT_EMPTY;
    hr = IMXWriter_get_output(writer, &dest);
    ok(hr == S_OK, "got %08x\n", hr);
    ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
    ok(!lstrcmpW(_bstr_("<><b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
    VariantClear(&dest);

    hr = ISAXContentHandler_endElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3);
    ok(hr == E_INVALIDARG, "got %08x\n", hr);

    hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3);
    ok(hr == E_INVALIDARG, "got %08x\n", hr);

    /* only local name is an error too */
    hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0);
    ok(hr == E_INVALIDARG, "got %08x\n", hr);

    hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1);
    ok(hr == S_OK, "got %08x\n", hr);

    V_VT(&dest) = VT_EMPTY;
    hr = IMXWriter_get_output(writer, &dest);
    ok(hr == S_OK, "got %08x\n", hr);
    ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
    ok(!lstrcmpW(_bstr_("<><b></b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
    VariantClear(&dest);

    /* some with namespace URI */
    hr = ISAXContentHandler_startElement(content, _bstr_(winehqA), sizeof(winehqA), _bstr_(""), 0, _bstr_("nspace:c"), 8, NULL);
    ok(hr == S_OK, "got %08x\n", hr);

    hr = ISAXContentHandler_endElement(content, _bstr_(winehqA), sizeof(winehqA), _bstr_(""), 0, _bstr_("nspace:c"), 8);
    ok(hr == S_OK, "got %08x\n", hr);

    V_VT(&dest) = VT_EMPTY;
    hr = IMXWriter_get_output(writer, &dest);
    ok(hr == S_OK, "got %08x\n", hr);
    ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
    todo_wine ok(!lstrcmpW(_bstr_("<><b></b><nspace:c/>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
    VariantClear(&dest);

    /* try to end element that wasn't open */
    hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
    ok(hr == S_OK, "got %08x\n", hr);

    V_VT(&dest) = VT_EMPTY;
    hr = IMXWriter_get_output(writer, &dest);
    ok(hr == S_OK, "got %08x\n", hr);
    ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
    todo_wine ok(!lstrcmpW(_bstr_("<><b></b><nspace:c/></a>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
//.........这里部分代码省略.........
开发者ID:MichaelMcDonnell,项目名称:wine,代码行数:101,代码来源:saxreader.c

示例5: TEXT

		TEXT("雏龙"),TEXT("幼龙"),TEXT("鸭嘴龙"),TEXT("双棘龙"),
		TEXT("迅龙"),TEXT("雷龙"),TEXT("甲龙"),TEXT("角龙"),
		TEXT("剑龙"),TEXT("黄金龙"),TEXT("霸王龙"),TEXT("北海冥龙"),
		TEXT("南海狂龙"),TEXT("西海魔龙"),TEXT("东海神龙"),TEXT("中华圣龙"),
	};
	for (int i=0;i<CountArray(lScoreInfo_2);i++)
	{
		if (score<lScoreInfo_2[i]) return pszOrderName_2[i];
	}
	return pszOrderName_2[17];
}

float CLogic::AssertUserPer(LONG score)
{
	LONG lScoreInfo_2[18]=
	{
		0L,50L,100L,200L,500L,800L,1200L,2000L,3000L,5000L,8000L,12000L,15000L,18000L,25000L,40000L,60000L,
	};
	for (int i=0;i<CountArray(lScoreInfo_2);i++)
	{
		if (score<lScoreInfo_2[i]&&i!=0) 
			return (float)(100.0*(score-lScoreInfo_2[i-1])/(lScoreInfo_2[i]-lScoreInfo_2[i-1]));
		else
		if (score<lScoreInfo_2[i]&&score<0&&i==0)
			return 0.0;
	}
	return 100.0;
}

void CLogic::OpenUrl(CString url)
{
	HRESULT hr;
	IWebBrowserApp* pWBApp = NULL; // Derived from IWebBrowser
	BSTR bstrURL = NULL, bstrHeaders = NULL;
	VARIANT vFlags = {0},
		vTargetFrameName = {0},
		vPostData = {0},
		vHeaders = {0};

	if (FAILED(hr = CoInitialize(NULL)))
	{
		return;
	}

	if (FAILED(hr = CoCreateInstance(CLSID_InternetExplorer,
		NULL,
		CLSCTX_SERVER,
		IID_IWebBrowserApp,
		(LPVOID*)&pWBApp)))
	{
		if (bstrURL) SysFreeString(bstrURL);
		if (bstrHeaders) SysFreeString(bstrHeaders);
		VariantClear(&vPostData);
		if (pWBApp) pWBApp->Release();
		CoUninitialize();
		return;
	}

	bstrURL = url.AllocSysString();
	if (!bstrURL)
	{
		if (bstrURL) SysFreeString(bstrURL);
		if (bstrHeaders) SysFreeString(bstrHeaders);
		VariantClear(&vPostData);
		if (pWBApp) pWBApp->Release();
		CoUninitialize();
开发者ID:Michael-Z,项目名称:qipai-game,代码行数:66,代码来源:Logic.cpp

示例6: getclock

static unsigned int getclock(void)
{
	unsigned int clock;
#ifdef KONOHA_ON_MACOSX
	int cpu_sels[2] = { CTL_HW, HW_CPU_FREQ };
	size_t len = sizeof(int);
	sysctl(cpu_sels, 2, &clock, &len, NULL, 0);
	clock = (unsigned int) clock / (1000 * 1000);
#elif defined(KONOHA_ON_WINDOWS)
	HRESULT hres;
	hres = CoInitializeEx(0, COINIT_MULTITHREADED);
	hres = CoInitializeSecurity(
		NULL,
		-1,                          // COM authentication
		NULL,                        // Authentication services
		NULL,                        // Reserved
		RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication
		RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
		NULL,                        // Authentication info
		EOAC_NONE,                   // Additional capabilities
		NULL                         // Reserved
		);
	IWbemLocator *pLoc = NULL;
	hres = CoCreateInstance(
		CLSID_WbemLocator,
		0,
		CLSCTX_INPROC_SERVER, 
		IID_IWbemLocator, (LPVOID *) &pLoc);
	IWbemServices *pSvc = NULL;
	hres = pLoc->ConnectServer(
		_bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
		NULL,                    // User name. NULL = current user
		NULL,                    // User password. NULL = current
		0,                       // Locale. NULL indicates current
		NULL,                    // Security flags.
		0,                       // Authority (e.g. Kerberos)
		0,                       // Context object
		&pSvc                    // pointer to IWbemServices proxy
		);
	hres = CoSetProxyBlanket(
		pSvc,                        // Indicates the proxy to set
		RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx
		RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx
		NULL,                        // Server principal name
		RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx
		RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
		NULL,                        // client identity
		EOAC_NONE                    // proxy capabilities
		);
	IEnumWbemClassObject* pEnumerator = NULL;
	hres = pSvc->ExecQuery(
		bstr_t("WQL"),
		bstr_t("SELECT * FROM Win32_Processor"),
		WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
		NULL,
		&pEnumerator);
	IWbemClassObject *pclsObj;
	ULONG uReturn = 0;
	
	while (pEnumerator) {
		HRESULT hr = pEnumerator->Next(
			WBEM_INFINITE,
			1,
			&pclsObj,
			&uReturn
			);
		if (uReturn == 0) { break; }
		VARIANT vtProp;
		hr = pclsObj->Get(L"MaxClockSpeed", 0, &vtProp, 0, 0);
		clock = (unsigned int)vtProp.bstrVal;
		VariantClear(&vtProp);
		pclsObj->Release();
	}
	pSvc->Release();
	pLoc->Release();
	pEnumerator->Release();
	CoUninitialize();
#elif defined(KONOHA_ON_LINUX)
	char buf[64] = {'\0'}, *data = buf;
	const char *cpumhz = "cpu MHz";
	size_t len = strlen(cpumhz);
	FILE *fp = fopen("/proc/cpuinfo","r");
	while (fgets( buf, 64, fp ) != NULL){
		if ( strncmp(buf, cpumhz, len) == 0){
			data = strstr(buf, cpumhz);
			break;
		}
	}
	while (!isdigit(*data)) {
		data++;
	}
	clock = (unsigned int) atoi(data) / 1000;
	fclose(fp);

#else
	TODO();
#endif
	return clock;
}
开发者ID:imasahiro,项目名称:konoha-jit-deprecated,代码行数:99,代码来源:security.c

示例7: IStreamToDOMDocument

HRESULT
IStreamToDOMDocument(
    __inout     IStream           *pStream, 
    __deref_out IXMLDOMDocument2 **ppXmlDocument
    )
{
    HRESULT           hr        = S_OK;

    if (NULL == ppXmlDocument || 
        NULL == pStream)
    {
        hr = E_INVALIDARG;
    }

    if (ppXmlDocument)
    {
        *ppXmlDocument = NULL;
    }

    if ( SUCCEEDED(hr) )
    {
        hr = CoCreateInstance(CLSID_DOMDocument60,NULL,CLSCTX_INPROC_SERVER,IID_IXMLDOMDocument2,(LPVOID *)ppXmlDocument);
    }

    if( SUCCEEDED(hr) )
    {
        LARGE_INTEGER pos = {0, 0};
        hr = pStream->Seek( pos, STREAM_SEEK_SET, NULL );
    }

    //
    // Load the XML synchronously
    //
    if (SUCCEEDED(hr))
    {
        VARIANT_BOOL loadResult = 0; // Inidicates the result of loading the XML
        VARIANT      streamVar;      // Variant wrapper for the IStream to pass to load.

        VariantInit(&streamVar);
        V_VT(&streamVar) = VT_UNKNOWN;
        V_UNKNOWN(&streamVar) = pStream;
        pStream->AddRef();

        hr = (*ppXmlDocument)->load( streamVar, &loadResult );

        //
        // Check immediately to see if there was a parse error, since this
        // comes back as S_FALSE instead of E_...  
        //
        if (hr == S_FALSE)
        {
            // We could Figure out why it failed, but for now, lets just 
            // signal failure.
            hr = E_FAIL;
            
        }

        VariantClear(&streamVar);
    }

    return hr;
}
开发者ID:Ippei-Murofushi,项目名称:WindowsSDK7-Samples,代码行数:62,代码来源:util.cpp

示例8: main


//.........这里部分代码省略.........

    //Allocate Memory
    categories = (long *)calloc (numberOfCategories , sizeof(long));
    BAIL_ON_ALLOC_FAILURE(categories, calloc);

    //Take Firewall Category Ownership
    categories[0] = NET_FW_RULE_CATEGORY_FIREWALL;
    result = ArrayOfLongsToVariant(numberOfCategories, categories, &varCategories);
    
	displayName = SysAllocString(L"@RegisterFirewallSample.exe,-127");
    BAIL_ON_ALLOC_FAILURE(displayName, SysAllocString);

    hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
    if (FAILED(hr))
    {
        //COM initialize failed
        wprintf(L"CoInitialize failed: 0x%08lx\n", result);
        goto CLEANUP;
    }
    comInit = TRUE;


    hr = CoCreateInstance(__uuidof(NetFwProduct),NULL,CLSCTX_INPROC_SERVER,__uuidof(INetFwProduct),(void**)&product );

    if (FAILED(hr))
    {
        //CoCreateInstance Failed
        wprintf(L"CoCreateInstance for INetFwProduct failed: 0x%08lx\n", hr);
        goto CLEANUP;
    }

    hr = product->put_DisplayName(displayName);

    if (FAILED(hr))
    {
        //Put_displayName failed
        wprintf(L"put_DisplayName for INetFwProduct failed Error: 0x%08lx\n", hr);
        goto CLEANUP;
    }
    hr = product->put_RuleCategories(varCategories);

    if (FAILED(hr))
    {
        //Put_rulecategories failed
        wprintf(L"put_RuleCategories failed for INetFwProduct Error: 0x%08lx\n", hr);
        goto CLEANUP;
    }


    hr = CoCreateInstance(__uuidof(NetFwProducts),NULL,CLSCTX_INPROC_SERVER,__uuidof(INetFwProducts),(void**)&products );

    if (FAILED(hr))
    {
        //CoCreateInstance Failed
        wprintf(L"CoCreateInstance for INetFwProducts failed: 0x%08lx\n", hr);
        goto CLEANUP;
    }

    hr = products->Register(product, &registration);
    if (FAILED(hr))
    {
        //Failed to Register Products
        wprintf(L"Register failed: 0x%08lx\n", hr);
        goto CLEANUP;
    }			

    hr = products->get_Count( &count);
    if (FAILED(hr))
    {
        //Failed to get Count of Products
        wprintf(L"Get count failed: 0x%08lx\n", hr);
        goto CLEANUP;
    }		
    wprintf(L"INetFwProducts_Count returned %ld.\n", count);

    wprintf(L"Hit any key to unregister.\n");
    _getch();

CLEANUP:
	if (registration != NULL)
   {
      registration->Release();
   }
   if (products != NULL)
   {
      products->Release();
   }
   if (product != NULL)
   {
      product->Release();
   }
   if (comInit)
   {
      CoUninitialize();
   }
   free(categories);
   SysFreeString(displayName);
   VariantClear(&varCategories);
   return;
} 
开发者ID:Ippei-Murofushi,项目名称:WindowsSDK7-Samples,代码行数:101,代码来源:Main.cpp

示例9: VARIANTARGToCVar


//.........这里部分代码省略.........
        goto Cleanup;
    }
    // If the c style parameter is the same type as the VARIANT then we'll just
    // move the data.  Also if the c style type is a VARIANT then there's
    // nothing to convert just copy the variant to the C parameter.
    else if((V_VT(pvarg)&(VT_TYPEMASK|VT_BYREF))!=vt && (vt!=VT_VARIANT))
    {
        // If the request type isn't the same as the variant passed in then we
        // need to convert.
        VariantInit(&vargNew);
        pVArgCopy = &vargNew;

        hr = VariantChangeTypeSpecial(pVArgCopy, pvarg, vt,pSrvProvider);

        if(hr)
        {
            goto Cleanup;
        }

        *pfAlloc = (vt==VT_BSTR) || (vt==VT_UNKNOWN) || (vt==VT_DISPATCH);
    }

    // Move the variant data to C style data.
    switch(vt)
    {
    case VT_BOOL:
        // convert VT_TRUE and any other non-zero values to TRUE
        *(VARIANT_BOOL*)pv = V_BOOL(pVArgCopy);
        break;

    case VT_I2:
        *(short*)pv = V_I2(pVArgCopy);
        break;

    case VT_ERROR:
    case VT_I4:
        *(long*)pv = V_I4(pVArgCopy);
        break;

    case VT_R4:
        *(float*)pv = V_R4(pVArgCopy);
        break;

    case VT_R8:
        *(double*)pv = V_R8(pVArgCopy);
        break;

    case VT_CY:
        *(CY*)pv = V_CY(pVArgCopy);
        break;

        // All Pointer types.
    case VT_BSTR:
        if(wMaxstrlen && FormsStringLen(V_BSTR(pVArgCopy))>wMaxstrlen)
        {
            hr = FormsAllocStringLen(V_BSTR(pVArgCopy), wMaxstrlen, (BSTR*)pv);
            if(hr)
            {
                goto Cleanup;
            }

            if(*pfAlloc)
            {
                VariantClear(&vargNew);
            }
            else
            {
                *pfAlloc = TRUE;
            }

            goto Cleanup;
        }
    case VT_PTR:
    case VT_LPSTR:
    case VT_LPWSTR:
    case VT_DISPATCH:
    case VT_UNKNOWN:
        *(void**)pv = V_BYREF(pVArgCopy);
        break;

    case VT_VARIANT:
        hr = ClipVarString(pVArgCopy, (VARIANT*)pv, pfAlloc, wMaxstrlen);
        if(hr == S_FALSE)
        {
            hr = S_OK;
            // Copy entire variant to output parameter.
            *(VARIANT*)pv = *pVArgCopy;
        }

        break;

    default:
        Assert(FALSE && "Unknown type in VARIANTARGToCVar().\n");
        hr = DISP_E_TYPEMISMATCH;
        break;
    }

Cleanup:
    RRETURN(hr);
}
开发者ID:hufuman,项目名称:xindows,代码行数:101,代码来源:Variant.cpp

示例10: test_propertybag_read

static void test_propertybag_read(IPropertyBag2 *property)
{
    HRESULT hr;
    PROPBAG2 options[3] = {{0}};
    VARIANT values[3];
    HRESULT itm_hr[3] = {S_OK, S_OK, S_OK};

    /* 1. One unknown property */
    options[0].pstrName = (LPOLESTR)wszTestInvalidProperty;
    hr = IPropertyBag2_Read(property, 1, options, NULL, values, itm_hr);
    ok(hr == E_FAIL,
       "Read for an unknown property did not fail with expected code, hr=%x\n", hr);

    /* 2. One known property */
    options[0].pstrName = (LPOLESTR)wszTestProperty1;
    itm_hr[0] = E_FAIL;
    hr = IPropertyBag2_Read(property, 1, options, NULL, values, itm_hr);
    ok(hr == S_OK, "Read failed, hr=%x\n", hr);
    if (SUCCEEDED(hr))
    {
        ok(itm_hr[0] == S_OK,
           "Read failed, itm_hr[0]=%x\n", itm_hr[0]);
        ok(V_VT(&values[0]) == VT_UI1,
           "Read failed, V_VT(&values[0])=%x\n", V_VT(&values[0]));
        ok(V_UNION(&values[0], bVal) == 12,
           "Read failed, &values[0]=%i\n", V_UNION(&values[0], bVal));

        VariantClear(&values[0]);
    }

    /* 3. Two known properties */
    options[0].pstrName = (LPOLESTR)wszTestProperty1;
    options[1].pstrName = (LPOLESTR)wszTestProperty2;
    itm_hr[0] = E_FAIL;
    itm_hr[1] = E_FAIL;
    hr = IPropertyBag2_Read(property, 2, options, NULL, values, itm_hr);
    ok(hr == S_OK, "Read failed, hr=%x\n", hr);
    if (SUCCEEDED(hr))
    {
        ok(itm_hr[0] == S_OK, "Read failed, itm_hr[0]=%x\n", itm_hr[0]);
        ok(V_VT(&values[0]) == VT_UI1, "Read failed, V_VT(&values[0])=%x\n", V_VT(&values[0]));
        ok(V_UNION(&values[0], bVal) == 12, "Read failed, &values[0]=%i\n", V_UNION(&values[0], bVal));

        ok(itm_hr[1] == S_OK, "Read failed, itm_hr[1]=%x\n", itm_hr[1]);
        ok(V_VT(&values[1]) == VT_R4, "Read failed, V_VT(&values[1])=%x\n", V_VT(&values[1]));
        ok(V_UNION(&values[1], fltVal) == (float)3.14, "Read failed, &values[1]=%f\n", V_UNION(&values[1], fltVal));

        VariantClear(&values[0]);
        VariantClear(&values[1]);
    }


    /* 4. One unknown property between two valid */

    /* Exotic initializations so we can detect what is unchanged */
    itm_hr[0] = -1; itm_hr[1] = -1; itm_hr[2] = -1;
    V_VT(&values[0]) = VT_NULL;
    V_VT(&values[1]) = VT_NULL;
    V_VT(&values[2]) = VT_NULL;
    V_UNION(&values[0], bVal) = 254;
    V_UNION(&values[1], bVal) = 254;
    V_UNION(&values[2], bVal) = 254;

    options[0].pstrName = (LPOLESTR)wszTestProperty1;
    options[1].pstrName = (LPOLESTR)wszTestInvalidProperty;
    options[2].pstrName = (LPOLESTR)wszTestProperty2;

    hr = IPropertyBag2_Read(property, 3, options, NULL, values, itm_hr);
    ok(hr == E_FAIL, "Read failed, hr=%x\n", hr);
    if (hr == E_FAIL)
    {
        ok(itm_hr[0] == S_OK, "Read error code has unexpected value, itm_hr[0]=%x\n", itm_hr[0]);
        ok(itm_hr[1] == -1,   "Read error code has unexpected value, itm_hr[1]=%x\n", itm_hr[1]);
        ok(itm_hr[2] == -1,   "Read error code has unexpected value, itm_hr[2]=%x\n", itm_hr[2]);

        ok(V_VT(&values[0]) == VT_UI1,  "Read variant has unexpected type, V_VT(&values[0])=%x\n", V_VT(&values[0]));
        ok(V_VT(&values[1]) == VT_NULL, "Read variant has unexpected type, V_VT(&values[1])=%x\n", V_VT(&values[1]));
        ok(V_VT(&values[2]) == VT_NULL, "Read variant has unexpected type, V_VT(&values[2])=%x\n", V_VT(&values[2]));

        ok(V_UNION(&values[0], bVal) == 12,  "Read variant has unexpected value, V_UNION(&values[0])=%i\n", V_UNION(&values[0], bVal));
        ok(V_UNION(&values[1], bVal) == 254, "Read variant has unexpected value, V_UNION(&values[1])=%i\n", V_UNION(&values[1], bVal));
        ok(V_UNION(&values[2], bVal) == 254, "Read variant has unexpected value, V_UNION(&values[2])=%i\n", V_UNION(&values[2], bVal));
    }
}
开发者ID:GYGit,项目名称:reactos,代码行数:84,代码来源:propertybag.c

示例11: handle_xml_load

static inline HRESULT handle_xml_load(BindStatusCallback *This)
{
    static const WCHAR selectW[] = {'p','r','o','c','e','s','s','i','n','g','-',
        'i','n','s','t','r','u','c','t','i','o','n','(','\'','x','m','l',
        '-','s','t','y','l','e','s','h','e','e','t','\'',')',0};
    static const WCHAR hrefW[] = {'h','r','e','f','=',0};

    IXMLDOMDocument3 *xml = NULL, *xsl = NULL;
    IXMLDOMNode *stylesheet;
    IBindCtx *pbc;
    IMoniker *mon;
    LPOLESTR xsl_url;
    LARGE_INTEGER off;
    VARIANT_BOOL succ;
    VARIANT var;
    WCHAR *href = NULL, *p;
    BSTR bstr;
    HRESULT hres;

    off.QuadPart = 0;
    hres = IStream_Seek(This->stream, off, STREAM_SEEK_SET, NULL);
    if(FAILED(hres))
        return display_error_page(This);

    hres = DOMDocument_create(MSXML_DEFAULT, (void**)&xml);
    if(FAILED(hres))
        return display_error_page(This);

    V_VT(&var) = VT_UNKNOWN;
    V_UNKNOWN(&var) = (IUnknown*)This->stream;
    hres = IXMLDOMDocument3_load(xml, var, &succ);
    if(FAILED(hres) || !succ) {
        IXMLDOMDocument3_Release(xml);
        return display_error_page(This);
    }
    V_VT(&var) = VT_EMPTY;

    bstr = SysAllocString(selectW);
    hres = IXMLDOMDocument3_selectSingleNode(xml, bstr, &stylesheet);
    SysFreeString(bstr);
    if(hres != S_OK) {
        IXMLDOMDocument3_Release(xml);
        return display_error_page(This);
    }

    hres = IXMLDOMNode_get_nodeValue(stylesheet, &var);
    IXMLDOMNode_Release(stylesheet);
    if(SUCCEEDED(hres) && V_VT(&var)!=VT_BSTR) {
        FIXME("Variant type %d not supported\n", V_VT(&var));
        VariantClear(&var);
        hres = E_FAIL;
    }
    if(FAILED(hres)) {
        IXMLDOMDocument3_Release(xml);
        return display_error_page(This);
    }

    /* TODO: fix parsing processing instruction value */
    if((p = strstrW(V_BSTR(&var), hrefW))) {
        p += ARRAY_SIZE(hrefW) - 1;
        if(*p!='\'' && *p!='\"') p = NULL;
        else {
            href = p+1;
            p = strchrW(href, *p);
        }
    }
    if(p) {
        *p = 0;
    } else {
        VariantClear(&var);
        IXMLDOMDocument3_Release(xml);
        return display_error_page(This);
    }

    hres = CreateURLMonikerEx(This->mon, href, &mon, 0);
    VariantClear(&var);
    if(FAILED(hres)) {
        IXMLDOMDocument3_Release(xml);
        return display_error_page(This);
    }

    hres = CreateBindCtx(0, &pbc);
    if(SUCCEEDED(hres)) {
        hres = IMoniker_GetDisplayName(mon, pbc, NULL, &xsl_url);
        IMoniker_Release(mon);
        IBindCtx_Release(pbc);
    }
    if(FAILED(hres)) {
        IXMLDOMDocument3_Release(xml);
        return display_error_page(This);
    }

    V_VT(&var) = VT_BSTR;
    V_BSTR(&var) = SysAllocString(xsl_url);
    CoTaskMemFree(xsl_url);
    if(!V_BSTR(&var)) {
        IXMLDOMDocument3_Release(xml);
        return display_error_page(This);
    }

//.........这里部分代码省略.........
开发者ID:Moteesh,项目名称:reactos,代码行数:101,代码来源:xmlview.c

示例12: main

int main(int argc, char* argv[])
{
	HRESULT hr;
	IADsContainer *pCont=NULL;

	CoInitialize(NULL);
	///////////////////////////////////
	// Bind to the object
	/////////////////////////////////
	hr = ADsGetObject(L"WinNT://INDEPENDENCE", IID_IADsContainer, (void**) &pCont );
	if ( !SUCCEEDED(hr) )
	{
		return hr;
	}

	///////////////////////////////////
	// Build variant filter
	/////////////////////////////////
	LPWSTR pszFilter[] = { L"user", L"group" };
	DWORD dwNumber = sizeof( pszFilter ) /sizeof(LPWSTR);
	VARIANT var;

	hr = ADsBuildVarArrayStr( pszFilter, dwNumber, &var );

	if ( !SUCCEEDED(hr) )
	{
		pCont->Release();
		return hr;
	}

	///////////////////////////////////
	// Set the filter
	/////////////////////////////////

	hr = pCont->put_Filter(var);
	VariantClear(&var);

	if (!SUCCEEDED(hr) )
	{
		pCont->Release();
		return hr;
	}

	////////////////////////////////////////////
	// Enumerate the result
	///////////////////////////////////////////////
	IEnumVARIANT *pEnum = NULL;
	hr = ADsBuildEnumerator( pCont, &pEnum );
	pCont->Release(); // no longer needed, since we have the enumerator already
	
	if ( SUCCEEDED(hr) )
	{
		VARIANT var;
		ULONG lFetch;
		IADs *pChild=NULL;
		VariantInit(&var);
		
		while( SUCCEEDED(ADsEnumerateNext( pEnum, 1, &var, &lFetch )) && lFetch == 1 )
		{
			hr = V_DISPATCH(&var)->QueryInterface( IID_IADs, (void**) &pChild );
			if ( SUCCEEDED(hr) )
			{
				BSTR bstrName;
				BSTR bstrClass;
				// Get more information on the child classes
				pChild->get_Name(&bstrName);
				pChild->get_Class(&bstrClass);
				
				printf("%S\t\t(%S)\n", bstrName, bstrClass );
				
				// Clean-up
				SysFreeString(bstrName);
				SysFreeString(bstrClass);
				
				pChild->Release();
			}
			VariantClear(&var);
		}
	}
              
              
              if ( pEnum )
	{
		ADsFreeEnumerator( pEnum );
	}

	CoUninitialize();

	return 0;
}
开发者ID:AbdoSalem95,项目名称:WindowsSDK7-Samples,代码行数:90,代码来源:Filter.cpp

示例13: test_font_events_disp


//.........这里部分代码省略.........
    fontdesc.sCharset = 0;
    fontdesc.fItalic = FALSE;
    fontdesc.fUnderline = FALSE;
    fontdesc.fStrikethrough = FALSE;

    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
    EXPECT_HR(hr, S_OK);

    hr = IFont_QueryInterface(pFont, &IID_IConnectionPointContainer, (void **)&pCPC);
    EXPECT_HR(hr, S_OK);

    hr = IConnectionPointContainer_FindConnectionPoint(pCPC, &IID_IFontEventsDisp, &pCP);
    EXPECT_HR(hr, S_OK);
    IConnectionPointContainer_Release(pCPC);

    hr = IConnectionPoint_Advise(pCP, (IUnknown *)&FontEventsDisp, &dwCookie);
    EXPECT_HR(hr, S_OK);
    IConnectionPoint_Release(pCP);

    fonteventsdisp_invoke_called = 0;
    fonteventsdisp_invoke_arg0 = NULL;
    hr = IFont_put_Bold(pFont, TRUE);
    EXPECT_HR(hr, S_OK);

    ok(fonteventsdisp_invoke_called == 1, "IFontEventDisp::Invoke wasn't called once\n");
    SysFreeString(fonteventsdisp_invoke_arg0);

    hr = IFont_QueryInterface(pFont, &IID_IFontDisp, (void **)&pFontDisp);
    EXPECT_HR(hr, S_OK);

    for (i = 0; i < ARRAY_SIZE(font_dispids); i++)
    {
        switch (font_dispids[i].dispid)
        {
        case DISPID_FONT_NAME:
        {
            static const WCHAR arialW[] = {'A','r','i','a','l',0};
            V_VT(&vararg) = VT_BSTR;
            V_BSTR(&vararg) = SysAllocString(arialW);
            break;
        }
        case DISPID_FONT_SIZE:
            V_VT(&vararg) = VT_CY;
            S(V_CY(&vararg)).Lo = 25;
            S(V_CY(&vararg)).Hi = 0;
            break;
        case DISPID_FONT_BOLD:
            V_VT(&vararg) = VT_BOOL;
            V_BOOL(&vararg) = VARIANT_FALSE;
            break;
        case DISPID_FONT_ITALIC:
        case DISPID_FONT_UNDER:
        case DISPID_FONT_STRIKE:
            V_VT(&vararg) = VT_BOOL;
            V_BOOL(&vararg) = VARIANT_TRUE;
            break;
        case DISPID_FONT_WEIGHT:
            V_VT(&vararg) = VT_I2;
            V_I2(&vararg) = FW_BLACK;
            break;
        case DISPID_FONT_CHARSET:
            V_VT(&vararg) = VT_I2;
            V_I2(&vararg) = 1;
            break;
        default:
            ;
        }

        dispparams.cNamedArgs = 0;
        dispparams.rgdispidNamedArgs = NULL;
        dispparams.cArgs = 1;
        dispparams.rgvarg = &vararg;
        fonteventsdisp_invoke_called = 0;
        hr = IFontDisp_Invoke(pFontDisp, font_dispids[i].dispid, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
        ok(hr == S_OK, "dispid=%d, got 0x%08x\n", font_dispids[i].dispid, hr);
        ok(fonteventsdisp_invoke_called == 1, "dispid=%d, DISPID_FONT_CHANGED not called, got %d\n", font_dispids[i].dispid,
            fonteventsdisp_invoke_called);
        if (hr == S_OK)
        {
            ok(!lstrcmpW(font_dispids[i].name, fonteventsdisp_invoke_arg0), "dispid=%d, got %s, expected %s\n",
                font_dispids[i].dispid, wine_dbgstr_w(fonteventsdisp_invoke_arg0), wine_dbgstr_w(font_dispids[i].name));
            SysFreeString(fonteventsdisp_invoke_arg0);
        }
        VariantClear(&vararg);
    }

    IFontDisp_Release(pFontDisp);

    hr = IFont_Clone(pFont, &pFont2);
    EXPECT_HR(hr, S_OK);
    IFont_Release(pFont);

    /* this test shows that the notification routine isn't called again */
    fonteventsdisp_invoke_called = 0;
    hr = IFont_put_Bold(pFont2, FALSE);
    EXPECT_HR(hr, S_OK);
    ok(fonteventsdisp_invoke_called == 0, "got %d\n", fonteventsdisp_invoke_called);

    IFont_Release(pFont2);
}
开发者ID:Moteesh,项目名称:reactos,代码行数:101,代码来源:olefont.c

示例14: GetDeletedObjectsContainer

//----------------------------------------------------------------------------
//
//  GetDeletedObjectsContainer()
//
//  Binds to the Deleted Object container.
//
//----------------------------------------------------------------------------
HRESULT GetDeletedObjectsContainer(IADsContainer **ppContainer)
{
    if(NULL == ppContainer)
    {
        return E_INVALIDARG;
    }

    HRESULT hr;
    IADs *pRoot;

    *ppContainer = NULL;

    // Bind to the rootDSE object.
    hr = ADsOpenObject(L"LDAP://rootDSE",
                    NULL,
                    NULL,
                    ADS_SECURE_AUTHENTICATION,
                    IID_IADs,
                    (LPVOID*)&pRoot);
    if(SUCCEEDED(hr))
    {
        VARIANT var;
        
        VariantInit(&var);

        // Get the current domain DN.
        hr = pRoot->Get(L"defaultNamingContext", &var);
        if(SUCCEEDED(hr))
        {
            // Build the binding string.
            LPWSTR pwszFormat = L"LDAP://<WKGUID=%s,%s>";
            LPWSTR pwszPath;

            pwszPath = new WCHAR[wcslen(pwszFormat) + wcslen(GUID_DELETED_OBJECTS_CONTAINER_W) + wcslen(var.bstrVal)];
            if(NULL != pwszPath)
            {
                swprintf(pwszPath, pwszFormat, GUID_DELETED_OBJECTS_CONTAINER_W, var.bstrVal);

                // Bind to the object.
                hr = ADsOpenObject(pwszPath,
                                NULL,
                                NULL,
                                ADS_FAST_BIND | ADS_SECURE_AUTHENTICATION,
                                IID_IADsContainer,
                                (LPVOID*)ppContainer);

                delete pwszPath;
            }
            else
            {
                hr = E_OUTOFMEMORY;
            }

            VariantClear(&var);        
        }

        pRoot->Release(); 
    }

    return hr;
}
开发者ID:caidongyun,项目名称:libs,代码行数:68,代码来源:adrestore.cpp

示例15: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	//BSTR的使用
	{
		BSTR bstrA = SysAllocString(L"Hello BSTR");
		BSTR bstrB = SysAllocStringLen(bstrA, SysStringLen(bstrA));
		SysFreeString(bstrA);
		SysFreeString(bstrB);
	}

	//用VARIANT保存LONG
	{
		VARIANT var;
		VariantInit(&var);

		var.vt = VT_I4;
		var.lVal = 100;

		VariantClear(&var);

		int i = 0;
		i++;
	}

	//用VARIANT保存FLOAT
	{
		VARIANT var;
		VariantInit(&var);
		
		var.vt = VT_R4;
		var.fltVal = 1.23f;

		VariantClear(&var);
	}

	//用VARIANT保存BSTR
	{
		VARIANT var;
		VariantInit(&var);
		
		var.vt = VT_BSTR;
		var.bstrVal = SysAllocString(L"Hello World");

		VariantClear(&var);
	}

	//用VARIANT保存布尔类型
	{
		VARIANT var;
		VariantInit(&var);

		var.vt = VT_BOOL;
		var.boolVal = VARIANT_FALSE;

		VariantClear(&var);
	}

	//从VARIANT读取相应类型的值
	{
		VARIANT var;
		VariantInit(&var);

		var.vt = VT_I4;
		var.lVal = 100;

		if (var.vt == VT_I4)
		{ 
			LONG lValue = var.lVal;
		}
		else if (var.vt == VT_R4)
		{
			FLOAT fValue = var.fltVal;
		}
		else if (var.vt == VT_BSTR)
		{
			BSTR bstrValue = var.bstrVal;
		}
		else if (var.vt == VT_BOOL)
		{
			VARIANT_BOOL varbValue = var.boolVal;
		}

		VariantClear(&var);
	}

	//COM数据类型的转换,LONG转成FLOAT
	{
		VARIANT var;
		VariantInit(&var);

		var.vt = VT_I4;
		var.lVal = 100;

		VariantChangeType(&var,&var,0, VT_R4);

		if (var.vt == VT_R4)
		{
			FLOAT fValue = var.fltVal;
		}

//.........这里部分代码省略.........
开发者ID:KnowNo,项目名称:test-code-backup,代码行数:101,代码来源:Section3Demo1.cpp


注:本文中的VariantClear函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。