idl文件当中定义的helpstring等属性,如何在客户端显示出来? 例如,一个实现了IDispatch的组件,在客户端程序用MFC来导入类型库,VS自动为我声明一个包装类,这个包装类可以用来Invoke组件的函数。我的问题是: 这个组件是用ATL实现的,某些接口和函数里面有[helpstring]这样的属性。请问: 客户端程序能否得到并显示这些类型库当中的helpstring? 如何编码呢?谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 msdn 例子:OLEAUT\TIBROWSE通过类型库接口获取到. 我在网上没有找到啊。能给个msdn链接吗?多谢。 vc6 的 msdn 中有, 后来微软给去掉了就是通过 dispatch 接口得到类型信息.看看 msdn 中:Win32 and COM Development Component Development Automation SDK Documentation Type Description Interface下面的接口, 自己也能写出来.voidtypetree::load(IDispatch* pDisp){ //remove all nodes DeleteAllItems(); // release previous if loaded release(); UINT cCount=0; HRESULT hr = pDisp->GetTypeInfoCount(&cCount); for (UINT i = 0; i < cCount; i++) { ITypeInfo* pTypeInfo = 0; pDisp->GetTypeInfo(i, LOCALE_USER_DEFAULT, &pTypeInfo); walkTypeInfo(pTypeInfo, TVI_ROOT); }}voidtypetree::walkTypeInfo(ITypeInfo* pTypeInfo, HTREEITEM hParentItem){ WORD cFuncs, cVars, cImplTypes; TYPEKIND typekind; TYPEATTR* pTypeAttr = 0; TCHAR szText[128]; CStdString str; HTREEITEM hItem; HRESULT hr = pTypeInfo->GetTypeAttr(&pTypeAttr); if (SUCCEEDED(hr)) { GUID guid = pTypeAttr->guid; LCID lcid = pTypeAttr->lcid; DWORD dwReserved = pTypeAttr->dwReserved; MEMBERID memidConstructor = pTypeAttr->memidConstructor; MEMBERID memidDestructor = pTypeAttr->memidDestructor; LPOLESTR lpstrSchema = pTypeAttr->lpstrSchema; ULONG cbSizeInstance = pTypeAttr->cbSizeInstance; typekind = pTypeAttr->typekind; cFuncs = pTypeAttr->cFuncs; cVars = pTypeAttr->cVars; cImplTypes = pTypeAttr->cImplTypes; WORD cbSizeVft = pTypeAttr->cbSizeVft; WORD cbAlignment = pTypeAttr->cbAlignment; WORD wTypeFlags = pTypeAttr->wTypeFlags; WORD wMajorVerNum = pTypeAttr->wMajorVerNum; WORD wMinorVerNum = pTypeAttr->wMinorVerNum; TYPEDESC tdescAlias = pTypeAttr->tdescAlias; IDLDESC idldescType = pTypeAttr->idldescType; pTypeInfo->ReleaseTypeAttr(pTypeAttr); } else { return; } { BSTR name, docString, helpFile; DWORD dwHelpContext; //If the passed-in memid is MEMBERID_NIL, then the documentation for the type description is returned. pTypeInfo->GetDocumentation(MEMBERID_NIL, &name, &docString, &dwHelpContext, &helpFile); _stprintf(szText, _T("%s [%s]"), (LPCTSTR)name, typeKindToStr(typekind, str)); SysFreeString(name);SysFreeString(docString);SysFreeString(helpFile); } switch (typekind) { case TKIND_ENUM: hItem = InsertItem(hParentItem, NULL, szText, NULL, 4, 4); break; case TKIND_RECORD: hItem = InsertItem(hParentItem, NULL, szText, NULL, 0, 0); break; case TKIND_MODULE: hItem = InsertItem(hParentItem, NULL, szText, NULL, 14, 14); break; case TKIND_INTERFACE: case TKIND_DISPATCH: { hItem = InsertItem(hParentItem, NULL, szText, NULL, 8, 8); walkVariables(pTypeInfo, cVars, hItem); walkFunctions(pTypeInfo, cFuncs, hItem); } break; case TKIND_COCLASS: hItem = InsertItem(hParentItem, NULL, szText, NULL, 1, 1); break; case TKIND_ALIAS: hItem = InsertItem(hParentItem, NULL, szText, NULL, 10, 10); break; case TKIND_UNION: hItem = InsertItem(hParentItem, NULL, szText, NULL, 23, 23); break; default: hItem = InsertItem(hParentItem, NULL, szText, NULL, 21, 21); break; }} 请问如何attach 对象??? 向串口发送数据 沈阳招vc程序员 VC中的序列化问题 请教一段代码,不知道为什么while()循环得不到预期的结果? 菜鸟问题:如何将 int 转换位 CString。如何将 CSring 转换位 int. VC6 IDE使用的问题. 为什么在win2000下编写的程序在win98下不能正常运行? 请问:关于单文档滚动条 TO TABLE:你再看一下,就一點 求助,timeSetEvent与timeKillEvent的使用,导致进程不能退出 VC++ 对话框上加载web网页,并会调用js函数,用什么方法好?
OLEAUT\TIBROWSE
通过类型库接口获取到.
多谢。
就是通过 dispatch 接口得到类型信息.
看看 msdn 中:
Win32 and COM Development
Component Development
Automation
SDK Documentation
Type Description Interface
下面的接口, 自己也能写出来.
void
typetree::load(IDispatch* pDisp)
{
//remove all nodes
DeleteAllItems(); // release previous if loaded
release(); UINT cCount=0;
HRESULT hr = pDisp->GetTypeInfoCount(&cCount);
for (UINT i = 0; i < cCount; i++) {
ITypeInfo* pTypeInfo = 0;
pDisp->GetTypeInfo(i, LOCALE_USER_DEFAULT, &pTypeInfo);
walkTypeInfo(pTypeInfo, TVI_ROOT);
}
}
void
typetree::walkTypeInfo(ITypeInfo* pTypeInfo, HTREEITEM hParentItem)
{
WORD cFuncs, cVars, cImplTypes;
TYPEKIND typekind;
TYPEATTR* pTypeAttr = 0;
TCHAR szText[128];
CStdString str;
HTREEITEM hItem;
HRESULT hr = pTypeInfo->GetTypeAttr(&pTypeAttr);
if (SUCCEEDED(hr)) {
GUID guid = pTypeAttr->guid;
LCID lcid = pTypeAttr->lcid;
DWORD dwReserved = pTypeAttr->dwReserved;
MEMBERID memidConstructor = pTypeAttr->memidConstructor;
MEMBERID memidDestructor = pTypeAttr->memidDestructor;
LPOLESTR lpstrSchema = pTypeAttr->lpstrSchema;
ULONG cbSizeInstance = pTypeAttr->cbSizeInstance;
typekind = pTypeAttr->typekind;
cFuncs = pTypeAttr->cFuncs;
cVars = pTypeAttr->cVars;
cImplTypes = pTypeAttr->cImplTypes;
WORD cbSizeVft = pTypeAttr->cbSizeVft;
WORD cbAlignment = pTypeAttr->cbAlignment;
WORD wTypeFlags = pTypeAttr->wTypeFlags;
WORD wMajorVerNum = pTypeAttr->wMajorVerNum;
WORD wMinorVerNum = pTypeAttr->wMinorVerNum;
TYPEDESC tdescAlias = pTypeAttr->tdescAlias;
IDLDESC idldescType = pTypeAttr->idldescType; pTypeInfo->ReleaseTypeAttr(pTypeAttr);
} else {
return;
}
{
BSTR name, docString, helpFile;
DWORD dwHelpContext; //If the passed-in memid is MEMBERID_NIL, then the documentation for the type description is returned.
pTypeInfo->GetDocumentation(MEMBERID_NIL, &name, &docString, &dwHelpContext, &helpFile);
_stprintf(szText, _T("%s [%s]"), (LPCTSTR)name, typeKindToStr(typekind, str));
SysFreeString(name);SysFreeString(docString);SysFreeString(helpFile);
} switch (typekind)
{
case TKIND_ENUM:
hItem = InsertItem(hParentItem, NULL, szText, NULL, 4, 4);
break;
case TKIND_RECORD:
hItem = InsertItem(hParentItem, NULL, szText, NULL, 0, 0);
break;
case TKIND_MODULE:
hItem = InsertItem(hParentItem, NULL, szText, NULL, 14, 14);
break;
case TKIND_INTERFACE:
case TKIND_DISPATCH:
{
hItem = InsertItem(hParentItem, NULL, szText, NULL, 8, 8);
walkVariables(pTypeInfo, cVars, hItem);
walkFunctions(pTypeInfo, cFuncs, hItem);
}
break;
case TKIND_COCLASS:
hItem = InsertItem(hParentItem, NULL, szText, NULL, 1, 1);
break;
case TKIND_ALIAS:
hItem = InsertItem(hParentItem, NULL, szText, NULL, 10, 10);
break;
case TKIND_UNION:
hItem = InsertItem(hParentItem, NULL, szText, NULL, 23, 23);
break;
default:
hItem = InsertItem(hParentItem, NULL, szText, NULL, 21, 21);
break;
}
}