为什么unknw.h中需要三个前瞻性声明

Why are the three forward declarations necessary in unknwn.h?

本文关键字:三个 前瞻性 声明 unknw 为什么      更新时间:2023-10-16

我正在使用JNAngator来解析windows API头文件,这样我就可以从JVM中引用它们。然而,我对C/C++不像其他语言那样熟悉,但我需要理解这些头文件,然后才能正确解析它们。

我特别关注Unkwn.h,它基本上包含

#include "rpc.h"
#include "rpcndr.h"
#ifndef COM_NO_WINDOWS_H
#include "windows.h"
#include "ole2.h"
#endif /*COM_NO_WINDOWS_H*/

//Some forward declarations
typedef interface IUnknown IUnknown;
typedef interface AsyncIUnknown AsyncIUnknown;
typedef interface IClassFactory IClassFactory;
#include "wtypes.h"
//followed by the full declarations for the interfaces IUnkown, AsyncIUnkown and IClassFactory and their methods, but no actual implementations of course. 

如果类型(IUnkown、AsynUnkown或IClassFactory)被wtypes.h引用,我认为这些正向定义是必要的,但我在wtypes.小时或wtypes.h引用的其他标头中找不到对这些类型的任何引用。那么,为什么需要前瞻性声明(或者我错过了什么)?

这些不是正向声明。这些是类型定义,它们定义接口数据类型。这当然是微软的扩展。定义所做的是确保IUnknown(例如)引用该名称的接口。