RTSystemQueryDmiString-win.cpp revision 760446f710619a9daa6cedc7f0601f49e4ea3442
/* $Id$ */
/** @file
* IPRT - RTSystemQueryDmiString, windows ring-3.
*/
/*
* Copyright (C) 2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define _WIN32_DCOM
#include <Windows.h>
#include <WbemCli.h>
/**
* Initialize COM.
*
* @returns COM status code.
*/
static HRESULT rtSystemDmiWinInitialize(void)
{
{
-1, /* COM authentication. */
NULL, /* Which 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. */
if (hrc == RPC_E_TOO_LATE)
}
return hrc;
}
/**
* Undo what rtSystemDmiWinInitialize did.
*/
static void rtSystemDmiWinTerminate(void)
{
}
/**
* Convert a UTF-8 string to a BSTR.
*
* @returns BSTR pointer.
* @param psz The UTF-8 string.
*/
{
if (RT_FAILURE(rc))
return NULL;
return pBStr;
}
/**
* Connect to the DMI server.
*
* @returns COM status code.
* @param pLocator The locator.
* @param pszServer The server name.
* @param ppServices Where to return the services interface.
*/
static HRESULT rtSystemDmiWinConnectToServer(IWbemLocator *pLocator, const char *pszServer, IWbemServices **ppServices)
{
if (!pBStrServer)
return E_OUTOFMEMORY;
NULL,
NULL,
0,
NULL,
0,
0,
{
NULL,
NULL,
(*ppServices)->Release();
}
return hrc;
}
{
*pszBuf = '\0';
AssertReturn(enmString > RTSYSDMISTR_INVALID && enmString < RTSYSDMISTR_END, VERR_INVALID_PARAMETER);
/*
* Figure the property name before we start.
*/
const char *pszPropName;
switch (enmString)
{
default:
return VERR_NOT_SUPPORTED;
}
/*
* Before we do anything with COM, we have to initalize it.
*/
return VERR_NOT_SUPPORTED;
int rc = VERR_NOT_SUPPORTED;
if (pBstrPropName)
{
/*
* Instantiate the IWbemLocator, whatever that is and connect to the
* DMI serve.
*/
0,
{
{
/*
* Enumerate whatever it is we're looking at and try get
* the desired property.
*/
if (pBstrFilter)
{
{
do
{
&& cObjRet >= 1)
{
VariantInit(&Var);
{
/*
* Convert the BSTR to UTF-8 and copy it
* into the return buffer.
*/
char *pszValue;
if (RT_SUCCESS(rc))
{
hrc = WBEM_S_FALSE;
}
}
VariantClear(&Var);
}
} while (hrc != WBEM_S_FALSE);
}
}
else
hrc = E_OUTOFMEMORY;
}
}
}
else
hrc = E_OUTOFMEMORY;
return rc;
}