2011-11-02 57 views
0

IAutomation - 如何獲取其順利通過指針參數的值?IAutomation - 如何獲取其順利通過指針參數的值?

在.idl文件所著:

interface IAutomation : IDispatch { 
     [id(0x000000e0), helpstring("Returns if the player is ready. Many of the other commands fail as long as the player is not ready.")] 
     HRESULT GetReady([out] VARIANT* Ready); 
}; 

我想,GETREADY() - 方法,而不是財產。

如果我想使用田鼠庫:

object player = object::create("StereoPlayer.Automation", CLSCTX_LOCAL_SERVER, vole::coercion_level::valueCoercion); 
VARIANT var; 
::VariantInit(&var); 
VARIANT pos = player.invoke_method(vole::of_type<VARIANT>(), L"GetReady", var); 

但收到鏈接錯誤:

error LNK2019: unresolved external symbol "public: static struct tagVARIANT __cdecl vole::com_return_traits<struct tagVARIANT>::convert(struct tagVARIANT const &,enum vole::coercion_level::coercion_level)" ([email protected][email protected]@@@[email protected]@[email protected]@[email protected][email protected]@@Z) referenced in function "public: struct tagVARIANT __thiscall vole::object::invoke_method<struct tagVARIANT,struct tagVARIANT>(struct vole::of_type<struct tagVARIANT>,unsigned short const *,struct tagVARIANT const &)" ([email protected]@@[email protected]@[email protected]@@[email protected]@[email protected]@@@[email protected]@@Z) 

調用其他方法,它返回任何結果,完美的作品。

另外我嘗試直接調用方法IDispatch :: Invoke(),如How To Use Visual C++ to Access DocumentProperties with Automation 中所述。但誤解了如何回報價值。

回答

0

我不熟悉的田鼠,但如果我正確地閱讀它的源代碼,你需要做的,而不是:

VARIANT pos = player.invoke_method<VARIANT>(L"GetReady"); 

或者這樣:

VARIANT pos = player.invoke_method(vole::of_type<VARIANT>(), L"GetReady"); 

你試圖傳遞在一個VARIANT作爲[in]參數GetReady(),但它沒有這樣的參數。它有一個[out]參數,代表返回值invoke_method(),所以你不需要傳遞你自己的VARIANT參數。

invoke_method()執行VARIANT -to-型coersions內部,所以假設GetReady()實際上返回封裝在VARIANT一個布爾值,你甚至可以做這樣的事情:

VARIANT_BOOL ready = player.invoke_method<VARIANT_BOOL>(L"GetReady"); 

甚至:

bool ready = player.invoke_method<bool>(L"GetReady"); 
+0

如果調用不帶參數的invoke_method - invoke()返回hr = 0x8002000e參數個數無效。 – Peleron