⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 query.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft shared
// source or premium shared source license agreement under which you licensed
// this source code. If you did not accept the terms of the license agreement,
// you are not authorized to use this source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the SOURCE.RTF on your install media or the root of your tools installation.
// THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//=--------------------------------------------------------------------------=
// MSMQQueryObj.Cpp
//=--------------------------------------------------------------------------=
//
// the MSMQQuery object
//
//
#include "IPServer.H"

#include "LocalObj.H"
#include "Query.H"

#include "limits.h"   // for UINT_MAX
//#include "mq.h"
//#include "lookupx.h"  // from mqadminx

// for ASSERT and FAIL
//
SZTHISFILE

// debug...
#define new DEBUG_NEW
#if DEBUG
#define SysAllocString DebSysAllocString
#define SysReAllocString DebSysReAllocString
#define SysFreeString DebSysFreeString
#endif // DEBUG


// Helper: PrOfRel:
//  Map RELOPS enumerator to PR enumerator.
//
UINT PrOfRel(RELOPS rel)
{
    UINT uPr = UINT_MAX;

    // UNDONE: must as well be a hard-wired array...

    switch (rel) {
    case REL_NOP:
      // maps to default
      break;
    case REL_EQ:
      uPr = PREQ;
      break;
    case REL_NEQ:
      uPr = PRNE;
      break;
    case REL_LT:
      uPr = PRLT;
      break;
    case REL_GT:
      uPr = PRGT;
      break;
    case REL_LE:
      uPr = PRLE;
      break;
    case REL_GE:
      uPr = PRGE;
      break;
    default:
      ASSERT(0, L"bad enumerator.");
      break;
    } // switch
    return uPr;
}


// Helper: PrOfVariant
//  Maps VARIANT to PR enumerator.
//  Returns UINT_MAX if out of bounds or illegal.
//
UINT PrOfVar(VARIANT *pvarRel)
{
    UINT uPr = UINT_MAX;
    HRESULT hresult;

    // ensure we can coerce rel to UINT.
    hresult = VariantChangeType(pvarRel, 
                                pvarRel, 
                                0, 
                                VT_I4);
    if (SUCCEEDED(hresult)) {
      uPr = PrOfRel((RELOPS)pvarRel->lVal);
    }
    return uPr; // == UINT_MAX ? PREQ : uPr;
}


//=--------------------------------------------------------------------------=
// CMSMQQuery::Create
//=--------------------------------------------------------------------------=
// creates a new MSMQQuery object.
//
// Parameters:
//    IUnknown *        - [in] controlling unkonwn
//
// Output:
//    IUnknown *        - new object.
//
// Notes:
//
IUnknown *CMSMQQuery::Create
(
    IUnknown *pUnkOuter
)
{
    // make sure we return the private unknown so that we support aggegation
    // correctly!
    //
    CMSMQQuery *pNew = new CMSMQQuery(pUnkOuter);
    return pNew ? pNew->PrivateUnknown() : NULL;
}

//=--------------------------------------------------------------------------=
// CMSMQQuery::CMSMQQuery
//=--------------------------------------------------------------------------=
// create the object and initialize the refcount
//
// Parameters:
//    IUnknown *    - [in] controlling unknown
//
// Notes:
//
#pragma warning(disable:4355)  // using 'this' in constructor
CMSMQQuery::CMSMQQuery
(
    IUnknown *pUnkOuter
)
: CAutomationObject(pUnkOuter, OBJECT_TYPE_OBJMQQUERY, (void *)this)
{

    // TODO: initialize anything here
    // m_pguidServiceType = new GUID(GUID_NULL);
    // m_pguidQueue = new GUID(GUID_NULL);
    // m_bstrLabel = NULL;
}
#pragma warning(default:4355)  // using 'this' in constructor

//=--------------------------------------------------------------------------=
// CMSMQQuery::CMSMQQuery
//=--------------------------------------------------------------------------=
// "We all labour against our own cure, for death is the cure of all diseases"
//    - Sir Thomas Browne (1605 - 82)
//
// Notes:
//
CMSMQQuery::~CMSMQQuery ()
{
    // TODO: clean up anything here.
    // delete m_pguidServiceType;
    // delete m_pguidQueue;
    // SysFreeString(m_bstrLabel);
} 

//=--------------------------------------------------------------------------=
// CMSMQQuery::InternalQueryInterface
//=--------------------------------------------------------------------------=
// the controlling unknown will call this for us in the case where they're
// looking for a specific interface.
//
// Parameters:
//    REFIID        - [in]  interface they want
//    void **       - [out] where they want to put the resulting object ptr.
//
// Output:
//    HRESULT       - S_OK, E_NOINTERFACE
//
// Notes:
//
HRESULT CMSMQQuery::InternalQueryInterface
(
    REFIID riid,
    void **ppvObjOut
)
{
    CHECK_POINTER(ppvObjOut);

    // we support IMSMQQuery and ISupportErrorInfo
    //
    if (DO_GUIDS_MATCH(riid, IID_IMSMQQuery)) {
        *ppvObjOut = (void *)(IMSMQQuery *)this;
        AddRef();
        return S_OK;
    } else if (DO_GUIDS_MATCH(riid, IID_ISupportErrorInfo)) {
        *ppvObjOut = (void *)(ISupportErrorInfo *)this;
        AddRef();
        return S_OK;
    }

    // call the super-class version and see if it can oblige.
    //
    return CAutomationObject::InternalQueryInterface(riid, ppvObjOut);
}



