【问题标题】:MSMQ (COM) Check if private queue existsMSMQ (COM) 检查私有队列是否存在
【发布时间】:2014-05-06 22:10:37
【问题描述】:

我可以使用 Delphi7 中的 MSMQ COM 组件检查我的 PC 上是否存在 private 队列,具有路径或格式名称吗? 我读到了LookupQueue,但它似乎只适用于公共队列,我需要一个我不知道的 GUID。欢迎任何其他替代方案或正确使用LookupQueue 示例。

【问题讨论】:

    标签: delphi com delphi-7 msmq


    【解决方案1】:

    这是我不久前使用的一段代码。

    function GetAllPrivateQueues( const aMachine : WideString; aStrL : TStrings) : HRESULT;
    // Returns a list of all private queues of a given machine
    type PPWideChar = ^PWideChar;
    var props : MQMGMTPROPS;
        keys  : array[0..0] of MGMTPROPID;
        vals  : array[0..0] of MQPROPVARIANT;
        ppws  : PPWideChar;
        i     : Integer;
    begin
      // Init Props
      props.cProp    := 0;
      props.aPropID  := @keys;
      props.aPropVar := @vals;
      props.aStatus  := nil;
    
      // we want private queues
      ASSERT( props.cProp < (SizeOf(keys) / SizeOf(PROPID)));
      keys[props.cProp]         := PROPID_MGMT_MSMQ_PRIVATEQ;
      vals[props.cProp].vt      := VT_NULL;
      Inc(props.cProp);
    
      // MQMgmtGetInfo() has what we want, requires MSMQ 3.0
      result := MQMgmtGetInfo( PWideChar(aMachine), MO_MACHINE_TOKEN, props);
      if FAILED(result) then Exit;
    
      // collect the names
      // cast required this way, the data type in ActiveX.pas (D7) is incorrect
      ppws := PPWideChar(vals[0].calpwstr.pElems);
      for i := 0 to vals[0].calpwstr.cElems-1 do begin
        aStrL.Add( ppws^);
        MQFreeMemory( ppws^);
        Inc(ppws);
      end;
    end;
    

    请注意,它可能需要一些调整,具体取决于您的确切环境和/或 Delphi 版本。我自己做了 Windows 标题翻译,因为当时我(也)需要它用于 D7。 Windows SDK中提供了头文件,相关起点为mq.h

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-20
      • 1970-01-01
      • 2014-12-01
      • 2011-09-23
      • 2014-06-18
      • 1970-01-01
      • 2011-03-24
      • 1970-01-01
      相关资源
      最近更新 更多