- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有谁知道从类型库(.tlb)生成 idl 文件的命令行工具?这样做的原因是为了摆脱 regasm 生成的枚举值中的下划线。此博客中讨论了枚举中的下划线问题
http://blogs.artinsoft.net/mrojas/archive/2010/05/17/interop-remove-prefix-from-c-enums-for-com.aspx
我知道 OLEView 可以生成 IDL 文件,但我正在寻找一种适合自动构建的解决方案。
最佳答案
我怀疑这是一个完全可以满足您需求的工具。但是,滚动您自己的转换器应该不会太难。使用类型库有点麻烦。我编写了一个工具,它可以从 .idl 文件或 .tlb 文件为 COM 接口(interface)生成 C++ 包装类。读取接口(interface)相关信息的代码大约有250行代码,所以如果你添加一些代码来生成一个.idl文件你应该会得到大约1000行代码。
以下代码是我的 C++ 代码的精简版,它应该可以为您提供总体思路。但是,由于我目前无法访问编译器,因此我无法检查它是编译(不太可能)还是工作(当然不是)。
#include <afxwin.h>
#include <comdef.h>
#include <atlconv.h>
#include <atlbase.h>
char* paTypeNames[] =
{
"VT_EMPTY", // = 0,
"VT_NULL", // = 1,
"short", //"VT_I2", // = 2,
"long", //"VT_I4", // = 3,
"real", // "VT_R4", // = 4,
"double", // "VT_R8", // = 5,
"VT_CY", // = 6,
"VT_DATE", // = 7,
"BSTR", //"VT_BSTR", // = 8,
"IDispatch*", // "VT_DISPATCH", // = 9,
"VT_ERROR", // = 10,
"VARIANT_BOOL", //"VT_BOOL", // = 11,
"VARIANT", //"VT_VARIANT", // = 12,
"IUnknown*", // VT_UNKNOWN = 13,
"VT_DECIMAL", // = 14,
"VBA reserves 15 for future use",
"VT_I1", // = 16,
"VT_UI1", // = 17,
"VT_UI2", // = 18,
"VT_UI4", // = 19,
"VT_I8", // = 20,
"VT_UI8", // = 21,
"int", //"VT_INT", // = 22,
"UINT", // = 23,
"VOID", // = 24,
"HRESULT", // = 25,
"VT_PTR", // = 26,
"VT_SAFEARRAY", // = 27,
"VT_CARRAY", // = 28,
"VT_USERDEFINED", // = 29,
"VT_LPSTR", // = 30,
"VT_LPWSTR", // = 31,
"VBA reserves 32 for future use",
"VBA reserves 33 for future use",
"VBA reserves 34 for future use",
"VBA reserves 35 for future use",
"VT_RECORD", // = 36,
"VT_INT_PTR", // = 37,
"VT_UINT_PTR", // = 38,
"Unknown Type number above 39"
};
CString GetType (const TYPEDESC& p_TYPEDESC, ITypeInfo* p_pTypeInfo)
{
// Look up user defined types in the type library.
if (p_TYPEDESC.vt == VT_USERDEFINED)
{
ITypeInfoPtr spInnerType;
VERIFY (SUCCEEDED (p_pTypeInfo->GetRefTypeInfo (p_TYPEDESC.hreftype, &spInnerType)));
BSTR CurrTypeName;
VERIFY (SUCCEEDED (spInnerType->GetDocumentation (MEMBERID_NIL, &CurrTypeName, NULL, NULL, NULL)));
return CString (CurrTypeName);
}
else if (p_TYPEDESC.vt == VT_PTR)
return GetType (*p_TYPEDESC.lptdesc, p_pTypeInfo) + CString (_T("*"));
else
{
return CString (paTypeNames[min (p_TYPEDESC.vt & VT_TYPEMASK, 39)]);
}
}
bool ParseTypeLib (char* p_strTypeLibName)
{
USES_CONVERSION;
// Load the type library.
ITypeLibPtr spTypeLib;
HRESULT hr = LoadTypeLibEx (A2OLE (p_strTypeLibName), REGKIND_DEFAULT, &spTypeLib);
if (!(bool)spTypeLib)
return false;
UINT uiNumberOfTypes = spTypeLib->GetTypeInfoCount ();
for (int i = 0; i < uiNumberOfTypes; i++)
{
ITypeInfoPtr spCurrTypeInfo;
spTypeLib->GetTypeInfo (i, &spCurrTypeInfo);
if (!(bool) spCurrTypeInfo)
return false;
// We only want to process interface definitions, so if we encounter anything
// else (for example enums), we skip the rest of the loop.
TYPEATTR* pCurrentTypeAttr;
VERIFY (SUCCEEDED (spCurrTypeInfo->GetTypeAttr (&pCurrentTypeAttr)));
if (pCurrentTypeAttr->typekind != TKIND_DISPATCH &&
pCurrentTypeAttr->typekind != TKIND_INTERFACE)
continue;
// Retrieve the current interface name.
CComBSTR CurrInterfaceName;
hr = spTypeLib->GetDocumentation (i, &CurrInterfaceName, NULL, NULL, NULL);
std::cout << "interface " << CurrInterfaceName;
// Retrieve the name of the base class. According to MSDN
// (http://msdn.microsoft.com/en-us/library/aa909031.aspx), we must first retrieve
// the TKIND_INTERFACE type description for our class, and then we can retrieve
// the base class information. We also need the TKIND_INTERFACE type description
// because TKIND_DISPATCH type descriptions contain both the methods of the current
// interface as well as the methods of all base interfaces.
ITypeInfoPtr spBaseType;
if (pCurrentTypeAttr->typekind == TKIND_DISPATCH)
{
HREFTYPE TempHREF;
VERIFY (SUCCEEDED (spCurrTypeInfo->GetRefTypeOfImplType (-1, &TempHREF)));
ITypeInfoPtr spTempInfo;
VERIFY (SUCCEEDED (spCurrTypeInfo->GetRefTypeInfo (TempHREF, &spTempInfo)));
spCurrTypeInfo = spTempInfo;
}
HREFTYPE BaseClassHREF;
VERIFY (SUCCEEDED (spCurrTypeInfo->GetRefTypeOfImplType (0, &BaseClassHREF)));
VERIFY (SUCCEEDED (spCurrTypeInfo->GetRefTypeInfo (BaseClassHREF, &spBaseType)));
CComBSTR CurrBaseTypeName;
VERIFY (SUCCEEDED (spBaseType->GetDocumentation (MEMBERID_NIL, &CurrBaseTypeName, NULL, NULL, NULL)));
std::cout << " : " << CurrBaseTypeName << "{\n";
// Process the methods of the current interface.
FUNCDESC* pCurrFUNCDESC;
int j = 0;
while (SUCCEEDED (spCurrTypeInfo->GetFuncDesc (j++, &pCurrFUNCDESC)))
{
// Retrieve the return type of the COM method (this does not necessarily have to be
// an HRESULT).
std::cout << paTypeNames[pCurrFUNCDESC->elemdescFunc.tdesc.vt] << " ";
// Ask for the function descriptor for the current function.
unsigned int cNames;
BSTR* CurrNames = DEBUG_NEW BSTR[pCurrFUNCDESC->cParams + 1];
hr = spCurrTypeInfo->GetNames (pCurrFUNCDESC->memid, CurrNames, pCurrFUNCDESC->cParams + 1, &cNames);
// The first element contains the name of the function.
std::cout << CurrNames[0] << " (";
// Process the parameters of the current function.
for (int k = 0; k < pCurrFUNCDESC->cParams; k++)
{
std::cout << "[";
// Determine the type of the parameter (in, out, retval).
bool needComma = false;
if (pCurrFUNCDESC->lprgelemdescParam[k].paramdesc.wParamFlags & PARAMFLAG_FIN)
{
std::cout << "in";
needComma = true;
}
if (pCurrFUNCDESC->lprgelemdescParam[k].paramdesc.wParamFlags & PARAMFLAG_FOUT)
{
if (needComma)
std::cout << ", ";
std::cout << "out";
needComma = true;
}
if (pCurrFUNCDESC->lprgelemdescParam[k].paramdesc.wParamFlags & PARAMFLAG_FRETVAL)
{
if (needComma)
std::cout << ", ";
std::cout << "retval";
}
std::cout << "] ";
std::cout << GetType (pCurrFUNCDESC->lprgelemdescParam[k].tdesc, spCurrTypeInfo);
// If we didn't get a name for the parameter, it must be the parameter of a property put
// method. In this case we call the parameter simply "RHS"
if (k + 1 >= cNames)
std::cout << "RHS";
else
std::cout << CurrNames[k + 1];
}
delete[] CurrNames;
}
}
// If we have reached this line, all of the above operations must have succeeded.
return true;
}
关于.net - 将 TLB 转换为 IDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13719631/
我有一个奇怪的问题。根据像this这样的帖子我希望 IDLE 比在命令行上运行我的代码慢。然而,我看到完全相反的情况。 该程序比较两个文件并将匹配行配对在一起并将所有匹配项写入新文件。我认为它类似于
我使用 emacs-24.5.1 浏览了 linux 内核代码,并使用 cedet(内联在 emacs 中)进行语义解析。 经过一些常规配置后,我用emacs打开init/main.c,出现了“Par
我写的字符串很长。为了便于阅读,我想将文本换行到多行。这是怎么做到的。我以前看过说明,但现在找不到了。 最佳答案 [这个答案一般适用于 Python,并不特定于 IDLE。] 对于没有嵌入换行符的长字
是否有任何现有的网络应用程序可以让多个用户同时使用交互式 IDLE 类型 session ? 类似于: IDLE 2.6.4 Morgan: >>> letters = list("abcdefg")
我是编程新手,我决定先学Python,所以; 我安装了 Python,最新版本 3.4。我正在尝试打开 Python IDLE(GUI) 模式,所以当我打开时,我收到消息“IDLE 的子进程没有建立连
最近很多用户发现system idle process占用率特别高,不知道什么意思,想要解决它。这个只是显示电脑剩余内存的,下面来看看想想的介绍吧。 system idle process占用率高
默认的 ATL 简单对象在其 IDL 文件的顶部具有以下内容: import "oaidl.idl"; import "ocidl.idl"; 这些文件有什么用,我怎么知道什么时候需要导入它们?是否有
这个问题在这里已经有了答案: How to clear the interpreter console? (30 个答案) 关闭 9 年前。 我正在运行一个脚本,该脚本使用的模块会在屏幕上打印很多内
这里 TP_DSCVoyChange 类有 KEY_DSC作为一个属性,我们要填充此 KEY_DSC 使用 TP_DSCVoyChange 使用 String 值从 Java 获取值构造函数。例如。
在我的 Mac 上,我通过自制软件安装了 python 3.9。 我尝试启动空闲并收到此错误: > idle3 ** IDLE can't import Tkinter. Your Python ma
我正在使用 this用于检测用户在我的应用程序中是否空闲的库。我正在使用 StartWatching(),在 onTimerStart 中,我现在只是打印控制台。 当用户空闲 N 秒时,onTimer
我们有一个 .NET 程序集(实际上是 Aspose.Words),我们希望客户端能够轻松地从 COM 客户端使用它。 因此,我们随程序集提供了 .TLB,以便客户端可以通过 C++ 或 Delphi
在之前的函数中,我创建并返回了一个哈希值。执行此操作后,它将哈希作为结构返回,我将其用作此以下函数的输入。 myStruct 的每个标签都是一个结构,每个都有一个名称和数据类型标签。 我正在尝试遍历每
假设我创建了以下 IDL 文件: module ProviderTest { interface Multiplier { long twice(in long number)
我有一个IDL文件,我使用scipy中的readsav将其导入Python,我更改了文件中的参数,我想将其导出/保存回原始格式,IDL可读。 这就是我导入它的方式: from scipy.io.idl
我正在尝试替换/删除文本文档中的一些行。该文档采用 ISO-8859-1 字符编码。 当我尝试将此行复制到我的 Python 脚本中进行替换时,它不会匹配。如果我缩短该行并删除直到第一个双引号 "它将
我的 Espresso 测试在 Espresso 版本 2.2.2 上运行良好,但是当我将我的工作室更新到最新版本并应用迁移规则时,测试将失败并需要更新版本。 库使用 androidTestImple
2013 年 4 月 15 日决议。 在 Windows 7(64 位)Windows 资源管理器中,当我右键单击 Python 文件并选择“使用 IDLE 编辑”时,编辑器会正确打开,但是当我运行(
我用的是3.8.10版本的Python.(32位)。我正在尝试在IDLE中导入NumPy包,但是我收到了这个消息。图像。我的Idle崩溃了,并显示以下信息。同样的事情也发生在其他包上,比如:Chain
IDL是什么意思?我用谷歌搜索了一下,发现它代表接口(interface)定义语言,用于组件的接口(interface)定义。但是,在实践中,IDL 的目的是什么?微软使用它吗? 最佳答案 接口(in
我是一名优秀的程序员,十分优秀!