TxITGuy
2005-06-14 17:08:02 UTC
Hello,
I am having a curious (and mildly frustrating) problem with a COM component
I am writing in C++. Every method and event works flawlessly in both the
ActiveX Control Test container and in a Visual Basic application. I just
tried to add my first property (get, read-only) to the class, though, and
can't figure out how to get Visual Basic to accept it.
Here are the declaration and definition statements from C++:
IDL:
[propget, id(6), helpstring("Contains the data returned by the most recent
HTTP request.")] HRESULT Data([out, retval] BSTR* *pVal);
Declaration:
STDMETHOD(get_Data)(/*[out, retval]*/ BSTR* *pVal);
definition:
STDMETHODIMP CHTTP::get_Data(BSTR **pVal)
{
CComBSTR bsData;
bsData = m_sDataReceived.c_str(); //convert string to BSTR
**pVal = bsData.Copy(); //I read on
//
"http://www.roblocher.com/
//
whitepapers/oletypes.aspx"
//that
this was the way to get a
//OLE
compatible BSTR pointer.
//Any
other ideas are welcome.
return S_OK;
}
When compiled, the IDL declaration produces the following warning:
MIDL2039 : interface does not conform to [oleautomation] attribute : [
Parameter 'pVal' of Procedure 'get_Data' ( Interface 'IHTTP' ) ]
It finishes the build process normally, though, without any other errors or
warnings.
When I attempt to use the control on a Visual Basic form (with early
binding), however, I receive the following error if I try to read the Data
property:
"Function or interface marked as restricted, or the function uses an
automation type not supported in Visual Basic."
The Visual Basic object browser lists this property as returning a String,
though, which is what I wanted and expected ... and supposedly is supported
by Visual Basic.
The only difference between this BSTR and the other BSTRings in the
component is that this one is passed as a pointer. I tried changing the
declaration to to eliminate the pointers, but C++ really didn't like that at
all.
There doesn't seem to be much documentation on OLE data type requirements
around, at least not that I've been able to locate. Does anyone know how to
create a BSTR property that Visual Basic will accept?
Thanks,
Ben
I am having a curious (and mildly frustrating) problem with a COM component
I am writing in C++. Every method and event works flawlessly in both the
ActiveX Control Test container and in a Visual Basic application. I just
tried to add my first property (get, read-only) to the class, though, and
can't figure out how to get Visual Basic to accept it.
Here are the declaration and definition statements from C++:
IDL:
[propget, id(6), helpstring("Contains the data returned by the most recent
HTTP request.")] HRESULT Data([out, retval] BSTR* *pVal);
Declaration:
STDMETHOD(get_Data)(/*[out, retval]*/ BSTR* *pVal);
definition:
STDMETHODIMP CHTTP::get_Data(BSTR **pVal)
{
CComBSTR bsData;
bsData = m_sDataReceived.c_str(); //convert string to BSTR
**pVal = bsData.Copy(); //I read on
//
"http://www.roblocher.com/
//
whitepapers/oletypes.aspx"
//that
this was the way to get a
//OLE
compatible BSTR pointer.
//Any
other ideas are welcome.
return S_OK;
}
When compiled, the IDL declaration produces the following warning:
MIDL2039 : interface does not conform to [oleautomation] attribute : [
Parameter 'pVal' of Procedure 'get_Data' ( Interface 'IHTTP' ) ]
It finishes the build process normally, though, without any other errors or
warnings.
When I attempt to use the control on a Visual Basic form (with early
binding), however, I receive the following error if I try to read the Data
property:
"Function or interface marked as restricted, or the function uses an
automation type not supported in Visual Basic."
The Visual Basic object browser lists this property as returning a String,
though, which is what I wanted and expected ... and supposedly is supported
by Visual Basic.
The only difference between this BSTR and the other BSTRings in the
component is that this one is passed as a pointer. I tried changing the
declaration to to eliminate the pointers, but C++ really didn't like that at
all.
There doesn't seem to be much documentation on OLE data type requirements
around, at least not that I've been able to locate. Does anyone know how to
create a BSTR property that Visual Basic will accept?
Thanks,
Ben