ATL Component with C++ class
Hi,
I want to build a ATL wrapper on c++ class and would like to use that
component in VB.
I insert an ATL class MyAWrapper
I add one property HRESULT String([out, retval] BSTR *pVal)
one method HRESULT ClearString() to IMyAWrapper.
IDL file shows it then in MyAWrapper.h
i put following c++ code
class foo
{
std::string m_str;
public:
foo(std::string bar, bool baz) : m_str(bar)
{
if (baz) throw std::exception();
}
std::string get_string(void) { return m_str; }
void clear_string(void) { m_str = ""; }
};
in ATL class.. class MyAWrapper I addfollowing code.
STDMETHOD(FinalConstruct)(void)
{
try {
m_pfoo = new foo("test", false);
}
catch (...) {
return E_FAIL;
}
return S_OK;
}
in MyAWrapper.cpp, I put
STDMETHODIMP MyAWrapper::get_String(BSTR *pVal)
{
// TODO: Add your implementation code here
if (pVal == NULL)
return E_POINTER;
std::string sTemp = m_pfoo->get_string();
*pVal = ::SysAllocStringLen(sTemp.c_str(), sTemp.length());
return *pVal ? S_OK : E_OUTOFMEMORY;
}
STDMETHODIMP MyAWrapper::ClearString()
{
// TODO: Add your implementation code here
m_pfoo->clear_string();
}
Please tell me Are these stpes OK??
or
where to put c++ code?
I can not compile the project.. I get around 34 errors one of which is
'std' : is not a class or namespace name
Pleasew tell me how to have this perfectly function.
Thanks
Lee