访问COM接口方法C ++

时间:2021-10-12 15:07:31

Both:

  • CLSID
  • IID

Having specified the above, and using:

指定了上述内容,并使用:

  • CoCreateInstance()

To returning a single uninitialised object of the class specified by the CLSID above.

返回由上面的CLSID指定的类的单个未初始化对象。

How can I then access an Interface's method from C++? Without:

那我如何从C ++访问Interface的方法呢?无:

  • ATL
  • MFC
  • Just plain C++
  • 简单的C ++

Afterwards, I use CreateInstance()

之后,我使用CreateInstance()

I'm having trouble, using CreateInstance() - with the last parameter - ppv

我遇到了麻烦,使用CreateInstance() - 使用最后一个参数 - ppv

Using oleview, I can see methods of the specified IIDabove IID above, such as:

使用oleview,我可以看到上面指定的IID上面的IID的方法,例如:

interface IS8Simulation : IDispatch {
    HRESULT Open([in] BSTR FileName);
};

How can I then access the above? Examples/guidance - please

我怎样才能访问上面的内容?示例/指导 - 请

Regards

4 个解决方案

#1


By doing a CoCreateInstance you get an interface pointer. Through QueryInterface(...) method you can get the interface pointer of some other interface easily. e.g.,

通过执行CoCreateInstance,您将获得一个接口指针。通过QueryInterface(...)方法,您可以轻松获取其他界面的界面指针。例如。,


IUnknown* pUnk = NULL;
HRESULT hr = ::CoCreateInstance(clsid,NULL,CLSCTX_ALL,__uuidof(IUnknown),(void**)&pUnk);

IS8Simulation* pSim = NULL; hr = pUnk->QueryInterface(__uuidof(IS8Simulation), (void**)&pSim);

IS8Simulation * pSim = NULL; hr = pUnk-> QueryInterface(__ uuidof(IS8Simulation),(void **)&pSim);

After doing this, you will get the pointer to IS8Simulation in pSim and through that you can call methods of that interface. Remember you need to provide a valid clsid in the CoCreateInstance call.

执行此操作后,您将在pSim中获得指向IS8Simulation的指针,并通过该指针调用该接口的方法。请记住,您需要在CoCreateInstance调用中提供有效的clsid。

#2


It's a little vague what the actual problem is. Some code would be helpful. But to take a guess, do you need to QueryInterface?

实际问题是什么有点模糊。一些代码会有所帮助。但是要猜测,你需要QueryInterface吗?

#3


 IS8Simulation* pSim = NULL;
 hr = pUnk->QueryInterface(__uuidof(IS8Simulation), (void)&pSim);

I'll attempt the above, but were is IS8Simulation declared - please excuss my lack of COM understanding

我将尝试上述内容,但是IS8仿真已经宣布 - 请原谅我缺乏COM理解

Furthermore, how to call the method, below using plain C++:

此外,如何使用普通C ++调用该方法:

HRESULT Open([in] BSTR FileName)

#4


You probably want #import "something.dll". This will give you C++ declarations for types like IS8Simulation, similar to what #include "something.h" would do.

你可能想要#import“something.dll”。这将为您提供类似于IS8Simulation的类型的C ++声明,类似于#include“something.h”所做的。

#1


By doing a CoCreateInstance you get an interface pointer. Through QueryInterface(...) method you can get the interface pointer of some other interface easily. e.g.,

通过执行CoCreateInstance,您将获得一个接口指针。通过QueryInterface(...)方法,您可以轻松获取其他界面的界面指针。例如。,


IUnknown* pUnk = NULL;
HRESULT hr = ::CoCreateInstance(clsid,NULL,CLSCTX_ALL,__uuidof(IUnknown),(void**)&pUnk);

IS8Simulation* pSim = NULL; hr = pUnk->QueryInterface(__uuidof(IS8Simulation), (void**)&pSim);

IS8Simulation * pSim = NULL; hr = pUnk-> QueryInterface(__ uuidof(IS8Simulation),(void **)&pSim);

After doing this, you will get the pointer to IS8Simulation in pSim and through that you can call methods of that interface. Remember you need to provide a valid clsid in the CoCreateInstance call.

执行此操作后,您将在pSim中获得指向IS8Simulation的指针,并通过该指针调用该接口的方法。请记住,您需要在CoCreateInstance调用中提供有效的clsid。

#2


It's a little vague what the actual problem is. Some code would be helpful. But to take a guess, do you need to QueryInterface?

实际问题是什么有点模糊。一些代码会有所帮助。但是要猜测,你需要QueryInterface吗?

#3


 IS8Simulation* pSim = NULL;
 hr = pUnk->QueryInterface(__uuidof(IS8Simulation), (void)&pSim);

I'll attempt the above, but were is IS8Simulation declared - please excuss my lack of COM understanding

我将尝试上述内容,但是IS8仿真已经宣布 - 请原谅我缺乏COM理解

Furthermore, how to call the method, below using plain C++:

此外,如何使用普通C ++调用该方法:

HRESULT Open([in] BSTR FileName)

#4


You probably want #import "something.dll". This will give you C++ declarations for types like IS8Simulation, similar to what #include "something.h" would do.

你可能想要#import“something.dll”。这将为您提供类似于IS8Simulation的类型的C ++声明,类似于#include“something.h”所做的。