描述:
cpp部分内容:
STDMETHODIMP CLog::get_type(long *pVal)
{
// TODO: Add your implementation code here
*pVal = m_type;
return S_OK;
}
STDMETHODIMP CLog::put_type(long newVal)
{
// TODO: Add your implementation code here
m_type = newVal;
return S_OK;
}
--------------------------------------------------------
idl:
interface ILog : IDispatch
{
[id(1), helpstring("method Test")] HRESULT Test([out, retval]long *pVal);
[propget, id(2), helpstring("property type")] HRESULT type([out, retval] long *pVal);
[propput, id(2), helpstring("property type")] HRESULT type([in] long newVal); };
------------------------------------------
测试程序:
ILog log;
long test = 0;
log.SetType(1000);
test = log.GetType();
---------------------
说明:
编译通过,就是test无法赋值.
怎么回事?
谢谢,解决后马上给分!
解决方案1:
"ILog log;log.SetType(1000);"????你是这么调用方法的?难怪会错误!
解决方案2: if(!AfxOleInit())
AfxMessageBox("WRONG!");;
HRESULT hr;
IPDFVw *ppvPDFVw = NULL;//对应clsid
ICreateRTF *ppvaaa = NULL;//对应iid
HRESULT l = NULL;
hr=CoCreateInstance(CLSID_PDFVw,NULL,CLSCTX_LOCAL_SERVER ,IID_IPDFVw,(void**)&ppvPDFVw);
if(SUCCEEDED(hr))
{
l = ppvPDFVw->SomeMethod();
ppvPDFVw->Release();
}
else
AfxMessageBox("WRONG!");
不知道你的属性是怎么添加的,但是你用法好像是不对!呵呵
解决方案4: ILog log;
long test = 0;
log.SetType(1000);
test = log.GetType();
不是这样用的。
//IID_IGetNumber
this->UpdateData();
::CoInitialize( NULL );
IGetNumber *pGN = NULL;
CLSID clsid = CLSID_GetNumber;
HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,
IID_IGetNumber, (void **)&pGN);
if(FAILED(hr))
{
AfxMessageBox("生成接口出错,可能没有初使化com!");
::CoUninitialize();
return;
}
CComBSTR str = m_value;
long ret = 0;
pGN->GetUserCount(str,&ret);
CString str2;
str2.Format("the res %d",ret);
AfxMessageBox(str2);
::CoUninitialize();