// TODO: implement your interface methods and property exchange functions
//       here.


// helper: If this a valid non-NOP implicit or explicit REL?
BOOL IsValidRel(VARIANT *prel)
{
    // we return TRUE only if:
    //  a REL is supplied and it's not REL_NOP
    //   or a REL isn't supplied at all
    //  
    return ((prel->vt != VT_ERROR) && (PrOfVar(prel) != UINT_MAX)) ||
            (prel->vt == VT_ERROR);
}


//=--------------------------------------------------------------------------=
// CMSMQQuery::CreateRestriction
//=--------------------------------------------------------------------------=
//  Creates a restriction for MQLocateBegin.
//  NOTE: the hungarian lies here -- all params are formally
//   VARIANTs but we use their real underlying typetag.
//
// Parameters:
// [IN] varguidQueue 
// [IN] varGuidServiceType 
// [IN] strLabel 
// [IN] strPathName 
// [IN] relServiceType 
// [IN] relLabel 
// [OUT] prestriction
// [OUT] pcolumnset
//
// Output:
//    HRESULT       - S_OK, E_NOINTERFACE
//
// Notes:
//
HRESULT CMSMQQuery::CreateRestriction(
    VARIANT *pstrGuidQueue, 
    VARIANT *pstrGuidServiceType, 
    VARIANT *pstrLabel, 
    VARIANT *pdateCreateTime,
    VARIANT *pdateModifyTime,
    VARIANT *prelServiceType, 
    VARIANT *prelLabel, 
    VARIANT *prelCreateTime,
    VARIANT *prelModifyTime,
    MQRESTRICTION *prestriction,
    MQCOLUMNSET *pcolumnset)
{
return E_NOTIMPL;
#if 0 // not implemented in CE
    UINT cRestriction = 0, iProp, cCol, uPr;
    MQPROPERTYRESTRICTION *rgPropertyRestriction;
    BSTR bstrTemp = NULL;
    ULONG ulTime;
    CLSID *pguidQueue = NULL;
    CLSID *pguidServiceType = NULL;
    HRESULT hresult = NOERROR;

    IfNullRet(pguidQueue = new GUID(GUID_NULL));
    IfNullFail(pguidServiceType = new GUID(GUID_NULL));

    // Count optional params
    if (pstrGuidQueue->vt != VT_ERROR) {
      cRestriction++;
    }
    if (pstrGuidServiceType->vt != VT_ERROR) {

      // ignore if rel is NOP:
      if (IsValidRel(prelServiceType)) {
        cRestriction++;
      }
    }
    if (pstrLabel->vt != VT_ERROR) {

      // ignore if rel is NOP:
      if (IsValidRel(prelLabel)) {
        cRestriction++;
      }
    }
    if (pdateCreateTime->vt != VT_ERROR) {

      // ignore if rel is NOP:
      if (IsValidRel(prelCreateTime)) {
        cRestriction++;
      }
    }
    if (pdateModifyTime->vt != VT_ERROR) {

      // ignore if rel is NOP:
      if (IsValidRel(prelModifyTime)) {
        cRestriction++;
      }
    }
    rgPropertyRestriction = new MQPROPERTYRESTRICTION[cRestriction];

    // setup OUT param
    prestriction->cRes = cRestriction;
    prestriction->paPropRes = rgPropertyRestriction;

    // populate...
    iProp = 0;
    if (pstrGuidQueue->vt != VT_ERROR) {
      rgPropertyRestriction[iProp].prval.vt = VT_ERROR;
      if ((bstrTemp = GetBstr(pstrGuidQueue)) == NULL) {
        IfFailRet(hresult = E_INVALIDARG);
      }
      IfFailGo(CLSIDFromString(bstrTemp, pguidQueue));
      IfNullFail(rgPropertyRestriction[iProp].prval.puuid = 
        new CLSID(*pguidQueue));
      rgPropertyRestriction[iProp].rel = PREQ;
      rgPropertyRestriction[iProp].prop = PROPID_Q_INSTANCE;
      rgPropertyRestriction[iProp].prval.vt = VT_CLSID;
      iProp++;
    }
    if (pstrGuidServiceType->vt != VT_ERROR) {
      rgPropertyRestriction[iProp].prval.vt = VT_ERROR;
      if ((bstrTemp = GetBstr(pstrGuidServiceType)) == NULL) {
        IfFailGo(hresult = E_INVALIDARG);
      }
      if (IsValidRel(prelServiceType)) {
        IfFailGo(CLSIDFromString(bstrTemp, pguidServiceType));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -