我在C中有以下代码来创建UiAutomation对象:
#include "UiAutomationclient.h"
IUIAutomation *pAutomation = NULL;
IUIAutomationElement *element = NULL;
CoInitialize(NULL);
EXTERN_C const CLSID CLSID_CUIAutomation;
EXTERN_C const IID IID_IUIAutomation;
HRESULT hr = CoCreateInstance(CLSID_CUIAutomation,NULL, CLSCTX_INPROC_SERVER,IID_IUIAutomation,(void**)&pAutomation);
但是,我得到了以下错误:
'function': cannot convert from 'const CLSID' to 'const IID *const '
'function': cannot convert from 'const IID' to 'const IID *const '
我不知道我在做什么不对。谢谢你提前提供帮助
发布于 2020-10-09 21:55:22
发布的代码在C++中编译,但在C中,函数需要指针而不是引用。
HRESULT hr = CoCreateInstance(&CLSID_CUIAutomation, NULL, CLSCTX_INPROC_SERVER, &IID_IUIAutomation, (void**)&pAutomation);
这是因为CoCreateInstance
是已声明,因为:
HRESULT CoCreateInstance(
REFCLSID rclsid,
LPUNKNOWN pUnkOuter,
DWORD dwClsContext,
REFIID riid,
LPVOID *ppv
);
但REFCLSID
和REFIID
是有条件 #define
d,取决于目标语言:
#ifdef __cplusplus
#define REFIID const IID &
#else
#define REFIID const IID * __MIDL_CONST
#endif
#ifdef __cplusplus
#define REFCLSID const IID &
#else
#define REFCLSID const IID * __MIDL_CONST
#endif
https://stackoverflow.com/questions/64287718
复制相似问题