为 imapi2 com 对象查找 uuid 的/标头或让 __uuidof 在 mingw 上工作 [英] finding uuid's/headers for imapi2 com objects or get __uuidof to work on mingw

查看:59
本文介绍了为 imapi2 com 对象查找 uuid 的/标头或让 __uuidof 在 mingw 上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 mingw 项目访问 imapi2 com 对象.我试图遵循一个视觉工作室的例子.我在 Microsoft SDK 7.1 中找到了 imapi2 头文件,但它们似乎没有 uuid.我看到的示例是在创建对象时使用 __uuidof 查找 uuid.像这样:

I am trying to access imapi2 com objects from a mingw project. I was trying to follow a visual studio example. I found the imapi2 header files in Microsoft SDK 7.1, but they do not seem to have the uuid's. The example I saw was using __uuidof for finding the uuid when creating an object. Like this:

CoCreateInstance(__uuidof(MsftDiscMaster2), NULL, CLSCTX_INPROC_SERVER, __uuidof(IDiscMaster2), (void**) &m_discMaster);

但我总是因为__uuidof而出错

But I always get an error because of __uuidof that is

对 _GUID const& 的未定义引用__mingw_uuidof().

undefined reference to _GUID const& __mingw_uuidof().

但是 __mingw_uuidof 被定义为 ...

But __mingw_uuidof is defined as ...

#define __CRT_UUID_DECL(type,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)           \
    extern "C++" {                                                      \
    template<> inline const GUID &__mingw_uuidof<type>() {              \
        static const IID __uuid_inst = {l,w1,w2, {b1,b2,b3,b4,b5,b6,b7,b8}}; \
        return __uuid_inst;                                             \
    }                                                                   \
    template<> inline const GUID &__mingw_uuidof<type*>() {             \
        return __mingw_uuidof<type>();                                  \
    }                                                                  \
    }

... 在 _mingw.h 中的几行来自#define __uuidof(type) __mingw_uuidof<__typeof(type)>()"

... in _mingw.h a few lines up from "#define __uuidof(type) __mingw_uuidof<__typeof(type)>()"

为什么 __mingw_uuidof 的 mingw 定义不起作用?

Why does the mingw definition for __mingw_uuidof not work?

有没有办法在sdk头文件中找到像DiscMaster这样的imapi对象的uuid?或者我需要获取其他头文件.

Is there some way to find the uuid for imapi objects like DiscMaster in the sdk header files? Or do I need to get someother header file.

谢谢

推荐答案

Microsoft 平台 SDK 中的 COM 接口通常由 .idl 文件定义,并且它们使用来自这些的 midl 生成 .h 文件.因此,要查找 CLSID 或 IID 值,请搜索 idl 文件.在这种情况下 imapi2.idl 具有您需要的 guid,它已用于生成 imapi2.h 文件:

COM interfaces in Microsoft's Platform SDK are normally defined by .idl files and they generate .h files using midl from these. So to just look up the CLSID or IID values search the idl file. In this case imapi2.idl has the guid you need and this has been used to produce an imapi2.h file with:

class DECLSPEC_UUID("2735412E-7F64-5B0F-8F00-5D77AFBE261E")
MsftDiscMaster2;

Microsoft 编译器中的 __uuidof 扩展通过编译器特定的 declspec 语句读取附加到类或结构的编译器特定数据.您可以使用以下方法执行这些操作:

The __uuidof extension in Microsoft's compilers reads the compiler specific data attached to the class or structure by a compiler specific declspec statement. You can do these using:

struct declspec(uuid("{......}")) IMyInterfaceType;

因此上面的 DECLSPEC_UUID 行将该 guid 附加到类.

So the DECLSPEC_UUID line above is attaching that guid to the class.

您从 mingw 提供的示例代码提供了一个模板函数,如果您首先使用 __CRT_UUID_DECL 设置类型,该函数将返回给定类型的 uuid.可能他们有一个系统可以自动调用它,但没有显示.鉴于我在您的示例中看到的内容,要让 __uuidof 为您需要添加的给定 coclass 工作:

The example code you give from mingw gives a template function that will return a uuid for a given type provided you set up the type using __CRT_UUID_DECL first. It may be that they have a system to call this automatically but that is not shown. Given what I see in your example, to get __uuidof to work for the given coclass you need to add:

__CRT_UUID_DECL(MsftDiscMaster2, 0x2735412e, 0x7f64, 0x5b0f, 0x8f, 0x00, 0x5d, 0x77, 0xaf, 0xbe, 0x26, 0x1e);

在该语句之后,您将获得 __uuidof(MsftDiscMaster2) 的定义,该定义将返回正确的 uuid.

Following that statement, you will have a definition for __uuidof(MsftDiscMaster2) that will return the correct uuid.

这篇关于为 imapi2 com 对象查找 uuid 的/标头或让 __uuidof 在 mingw 上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