2012-06-14 79 views
0

我定義以下SCPD文檔,我的UPnP設備:如何將參數傳遞給IUPnPService.InvokeAction?

<?xml version="1.0"?> 
<scpd xmlns="urn:schemas-upnp-org:service-1-0" > 
    <specVersion> 
    <major>1</major> 
    <minor>0</minor> 
    </specVersion> 
    <actionList> 
    <action> 
     <name>Echo</name> 
     <argumentList> 
     <argument> 
      <name>InText</name> 
      <relatedStateVariable>Text</relatedStateVariable> 
      <direction>in</direction> 
     </argument> 
     <argument> 
      <name>ReturnText</name> 
      <relatedStateVariable>Text</relatedStateVariable> 
      <direction>out</direction> 
     </argument> 
     </argumentList> 
    </action> 
    </actionList> 
    <serviceStateTable> 
    <stateVariable sendEvents="no"> 
     <name>Text</name> 
     <dataType>string</dataType> 
    </stateVariable> 
    </serviceStateTable> 
</scpd> 

我註冊了我的UPnP設備了。我也能夠檢索我的UPnPDevice。我將如何調用SCPD文檔中定義的echo操作?

調用動作應該是這樣的代碼:

var o: IUPnPDeviceFinder; 
    d: IUPnPDevice; 
    s: IUPnPService; 
    E: IEnumVARIANT; 
    K: OleVariant; 
    iFetched: Cardinal; 
    V1, V2: OleVariant; 
    r: HRESULT; 
begin 
    o := CoUPnPDeviceFinder.Create; 
    d := o.FindByUDN('uuid:a6d332da-f8ce-43ce-8210-79eacd4231c6'); 

    E := d.Services._NewEnum as IEnumVARIANT; 
    E.Reset; 
    CheckOSError(E.Next(1, K, iFetched)); 

    s := IDispatch(K) as IUPnPService; 

    r := s.InvokeAction('Echo', v1, v2); 
    ShowMessage(v2); 
end; 

如何形成InvokeAction v1和v2參數?

回答

1

根據MSDN Docs您應該將參數作爲Variant數組傳遞。在Delphi中可以使用VarArrayOf或VarArrayCreate函數

+0

謝謝。 VarArrayOf和VarArrayCreate都可以工作。 –