Ejemplo n.º 1
0
void CVisProp::SetObjFromPv(const void *pvObj, bool fShared)
{
	assert(pvObj != 0);
	assert(!IsValid() || !FPointerToObject() || PvRefCntObj() != 0);

	const CVisPropTypeInfoBase *pproptypeinfo = &PropTypeInfo();

	if (IsValid() && (IsObjReference() || IsArray()))
		ReleaseObj();
	SetFObjReference(false);

	if ((IsValid()) && (IsShared() == fShared))
	{
		pproptypeinfo->AssignObjToObj(pvObj, PvObj());
	}
	else
	{
		if (IsValid())
			ReleaseObj();

		SetFShared(fShared);
		SetFPointerToObject(fShared || !pproptypeinfo->CanCopyObjectBytes());

		if (!FPointerToObject())
		{
			SetFInitialized(true);
			pproptypeinfo->AssignObjToObj(pvObj, PvObj());
		}
		else
		{
			SetPvRefCntObj(pproptypeinfo->PvRefCntObjMakePvObj(pvObj));
			SetFInitialized(true);
		}
	}
}
Ejemplo n.º 2
0
//+---------------------------------------------------------------------------
//
// Function:  HrReleaseINetCfg
//
// Purpose:   Uninitialize INetCfg, release write lock (if present)
//            and uninitialize COM.
//
// Arguments:
//    fHasWriteLock [in]  whether write lock needs to be released.
//    pnc           [in]  pointer to INetCfg object
//
// Returns:   S_OK on success, otherwise an error code
//
// Notes:
//
HRESULT HrReleaseINetCfg(BOOL fHasWriteLock, INetCfg* pnc)
{
    HRESULT hr = S_OK;

    // uninitialize INetCfg
    hr = pnc->Uninitialize();

    // if write lock is present, unlock it
    if (SUCCEEDED(hr) && fHasWriteLock)
    {
        INetCfgLock* pncLock;

        // Get the locking interface
        hr = pnc->QueryInterface(IID_INetCfgLock,
                                 (LPVOID *)&pncLock);
        if (SUCCEEDED(hr))
        {
            hr = pncLock->ReleaseWriteLock();
            ReleaseObj(pncLock);
        }
    }

    ReleaseObj(pnc);

    CoUninitialize();

    return hr;
}
Ejemplo n.º 3
0
void CVisProp::SetObjReferenceFromPv(void *pvObj, bool fShared)
{
	if (IsValid() && IsArray())
		ReleaseObj();

	assert(!IsValid() || !FPointerToObject() || PvRefCntObj() != 0);

	if ((IsValid()) && (IsShared() == fShared) && (IsObjReference()))
	{
		((CVisRefCntObj<void *> *) PvRefCntObj())->Obj() = pvObj;
	}
	else
	{
		ReleaseObj();
		SetFShared(fShared);
		SetFPointerToObject(fShared);

		if (fShared)
		{
			SetPvRefCntObj(new CVisRefCntObj<void *>(pvObj));
		}
		else
		{
			*((void * *) (void *) &m_llData) = pvObj;
		}

		SetFObjReference(true);
		SetFInitialized(true);
	}
}
Ejemplo n.º 4
0
HRESULT CMuxVirtualMiniport::DeInstall (VOID)
{
    INetCfgClass       *pncClass;
    INetCfgClassSetup  *pncClassSetup;
    INetCfgComponent   *pnccMiniport;
    HRESULT            hr;
    LPWSTR  *pmszwRefs=NULL;
    OBO_TOKEN  *pOboToken=NULL;

    TraceMsg( L"-->CMuxVirtualMiniport::DeInstall.\n" );

    hr = m_pnc->QueryNetCfgClass( &GUID_DEVCLASS_NET,
                                  IID_INetCfgClass,
                                  (void **)&pncClass );
    if ( hr == S_OK ) {

        hr = pncClass->QueryInterface( IID_INetCfgClassSetup,
                                       (void **)&pncClassSetup );
        if ( hr == S_OK ) {

            hr = HrFindInstance( m_pnc,
                                 m_guidMiniport,
                                 &pnccMiniport );

            if ( hr == S_OK ) {

                TraceMsg( L"   Found the miniport instance to uninstall.\n" );
                
                hr = pncClassSetup->DeInstall( pnccMiniport,
                                               pOboToken,
                                               pmszwRefs );
                ReleaseObj( pnccMiniport );
            }
            else {
                TraceMsg( L"   Didn't find the miniport instance to uninstall.\n" );
            }

            ReleaseObj( pncClassSetup );
        }
        else {

            TraceMsg( L"   QueryInterface failed.\n" );
        }

        ReleaseObj( pncClass );
    }
    else {

        TraceMsg( L"   QueryNetCfgClass failed.\n" );
    }

    TraceMsg( L"<--CMuxVirtualMiniport::DeInstall(HRESULT = %x).\n",
              hr );

    return hr;
}
Ejemplo n.º 5
0
//+---------------------------------------------------------------------------
//
// Function:  HrGetNextBindingPath
//
// Purpose:   Enumerate over binding paths that start with
//            the specified component
//
// Arguments:
//    pncc              [in]  pointer to INetCfgComponent object
//    dwBindingPathType [in]  type of binding path to retrieve
//    ppncbp            [out] pointer to INetCfgBindingPath interface
//
// Returns:   S_OK on success, otherwise an error code
//
// Notes:
//
HRESULT HrGetNextBindingPath(IN  INetCfgComponent* pncc,
                             IN  DWORD  dwBindingPathType,
                             OUT INetCfgBindingPath** ppncbp)
{
    HRESULT hr=S_OK;
    INetCfgBindingPath* pncbp=NULL;

    static IEnumNetCfgBindingPath* pebp=NULL;

    *ppncbp = NULL;

    // if this is the first call in the enumeration, obtain
    // the IEnumNetCfgBindingPath interface
    if (!pebp)
    {
        INetCfgComponentBindings* pnccb=NULL;

        hr = pncc->QueryInterface(IID_INetCfgComponentBindings,
                                  (void**) &pnccb);
        if (S_OK == hr)
        {
            hr = pnccb->EnumBindingPaths(dwBindingPathType, &pebp);
            ReleaseObj(pnccb);
        }
    }

    if (S_OK == hr)
    {
        ULONG celtFetched;

        // get next binding path
        hr = pebp->Next(1, &pncbp, &celtFetched);
    }

    // on the last call (hr == S_FALSE) or on error, release resources

    if (S_OK == hr)
    {
        *ppncbp = pncbp;
    }
    else
    {
        ReleaseObj(pebp);
        pebp = NULL;
    }

    return hr;
}
Ejemplo n.º 6
0
//+---------------------------------------------------------------------------
//
// Function:  HrUninstallNetComponent
//
// Purpose:   Uninstall the specified component.
//
// Arguments:
//    pnc           [in]  pointer to INetCfg object
//    szComponentId [in]  component to uninstall
//
// Returns:   S_OK or NETCFG_S_REBOOT on success, otherwise an error code
//
// Notes:
//
HRESULT HrUninstallNetComponent(IN INetCfg* pnc, IN PCWSTR szComponentId)
{
    HRESULT hr=S_OK;
    OBO_TOKEN OboToken;
    INetCfgComponent* pncc;
    GUID guidClass;
    INetCfgClass* pncClass;
    INetCfgClassSetup* pncClassSetup;

    // OBO_TOKEN specifies the entity on whose behalf this
    // component is being uninstalld

    // set it to OBO_USER so that szComponentId will be uninstalld
    // On-Behalf-Of "user"
    ZeroMemory (&OboToken, sizeof(OboToken));
    OboToken.Type = OBO_USER;

    // see if the component is really installed
    hr = pnc->FindComponent(szComponentId, &pncc);

    if (S_OK == hr)
    {
        // yes, it is installed. obtain INetCfgClassSetup and DeInstall

        hr = pncc->GetClassGuid(&guidClass);

        if (S_OK == hr)
        {
            hr = pnc->QueryNetCfgClass(&guidClass, IID_INetCfgClass,
                                       (void**)&pncClass);
            if (SUCCEEDED(hr))
            {
                hr = pncClass->QueryInterface(IID_INetCfgClassSetup,
                                              (void**)&pncClassSetup);
                    if (SUCCEEDED(hr))
                    {
                        hr = pncClassSetup->DeInstall (pncc, &OboToken, NULL);

                        ReleaseObj (pncClassSetup);
                    }
                ReleaseObj(pncClass);
            }
        }
        ReleaseObj(pncc);
    }

    return hr;
}
Ejemplo n.º 7
0
void CVisProp::SetTypeNameAndDim(const char *szType,
		const char *szName, const CVisDim& refdim, bool fShared)
{
	CVisPropTypeInfoBase *pproptypeinfo = VisLookupPropTypeInfo(szType);

	bool fNeedToSetTypeName = false;
	if (pproptypeinfo == 0)
	{
		// The type was not recognized, so we'll use a CVisPropList
		// object to read the value.
		// LATER:  This code has not been tested.
#ifdef _DEBUG
		OutputDebugString("VisSDK Warning:  Type '");
		OutputDebugString(szType);
		OutputDebugString("' not recognized in CVisProp::SetTypeNameAndDim.\n");
#endif // _DEBUG
		pproptypeinfo = VisLookupPropTypeInfo(typeid(CVisPropList));
		assert(pproptypeinfo != 0);
		fNeedToSetTypeName = true;
	}

	ReleaseObj();
	SetKeyData(CVisPropKeyData(szName));
	SetPPropTypeInfo(pproptypeinfo);

	// Make a new object to store the value.
	SetDefaultValue(refdim, fShared);
	if (fNeedToSetTypeName)
		SetPropListTypeName(szType);
}
Ejemplo n.º 8
0
//+---------------------------------------------------------------------------
//
// Function:  HrShowBindingPathsBelowComponent
//
// Purpose:   Display all binding paths that start with
//            the specified component
//
// Arguments:
//    szComponentId [in]  id of given component (e.g. MS_TCPIP)
//
// Returns:   S_OK on success, otherwise an error code
//
// Notes:
//
HRESULT HrShowBindingPathsOfComponent(IN PCWSTR szComponentId)
{
    HRESULT hr=S_OK;
    INetCfg* pnc=NULL;
    INetCfgComponent* pncc=NULL;
    INetCfgBindingPath* pncbp=NULL;

    // get INetCfg interface
    hr = HrGetINetCfg(FALSE, &pnc);

    if (SUCCEEDED(hr))
    {
        // get INetCfgComponent for szComponentId
        hr = pnc->FindComponent(szComponentId, &pncc);
        if (S_OK == hr)
        {
            LogPrintf(_T("Binding paths starting with '%s'\n\n"),
                     szComponentId);

            while (S_OK == (hr = HrGetNextBindingPath(pncc, EBP_BELOW,
                                                      &pncbp)))
            {
                // display the binding path
                hr = HrShowBindingPath(pncbp);
                ReleaseObj(pncbp);
            }

            LogPrintf(_T("Binding paths ending with '%s'\n\n"),
                     szComponentId);

            while (S_OK == (hr = HrGetNextBindingPath(pncc, EBP_ABOVE,
                                                      &pncbp)))
            {
                // display the binding path
                hr = HrShowBindingPath(pncbp);
                ReleaseObj(pncbp);
            }

            ReleaseObj(pncc);
        }
        // release INetCfg
        hr = HrReleaseINetCfg(FALSE, pnc);
    }

    return hr;
}
Ejemplo n.º 9
0
void CVisProp::SetPvRefCntObj(void *pvRefCntObj)
{
	ReleaseObj();
	assert(pvRefCntObj != 0);
	SetFPointerToObject(true);

	*((void * *) (void *) &m_llData) = pvRefCntObj;
}
Ejemplo n.º 10
0
void CVisProp::SetPvRefCntArray(void *pvRefCntArray)
{
	ReleaseObj();
	assert(pvRefCntArray != 0);
	SetFPointerToObject(true);
	SetFArray(true);

	*((void * *) (void *) &m_llData) = pvRefCntArray;
}
Ejemplo n.º 11
0
CMuxVirtualMiniport::~CMuxVirtualMiniport(VOID)
{
    TraceMsg( L"-->CMuxVirtualMiniport::~CMuxVirtualMiniport(Destructor).\n" );

    ReleaseObj( m_pnc );

    TraceMsg( L"<--CMuxVirtualMiniport::~CMuxVirtualMiniport(Destructor).\n" );

}
Ejemplo n.º 12
0
void CXtObjPool::FreeChunk( xt_poolchk_node_t *pChunk )
{
	xt_size_t i = 0;
	void *pObj = NULL;
	for ( i=0; i<pChunk->pool_chunk.count; ++i )
	{
		pObj = (pChunk->pool_chunk.buf + m_nObjSize*i);
		ReleaseObj( pObj );
	}	
}
bool ReleaseINetCfg(BOOL bHasWriteLock, INetCfg* pNetCfg)
{
	// If write lock is present, unlock it
	if (SUCCEEDED(pNetCfg->Uninitialize()) && bHasWriteLock)
	{
		INetCfgLock* pNetCfgLock;

		// Get the locking interface
		if (SUCCEEDED(pNetCfg->QueryInterface(IID_INetCfgLock, (LPVOID *)&pNetCfgLock)))
		{
			pNetCfgLock->ReleaseWriteLock();

			ReleaseObj(pNetCfgLock);
		}
	}

	ReleaseObj(pNetCfg);

	CoUninitialize(); 

	return true;
}
Ejemplo n.º 14
0
//+---------------------------------------------------------------------------
//
// Function:  HrInstallNetComponent
//
// Purpose:   Install the specified net component
//
// Arguments:
//    pnc           [in]  pointer to INetCfg object
//    szComponentId [in]  component to install
//    pguidClass    [in]  class guid of the component
//
// Returns:   S_OK or NETCFG_S_REBOOT on success, otherwise an error code
//
// Notes:
//
HRESULT HrInstallNetComponent(IN INetCfg* pnc,
                              IN PCWSTR szComponentId,
                              IN const GUID* pguidClass)
{
    HRESULT hr=S_OK;
    OBO_TOKEN OboToken;
    INetCfgClassSetup* pncClassSetup;
    INetCfgComponent* pncc;

    // OBO_TOKEN specifies the entity on whose behalf this
    // component is being installed

    // set it to OBO_USER so that szComponentId will be installed
    // On-Behalf-Of "user"
    ZeroMemory (&OboToken, sizeof(OboToken));
    OboToken.Type = OBO_USER;

    hr = pnc->QueryNetCfgClass (pguidClass, IID_INetCfgClassSetup,
                                (void**)&pncClassSetup);
    if (SUCCEEDED(hr))
    {
        hr = pncClassSetup->Install(szComponentId,
                                    &OboToken,
                                    NSF_POSTSYSINSTALL,
                                    0,       // <upgrade-from-build-num>
                                    NULL,    // answerfile name
                                    NULL,    // answerfile section name
                                    &pncc);
        if (S_OK == hr)
        {
            // we dont want to use pncc (INetCfgComponent), release it
            ReleaseObj(pncc);
        }

        ReleaseObj(pncClassSetup);
    }

    return hr;
}
Ejemplo n.º 15
0
void CVisProp::SetDefaultValue(const CVisDim& refdim, bool fShared)
{
	ReleaseObj();
	SetFObjReference(false);
	SetFShared(fShared);
	SetFPointerToObject(fShared || !(PropTypeInfo().CanCopyObjectBytes()));
	if (refdim.CObj() > 1)
		SetPvRefCntArray(PropTypeInfo().PRefCntArrayMake(refdim));
	else if (!FPointerToObject())
		ClearValue();
	else
		SetPvRefCntObj(PropTypeInfo().PvRefCntObjMakePvObj(0));
	SetFInitialized(true);
}
Ejemplo n.º 16
0
CMuxPhysicalAdapter::~CMuxPhysicalAdapter (VOID)
{
    CMuxVirtualMiniport  *pMiniport;
    DWORD                dwMiniportCount;
    DWORD                i;


    TraceMsg( L"-->CMuxPhysicalAdapter::~CMuxPhysicalAdapter(Destructor).\n" );

    //
    // Delete all the instances representing the virtual miniports.
    // We are only deleting the class instances, not uninstalling the
    // the virtual miniports.
    //

    dwMiniportCount = m_MiniportList.ListCount();

    for (i=0; i < dwMiniportCount; ++i) {

        pMiniport = NULL;
        m_MiniportList.Remove( &pMiniport );
        delete pMiniport;
    }

    dwMiniportCount = m_MiniportsToAdd.ListCount();

    for (i=0; i < dwMiniportCount; ++i) {

        pMiniport = NULL;
        m_MiniportsToAdd.Remove( &pMiniport );
        delete pMiniport;
    }

    dwMiniportCount = m_MiniportsToRemove.ListCount();

    for (i=0; i < dwMiniportCount; ++i) {

        pMiniport = NULL;
        m_MiniportsToRemove.Remove( &pMiniport );
        delete pMiniport;
    }

    ReleaseObj( m_pnc );

    TraceMsg( L"<--CMuxPhysicalAdapter::~CMuxPhysicalAdapter(Destructor).\n" );

}
Ejemplo n.º 17
0
//+---------------------------------------------------------------------------
//
// Function:  HrIsComponentInstalled
//
// Purpose:   Find out if a component is installed
//
// Arguments:
//    szComponentId [in]  id of component to search
//
// Returns:   S_OK    if installed,
//            S_FALSE if not installed,
//            otherwise an error code
//
// Author:    kumarp 11-February-99
//
// Notes:
//
HRESULT HrIsComponentInstalled(IN PCWSTR szComponentId)
{
    HRESULT hr=S_OK;
    INetCfg* pnc;
    INetCfgComponent* pncc;

    hr = HrGetINetCfg(FALSE, &pnc);
    if (S_OK == hr)
    {
        hr = pnc->FindComponent(szComponentId, &pncc);
        if (S_OK == hr)
        {
            ReleaseObj(pncc);
        }
        (void) HrReleaseINetCfg(FALSE, pnc);
    }

    return hr;
}
Ejemplo n.º 18
0
//+---------------------------------------------------------------------------
//
// Function:  HrGetNextBindingInterface
//
// Purpose:   Enumerate over binding interfaces that constitute
//            the given binding path
//
// Arguments:
//    pncbp  [in]  pointer to INetCfgBindingPath object
//    ppncbi [out] pointer to pointer to INetCfgBindingInterface object
//
// Returns:   S_OK on success, otherwise an error code
//
// Notes:
//
HRESULT HrGetNextBindingInterface(IN  INetCfgBindingPath* pncbp,
                                  OUT INetCfgBindingInterface** ppncbi)
{
    HRESULT hr=S_OK;
    INetCfgBindingInterface* pncbi=NULL;

    static IEnumNetCfgBindingInterface* pencbi=NULL;

    *ppncbi = NULL;

    // if this is the first call in the enumeration, obtain
    // the IEnumNetCfgBindingInterface interface
    //
    if (!pencbi)
    {
        hr = pncbp->EnumBindingInterfaces(&pencbi);
    }

    if (S_OK == hr)
    {
        ULONG celtFetched;

        // get next binding interface
        hr = pencbi->Next(1, &pncbi, &celtFetched);
    }

    // on the last call (hr == S_FALSE) or on error, release resources

    if (S_OK == hr)
    {
        *ppncbi = pncbi;
    }
    else
    {
        ReleaseObj(pencbi);
        pencbi = NULL;
    }

    return hr;
}
bool ChangeNicBindingOrder()
{
	HRESULT hr = S_OK;

	INetCfg *pNetCfg = NULL; 
	INetCfgBindingPath *pNetCfgPath; 
	INetCfgComponent *pNetCfgComponent = NULL;
	INetCfgComponentBindings *pNetCfgBinding = NULL;
	INetCfgLock *pNetCfgLock = NULL;

	IEnumNetCfgBindingPath *pEnumNetCfgBindingPath = NULL;

	PWSTR szLockedBy;

	if (!SUCCEEDED(CoInitialize(NULL)))
	{
		return false;
	}

	if (S_OK != CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER, IID_INetCfg, (void**)&pNetCfg))
	{
		return false;
	}

	if (!SUCCEEDED(pNetCfg->QueryInterface(IID_INetCfgLock, (LPVOID *)&pNetCfgLock)))
	{
		return false;
	}

	static const ULONG c_cmsTimeout = 5000;
	static const WCHAR c_szSampleNetcfgApp[] = L"TapRebinder (TapRebinder.exe)";

	if (!SUCCEEDED(pNetCfgLock->AcquireWriteLock(c_cmsTimeout, c_szSampleNetcfgApp, &szLockedBy)))
	{
		wprintf(L"Could not lock INetcfg, it is already locked by '%s'", szLockedBy);

		return false;
	}

	if (!SUCCEEDED(pNetCfg->Initialize(NULL)))
	{
		if (pNetCfgLock)
		{
			pNetCfgLock->ReleaseWriteLock();
		}

		ReleaseObj(pNetCfgLock);

		return false;
	}

	ReleaseObj(pNetCfgLock);

	if (S_OK != pNetCfg->FindComponent(L"ms_tcpip", &pNetCfgComponent))
	{
		return false;
	}

	if (S_OK != pNetCfgComponent->QueryInterface(IID_INetCfgComponentBindings, (LPVOID *)&pNetCfgBinding))
	{
		return false;
	}

	if (S_OK != pNetCfgBinding->EnumBindingPaths(EBP_BELOW, &pEnumNetCfgBindingPath))
	{
		return false;
	}

	while (S_OK == hr)
	{
		hr = pEnumNetCfgBindingPath->Next(1, &pNetCfgPath, NULL);

		LPWSTR pszwPathToken;

		pNetCfgPath->GetPathToken(&pszwPathToken);

		if (wcscmp(pszwPathToken, wDeviceInstanceId) == 0)
		{
			wprintf(L"   Moving adapter to the first position: %s.\n", pszwPathToken);

			pNetCfgBinding->MoveBefore(pNetCfgPath, NULL);
			pNetCfg->Apply();

			CoTaskMemFree(pszwPathToken);

			ReleaseObj(pNetCfgPath);

			break;
		}

		CoTaskMemFree(pszwPathToken);

		ReleaseObj(pNetCfgPath);
	}

	ReleaseObj(pEnumNetCfgBindingPath);

	ReleaseObj(pNetCfgBinding);
	ReleaseObj(pNetCfgComponent);

	ReleaseINetCfg(TRUE, pNetCfg);

	return true;
} 
Ejemplo n.º 20
0
HRESULT CMuxVirtualMiniport::Install (VOID)
{
    INetCfgClass       *pncClass;
    INetCfgClassSetup  *pncClassSetup;
    INetCfgComponent   *pnccMiniport;
    HRESULT            hr;
    LPWSTR  *pmszwRefs=NULL;
    OBO_TOKEN  *pOboToken=NULL;    
    DWORD  dwSetupFlags=0;
    LPCWSTR  pszwAnswerFile=NULL;
    LPCWSTR  pszwAnswerSections=NULL; 


    TraceMsg( L"-->CMuxVirtualMiniport::Install.\n" );

    hr = m_pnc->QueryNetCfgClass( &GUID_DEVCLASS_NET,
                                  IID_INetCfgClass,
                                  (void **)&pncClass );
    if ( hr == S_OK ) {

        hr = pncClass->QueryInterface( IID_INetCfgClassSetup,
                                       (void **)&pncClassSetup );
        if ( hr == S_OK ) {
            
            hr = pncClassSetup->Install( c_szMuxMiniport,
                                         pOboToken,
                                         dwSetupFlags,
                                         0,
                                         pszwAnswerFile,
                                         pszwAnswerSections,
                                         &pnccMiniport );
            if ( hr == S_OK ) {

                hr = pnccMiniport->GetInstanceGuid( &m_guidMiniport );

                if ( hr != S_OK ) {

                    TraceMsg( L"   Failed to get the instance guid, uninstalling "
                              L" the miniport.\n" );
                    
                    pncClassSetup->DeInstall( pnccMiniport,
                                              pOboToken,
                                              pmszwRefs );
                }

                ReleaseObj( pnccMiniport );
            }
            else {

                TraceMsg( L"   Failed to install the miniport.\n" );
            }

            ReleaseObj( pncClassSetup );
        }
        else {

            TraceMsg( L"   QueryInterface failed.\n" );
        }

        ReleaseObj( pncClass );
    }
    else {

     TraceMsg( L"   QueryNetCfgClass failed.\n" );
    }

    TraceMsg( L"<--CMuxVirtualMiniport::Install(HRESULT = %x).\n",
            hr );

    return hr;
}
Ejemplo n.º 21
0
void DumpBindingPath (INetCfgBindingPath *pncbp)
{
    LPWSTR                       lpsz;
    HRESULT                      hr;

#ifdef VERBOSE_TRACE
    INetCfgComponent             *pncc;
    IEnumNetCfgBindingInterface  *pencbi;
    INetCfgBindingInterface      *pncbi;
    DWORD                        dwIndex;
    ULONG                        ulCount;  
#endif 

    #pragma prefast(suppress:26035, "&lpsz is a pointer to a buffer that receives a constant null-terminated string, see http://msdn.microsoft.com/en-us/library/ms805810.aspx")
    hr = pncbp->GetPathToken( &lpsz );

    if ( hr == S_OK ) {

        TraceMsg( L"   BindingPath: %s\n",
               lpsz );

        CoTaskMemFree( lpsz );
    }
    else {

    TraceMsg( L"   BindingPath: GetPathToken failed(HRESULT %x).\n",
           hr );
    }

#ifdef VERBOSE_TRACE

    hr = pncbp->EnumBindingInterfaces( &pencbi );

    if ( hr == S_OK ) {

        hr = pencbi ->Next( 1, &pncbi, &ulCount );

        for (dwIndex=0; hr == S_OK; dwIndex++ ) {

            hr = pncbi->GetName( &lpsz );

            if ( hr == S_OK ) {

               TraceMsg( L"   BindingInterface(%d): %s\n",
                         dwIndex, lpsz );

               CoTaskMemFree( lpsz );
            }
            else {

               TraceMsg( L"   BindingInterface(%d): GetName failed(HRESULT %x).\n",
                         dwIndex, hr );
            }

            hr = pncbi->GetUpperComponent( &pncc );

            if ( hr == S_OK ) {

                TraceMsg( L"   \tUpperComponent of the interface(%d)...\n",
                         dwIndex );

                DumpComponent( pncc );

                ReleaseObj( pncc );
            }
            else {

                TraceMsg( L"   UpperComponent: GetUpperComponent failed(HRESULT = %x).\n",
                         hr );
            }
            hr = pncbi->GetLowerComponent( &pncc );

            if ( hr == S_OK ) {

                TraceMsg( L"   \tLowerComponent of the interface(%d)...\n",
                         dwIndex );
                DumpComponent( pncc );

                ReleaseObj( pncc );
            }
            else {

                TraceMsg( L"   LowerComponent: GetLowerComponent failed(HRESULT = %x).\n",
                         hr );
            }

            ReleaseObj( pncbi );

            hr = pencbi ->Next( 1,
                                     &pncbi,
                                     &ulCount );
        }

        ReleaseObj( pencbi );
    }
    else {

        TraceMsg( L"   EnumBindingInterfaces failed, (HRESULT = %x)\n",
                  hr ); 
    }
#endif 
    return;
}
Ejemplo n.º 22
0
HRESULT HrFindInstance (INetCfg *pnc,
                        GUID &guidInstance,
                        INetCfgComponent **ppnccMiniport)
{
    IEnumNetCfgComponent  *pencc;
    INetCfgComponent      *pncc;
    GUID                  guid;
    WCHAR                 szGuid[MAX_PATH+1];
    ULONG                 ulCount;
    BOOL                  found;
    HRESULT               hr;

    TraceMsg( L"-->HrFindInstance.\n" );

    hr = pnc->EnumComponents( &GUID_DEVCLASS_NET,
                            &pencc );

    if ( hr == S_OK ) {

        StringFromGUID2( guidInstance,
                      szGuid,
                      MAX_PATH+1 );

        TraceMsg( L"  Looking for component with InstanceGuid %s\n",
               szGuid );

        hr = pencc->Next( 1,
                          &pncc,
                          &ulCount );

        for ( found=FALSE; (hr == S_OK) && (found == FALSE); ) {

            hr = pncc->GetInstanceGuid( &guid );

            if ( hr == S_OK ) {

                StringFromGUID2( guid,
                                szGuid,
                                MAX_PATH+1 );

                TraceMsg( L"  Found component with InstanceGuid %s\n",
                         szGuid );

                found = IsEqualGUID( guid,
                                    guidInstance );

                if ( found == FALSE ) {

                    ReleaseObj( pncc );

                    hr = pencc->Next( 1,
                                    &pncc,
                                    &ulCount );
                }
                else {
                    *ppnccMiniport = pncc;
                }
            }
        }   

        ReleaseObj( pencc );
    }
    else {

     TraceMsg( L"   EnumComponents failed(HRESULT = %x).\n",
               hr );
    }

    TraceMsg( L"<--HrFindInstance(HRESULT = %x).\n",
            hr );

    return hr;
}
Ejemplo n.º 23
0
CAutotest::~CAutotest()
{
	ReleaseObj();
}
Ejemplo n.º 24
0
//+---------------------------------------------------------------------------
//
// Function:  HrInstallNetComponent
//
// Purpose:   Install the specified net component
//
// Arguments:
//    pnc           [in]  pointer to INetCfg object
//    szComponentId [in]  component to install
//    pguidClass    [in]  class guid of the component
//
// Returns:   S_OK or NETCFG_S_REBOOT on success, otherwise an error code
//
// Notes:
//
HRESULT HrInstallNetComponent(IN INetCfg* pnc,
                              IN PCTSTR szComponentId,
                              IN const GUID* pguidClass)
{
    HRESULT hr=S_OK;
    OBO_TOKEN OboToken;
    INetCfgClassSetup* pncClassSetup;
    INetCfgComponent* pncc;
	WCHAR szComponentIdW[256] ;
	int cnt ;


#ifdef _MBCS

	// @hootch@
	// 
	//
	size_t cchLen;
	StringCchLength(szComponentId, 256, &cchLen);
	cnt = MultiByteToWideChar(
		CP_ACP,						// code page
		0,							// character-type options
		szComponentId,				// string to map
		cchLen, // number of bytes in string
		szComponentIdW,				// wide-character buffer
		256							// size of buffer
	);
	if(cnt == 0) {
		// error
		return S_FALSE ;
	}

#endif

    // OBO_TOKEN specifies the entity on whose behalf this
    // component is being installed

    // set it to OBO_USER so that szComponentId will be installed
    // On-Behalf-Of "user"
    ZeroMemory (&OboToken, sizeof(OboToken));
    OboToken.Type = OBO_USER;

    hr = pnc->QueryNetCfgClass (pguidClass, IID_INetCfgClassSetup,
                                (void**)&pncClassSetup);
    if (SUCCEEDED(hr))
    {

		LogPrintf(_T("QueryNetCfg succeeded.\n"));

#ifdef _MBCS
        hr = pncClassSetup->Install(szComponentIdW,
                                    &OboToken,
                                    NSF_POSTSYSINSTALL,
                                    0,       // <upgrade-from-build-num>
                                    NULL,    // answerfile name
                                    NULL,    // answerfile section name
                                    &pncc);
#else
        hr = pncClassSetup->Install(szComponentId,
                                    &OboToken,
                                    NSF_POSTSYSINSTALL,
                                    0,       // <upgrade-from-build-num>
                                    NULL,    // answerfile name
                                    NULL,    // answerfile section name
                                    &pncc);
#endif
        if (S_OK == hr)
        {

			LogPrintf(_T("ClassSetup Install succeeded.\n"));

            // we dont want to use pncc (INetCfgComponent), release it
            ReleaseObj(pncc);
        } else {

			LogPrintf(_T("ClassSetup Install failed.\n"));

        }

        ReleaseObj(pncClassSetup);
    } else {
		LogPrintf(_T("QueryNetCfg failed.\n"));
    }

    return hr;
}
Ejemplo n.º 25
0
//+---------------------------------------------------------------------------
//
// Function:  HrShowNetComponents
//
// Purpose:   Display the list of installed components of the
//            specified class.
//
// Arguments:
//    pnc        [in]  pointer to INetCfg object
//    pguidClass [in]  pointer to class GUID
//
// Returns:   S_OK on success, otherwise an error code
//
// Notes:
//
HRESULT HrShowNetComponents(IN INetCfg* pnc,
                            IN const GUID* pguidClass)
{
    HRESULT hr=S_OK;
    PWSTR szInfId;
    PWSTR szDisplayName;
    DWORD dwcc;
    INetCfgComponent* pncc;
    INetCfgClass* pncclass;
    IEnumNetCfgComponent* pencc;
    ULONG celtFetched;

    hr = pnc->QueryNetCfgClass(pguidClass, IID_INetCfgClass,
                               (void**)&pncclass);
    if (SUCCEEDED(hr))
    {
        // get IEnumNetCfgComponent so that we can enumerate
        hr = pncclass->EnumComponents(&pencc);

        ReleaseObj(pncclass);

        while (SUCCEEDED(hr) &&
               (S_OK == (hr = pencc->Next(1, &pncc, &celtFetched))))
        {
            if (pguidClass == &GUID_DEVCLASS_NET)
            {
                // we are interested only in physical netcards
                //
                hr = pncc->GetCharacteristics(&dwcc);

                if (FAILED(hr) || !(dwcc & NCF_PHYSICAL))
                {
                    hr = S_OK;
                    ReleaseObj(pncc);
                    continue;
                }
            }

            hr = pncc->GetId(&szInfId);

            if (S_OK == hr)
            {
                hr = pncc->GetDisplayName(&szDisplayName);
                if (SUCCEEDED(hr))
                {
                    LogPrintf(_T("%-26s %s\n"), szInfId, szDisplayName);

                    CoTaskMemFree(szDisplayName);
                }
                CoTaskMemFree(szInfId);
            }
            // we dont want to stop enumeration just because 1 component
            // failed either GetId or GetDisplayName, therefore reset hr to S_OK
            hr = S_OK;

            ReleaseObj(pncc);
        }
        ReleaseObj(pencc);
    }


    if (S_FALSE == hr)
    {
        hr = S_OK;
    }

    return hr;
}
Ejemplo n.º 26
0
//+---------------------------------------------------------------------------
//
// Function:  HrShowBindingPath
//
// Purpose:   Display components of a binding path in the format:
//            foo -> bar -> adapter
//
// Arguments:
//    pncbp [in]  pointer to INetCfgBindingPath object
//
// Returns:   S_OK on success, otherwise an error code
//
// Notes:
//
HRESULT HrShowBindingPath(IN INetCfgBindingPath* pncbp)
{
    HRESULT hr=S_OK;
    INetCfgBindingInterface* pncbi;
    INetCfgComponent* pncc = NULL;
    BOOL fFirstInterface=TRUE;
    PWSTR szComponentId;

    while (SUCCEEDED(hr) &&
           (S_OK == (hr = HrGetNextBindingInterface(pncbp, &pncbi))))
    {
        // for the first (top) interface we need to get the upper as well as
        // the lower component. for other interfaces we need to get
        // only the lower component.

        if (fFirstInterface)
        {
            fFirstInterface = FALSE;
            hr = pncbi->GetUpperComponent(&pncc);
            if (SUCCEEDED(hr))
            {
                // get id so that we can display it
                //
                // for readability of the output, we have used the GetId
                // function. For non net class components, this
                // does not pose a problem. In case of net class components,
                // there may be more than one net adapters of the same type
                // in which case, GetId will return the same string. This will
                // make it impossible to distinguish between two binding
                // paths that end in two distinct identical cards. In such case,
                // it may be better to use the GetInstanceGuid function because
                // it will return unique GUID for each instance of an adapter.
                //
                hr = pncc->GetId(&szComponentId);
                ReleaseObj(pncc);
                if (SUCCEEDED(hr))
                {
                    LogPrintf(szComponentId);
                    CoTaskMemFree(szComponentId);
                }
            }
        }

        if (SUCCEEDED(hr))
        {
            hr = pncbi->GetLowerComponent(&pncc);
            if (SUCCEEDED(hr))
            {
                hr = pncc->GetId(&szComponentId);
                if (SUCCEEDED(hr))
                {
                    LogPrintf(_T(" -> %s"), szComponentId);
                    CoTaskMemFree(szComponentId);
                }
                ReleaseObj(pncc);
            }
        }
        ReleaseObj(pncbi);
    }

	LogPrintf(_T("\n"));

    if (hr == S_FALSE)
    {
        hr = S_OK;
    }

    return hr;
}
Ejemplo n.º 27
0
void CVisProp::Assign(
		const CVisProp& refprop)
{
	bool fSameTypes = (m_pproptypeinfo == refprop.m_pproptypeinfo);
	m_pproptypeinfo = refprop.m_pproptypeinfo;
	m_propkeydata = refprop.m_propkeydata;
	m_fPrint = refprop.m_fPrint;

	if (!refprop.IsValid())
	{
		ReleaseObj();
	}
	else if ((IsValid()) && (IsArray()) && (!IsShared()) && (refprop.IsArray())
			&& (!refprop.IsShared()) && (Dim() == refprop.Dim()) && (fSameTypes))
	{
		// Special case:  Just copy the array values (without reallocating).
		CopyArrayElements(refprop.PRefCntArray()->PvObjFirst());
	}
	else
	{
		assert(m_pproptypeinfo != 0);

		if ((IsValid()) && (IsArray()))
			ReleaseObj();

		if (refprop.IsArray())
		{
			ReleaseObj();
			SetFObjReference(refprop.IsObjReference());
			if (refprop.IsShared())
			{
				SetPvRefCntArray(refprop.PRefCntArray());
				// Need to set m_fInitialized to true here so that we can
				// assert(IsValid()) in the call to PRefCntArray().
				SetFInitialized(true);
				PropTypeInfo().AddRefPvRefCntArray(PRefCntArray());
			}
			else
			{
				SetObjFromPv(refprop.PRefCntArray()->PvObjFirst(),
						false, refprop.Dim());
			}
		}
		else if (refprop.IsObjReference())
		{
			ReleaseObj();
			SetFObjReference(true);
			if (refprop.IsShared())
			{
				SetPvRefCntObj(refprop.PvRefCntObj());
				// Need to set m_fInitialized to true here so that we can
				// assert(IsValid()) in the call to PvRefCntObj().
				SetFInitialized(true);
				((CVisRefCntObj<void *> *) PvRefCntObj())->AddRef();
			}
			else
			{
				SetFPointerToObject(false);
				*((void * *) (void *) &m_llData) = refprop.PvObj();
			}
		}
		else
		{
			m_fObjReference = false;
			if (!refprop.FPointerToObject())
			{
				ReleaseObj();
				SetFPointerToObject(false);
//				m_pproptypeinfo->AssignObjToObj(refprop.PvObj(), PvObj());
				m_pproptypeinfo->AssignObjToObj(refprop.PvObj(), (void *) &m_llData);
			}
			else if (!refprop.IsShared())
			{
				if (!IsValid())
				{
					SetPvRefCntObj(m_pproptypeinfo->ClonePvRefCntObj(refprop.PvRefCntObj()));
				}
				else
				{
					assert(FPointerToObject());
					m_pproptypeinfo->AssignObjToObj(refprop.PvObj(), PvObj());
				}
			}
			else
			{
				SetPvRefCntObj(refprop.PvRefCntObj());
				// Need to set m_fInitialized to true here so that we can
				// assert(IsValid()) in the call to PvRefCntObj().
				SetFInitialized(true);
				m_pproptypeinfo->AddRefPvRefCntObj(PvRefCntObj());
			}
		}

		SetFShared(refprop.IsShared());
		SetFInitialized(true);
	}
}
Ejemplo n.º 28
0
HRESULT CMuxPhysicalAdapter::ApplyPnpChanges(
    INetCfgPnpReconfigCallback *pfCallback,
    ConfigAction eApplyAction)
{
    CMuxVirtualMiniport     *pMiniport = NULL;
    GUID                    guidMiniport;
    DWORD                   dwMiniportCount;
    DWORD                   i;
    HRESULT                 hr;

#ifdef CUSTOM_EVENTS
    LPWSTR                  lpDevice;
    WCHAR                   szMiniportGuid[MAX_PATH+1];
    DWORD                   dwBytes;
    INetCfgComponent        *pncc;
    LPWSTR                  lpszBindName;
    PNOTIFY_CUSTOM_EVENT       lppnpEvent;
#endif

    UNREFERENCED_PARAMETER(eApplyAction);
    TraceMsg( L"-->CMuxPhysicalAdapter::ApplyPnpChanges.\n" );

#ifdef CUSTOM_EVENTS

    //
    // Find the instance of the adapter to get its bindname.
    //

    hr = HrFindInstance( m_pnc,
                         m_guidAdapter,
                         &pncc );

    if ( hr == S_OK ) {

        hr = pncc->GetBindName( &lpszBindName );

        if ( hr != S_OK ) {
            TraceMsg( L"  GetBindName failed.(HRESULT = %x). PnP changes will not "
                      L"be applied and the driver will not be notified.\n",
                      hr );
        }

        ReleaseObj( pncc );
    }
    else {
        TraceMsg( L"  PnP changes will not "
                  L"be applied and the driver will not be notified.\n",
                  hr );
    }

#endif

    dwMiniportCount = m_MiniportsToAdd.ListCount();

    TraceMsg( L"   Applying PnP changes to %d new miniports.\n",
              dwMiniportCount );

    for (i=0; i < dwMiniportCount; ++i) {

        pMiniport = NULL;
        m_MiniportsToAdd.Remove( &pMiniport );

        pMiniport->GetMiniportGUID( &guidMiniport );

        m_MiniportList.Insert( pMiniport,
                               guidMiniport );

        //
        // Do miniport specific Pnp Changes when they are added.
        //

        hr = pMiniport->ApplyPnpChanges( pfCallback,
                                         eActAdd );
        if( hr != S_OK) {
            // you may do something
        }

#ifdef CUSTOM_EVENTS


        //
        // Notify the driver that one or more virtual miniports have been added.
        //

        StringFromGUID2( guidMiniport,
                         szMiniportGuid,
                         MAX_PATH+1 );
        lpDevice = AddDevicePrefix( szMiniportGuid );

        if ( lpDevice ) {

            dwBytes = sizeof(NOTIFY_CUSTOM_EVENT) +
                      ((wcslen(lpDevice) + 1) * sizeof(WCHAR));

            lppnpEvent = (PNOTIFY_CUSTOM_EVENT)malloc( dwBytes );

            if ( lppnpEvent ) {

                lppnpEvent->uSignature = NOTIFY_SIGNATURE;
                lppnpEvent->uEvent = MUX_CUSTOM_EVENT;
                wcscpy( lppnpEvent->szMiniport,
                        lpDevice );

                hr = pfCallback->SendPnpReconfig( NCRL_NDIS,
                                                  c_szMuxService,
                                                  lpszBindName,
                                                  (PVOID)lppnpEvent,
                                                  dwBytes );

                TraceMsg( L"   INetCfgPnpReconfigCallback->SendPnpReconfig returned "
                          L"%#x.\n",
                          hr );

                if ( hr != S_OK ) {

                    TraceMsg( L"   Failed to apply Pnp changes, miniport(%d).\n",
                              i );

                }

                free( lppnpEvent );
            }
            free( lpDevice );
        }
#endif
    }

    dwMiniportCount = m_MiniportsToRemove.ListCount();

    TraceMsg( L"   Applying PnP changes to %d removed miniports.\n",
              dwMiniportCount );

    for (i=0; i < dwMiniportCount; ++i) {

        pMiniport = NULL;
        m_MiniportsToRemove.Remove( &pMiniport );

        pMiniport->GetMiniportGUID( &guidMiniport );

        //
        // Do miniport specific Pnp Changes when they are uninstalled.
        //

        hr = pMiniport->ApplyPnpChanges( pfCallback,
                                         eActRemove );
        if( hr != S_OK) {
            // you may do something
        }

        delete pMiniport;

#ifdef CUSTOM_EVENTS

        //
        // Notify the driver that one or more virtual miniports have been
        // uninstalled.
        //
        // We can't notify the driver in case the adapter or the protocol is
        // being uninstalled because the binding handle doesn't exist.
        //

        if ( eApplyAction != eActRemove ) {

            StringFromGUID2( guidMiniport,
                             szMiniportGuid,
                             MAX_PATH+1 );
            lpDevice = AddDevicePrefix( szMiniportGuid );

            if ( lpDevice ) {

                dwBytes = sizeof(NOTIFY_CUSTOM_EVENT) +
                          ((wcslen(lpDevice) + 1) * sizeof(WCHAR));

                lppnpEvent = (PNOTIFY_CUSTOM_EVENT)malloc( dwBytes );

                if ( lppnpEvent ) {

                    lppnpEvent->uSignature = NOTIFY_SIGNATURE;
                    lppnpEvent->uEvent = MUX_CUSTOM_EVENT;
                    wcscpy( lppnpEvent->szMiniport,
                            lpDevice );

                    hr = pfCallback->SendPnpReconfig( NCRL_NDIS,
                                                      c_szMuxService,
                                                      lpszBindName,
                                                      (PVOID)lppnpEvent,
                                                      dwBytes );
                    TraceMsg( L"   INetCfgPnpReconfigCallback->SendPnpReconfig returned "
                              L"%#x.\n",
                              hr );

                    if ( hr != S_OK ) {

                        TraceMsg( L"   Failed to apply Pnp changes, miniport(%d).\n",
                                  i );

                    }

                    free( lppnpEvent );
                }

                free( lpDevice );
            }
        }
#endif

    }

#ifdef CUSTOM_EVENTS
    CoTaskMemFree( lpszBindName );
#endif

    TraceMsg( L"<--CMuxPhysicalAdapter::ApplyPnpChanges(HRESULT = %x).\n",
              S_OK );

    return S_OK;
}
Ejemplo n.º 29
0
//+---------------------------------------------------------------------------
//
// Function:  HrGetINetCfg
//
// Purpose:   Initialize COM, create and initialize INetCfg.
//            Obtain write lock if indicated.
//
// Arguments:
//    fGetWriteLock [in]  whether to get write lock
//    ppnc          [in]  pointer to pointer to INetCfg object
//
// Returns:   S_OK on success, otherwise an error code
//
// Notes:
//
HRESULT HrGetINetCfg(IN BOOL fGetWriteLock,
                     INetCfg** ppnc)
{
    HRESULT hr=S_OK;

    // Initialize the output parameters.
    *ppnc = NULL;

    // initialize COM
    hr = CoInitializeEx(NULL,
                        COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED );

    if (SUCCEEDED(hr))
    {
        // Create the object implementing INetCfg.
        //
        INetCfg* pnc;
        hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER,
                              IID_INetCfg, (void**)&pnc);
        if (SUCCEEDED(hr))
        {
            INetCfgLock * pncLock = NULL;
            if (fGetWriteLock)
            {
                // Get the locking interface
                hr = pnc->QueryInterface(IID_INetCfgLock,
                                         (LPVOID *)&pncLock);
                if (SUCCEEDED(hr))
                {
                    // Attempt to lock the INetCfg for read/write
                    static const ULONG c_cmsTimeout = 15000;
                    static const WCHAR c_szSampleNetcfgApp[] =
                        L"Sample Netcfg Application (netcfg.exe)";
                    PWSTR szLockedBy;

                    hr = pncLock->AcquireWriteLock(c_cmsTimeout,
                                                   c_szSampleNetcfgApp,
                                                   &szLockedBy);
                    if (S_FALSE == hr)
                    {
                        hr = NETCFG_E_NO_WRITE_LOCK;
                    }
                }
            }

            if (SUCCEEDED(hr))
            {
                // Initialize the INetCfg object.
                //
                hr = pnc->Initialize(NULL);
                if (SUCCEEDED(hr))
                {
                    *ppnc = pnc;
                    pnc->AddRef();
                }
                else
                {
                    // initialize failed, if obtained lock, release it
                    if (pncLock)
                    {
                        pncLock->ReleaseWriteLock();
                    }
                }
            }
            ReleaseObj(pncLock);
            ReleaseObj(pnc);
        }

        if (FAILED(hr))
        {
            CoUninitialize();
        }
    }

    return hr;
}