3,248
社区成员




[ uuid(86D2FFCF-1279-465F-A04A-98EFF2E0FE9D) ]
dispinterface IMyScriptObject
{
properties:
methods:
[id(1), propget, helpstring("属性 Item")] VARIANT Item(BSTR bstrName);
[id(1), propput, helpstring("属性 Item")] void Item(BSTR bstrName, VARIANT newVal);
[id(2), helpstring("方法gcd")] LONG gcd(LONG a, LONG b);
[id(3), helpstring("方法HelpAbout")] void HelpAbout(void);
[id(4), helpstring("方法ShowValue")] void ShowValue(BSTR prompt, LONG n);
};
void CMyScriptObject::SetItem(LPCTSTR bstrName, VARIANT newVal)
{
AFX_MANAGE_STATE(AfxGetAppModuleState());
// TODO: 在此添加属性处理程序代码
CString str;
if (newVal.vt == VT_I4)
str.Format(_T("%s%d"), bstrName, newVal.intVal );
else
str.Format(_T("%s"), bstrName);
AfxMessageBox(str, MB_SETFOREGROUND);
}
void CMyScriptObject::SetItem(LPCTSTR bstrName, _variant_t newVal)
{
AFX_MANAGE_STATE(AfxGetAppModuleState());
// TODO: 在此添加属性处理程序代码
VARIANT dest;
VariantInit(&dest);
if(VariantChangeType(&dest,&newVal,0,VT_I4))
{
int i = 0;
}
CString str;
if (newVal.vt == VT_I4)
str.Format(_T("%s%d"), bstrName, newVal.intVal );
else
str.Format(_T("%s"), bstrName);
AfxMessageBox(str, MB_SETFOREGROUND);
}
通过VBS调用,本意是想newVal = 5,实际发现newVal类型变为不可知的了。但我把newVal声明为LONG等具体一个类型时,是没有错的。