Hi everyone,
I'm trying to compile this code but VC++ gives an error saying:
e:\download\dcom-implement\branch.h(42) : error C2065: 'CBranchAccountList' : undeclared identifier
Here is branch.h:
// Branch.h : Declaration of the CBranch
#ifndef __BRANCH_H_
#define __BRANCH_H_
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CBranch
class ATL_NO_VTABLE CBranch :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CBranch, &CLSID_Branch>,
public ISupportErrorInfo,
public IDispatchImpl<IBranch, &IID_IBranch, &LIBID_SERVERLib>
{
public:
CBranch()
{
m_pBranchAccountList = NULL;
}
~CBranch()
{
if (m_pBranchAccountList != NULL)
{
m_pBranchAccountList->Release();
}
}
DECLARE_REGISTRY_RESOURCEID(IDR_BRANCH)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CBranch)
COM_INTERFACE_ENTRY(IBranch)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
protected:
CComObject<CBranchAccountList> *m_pBranchAccountList;
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// IBranch
public:
STDMETHOD(get_BranchAccountList)(/*[out, retval]*/ LPDISPATCH *pVal);
};
#endif //__BRANCH_H_
And here is branch.cpp:
// Branch.cpp : Implementation of CBranch
#include "stdafx.h"
#include "Server.h"
#include "BranchAccountList.h"
#include "Branch.h"
/////////////////////////////////////////////////////////////////////////////
// CBranch
STDMETHODIMP CBranch::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IBranch
};
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr,riid))
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP CBranch::get_BranchAccountList(LPDISPATCH *pVal)
{
/*-----------------------------------------------------------*/
/* The BranchAccountList collection is built by "procrastination." */
/* That is, it is not built until first asked for. Once */
/* built, it stays built for the life of the Top Level */
/* Object. That is, further references to the BranchAccountList */
/* property of the Top Level Object return the already */
/* created instance. */
/*-----------------------------------------------------------*/
LPDISPATCH pDisp = NULL;
HRESULT hr;
*pVal = NULL;
if (m_pBranchAccountList == NULL)
{
/*----------------------------------------------------*/
/* Create the BranchAccountList collection object, then */
/* invoke its InitCollection function (a user-defined */
/* function that initializes the collection). */
/*----------------------------------------------------*/
hr = CComObject<CBranchAccountList>::CreateInstance(&m_pBranchAccountList);
if (SUCCEEDED(hr))
{
m_pBranchAccountList->AddRef();
hr = m_pBranchAccountList->InitBranchAccountListCollection();
if (FAILED(hr))
{
delete m_pBranchAccountList;
m_pBranchAccountList = NULL;
return hr;
}
}
}
/*-----------------------------------------------*/
/* Return IDispatch pointer to BranchAccountList object */
/*-----------------------------------------------*/
hr = m_pBranchAccountList->QueryInterface (IID_IDispatch,(void **) pVal);
return hr;
}
Please any help is appreciated. Thanks.
John
I'm trying to compile this code but VC++ gives an error saying:
e:\download\dcom-implement\branch.h(42) : error C2065: 'CBranchAccountList' : undeclared identifier
Here is branch.h:
// Branch.h : Declaration of the CBranch
#ifndef __BRANCH_H_
#define __BRANCH_H_
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CBranch
class ATL_NO_VTABLE CBranch :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CBranch, &CLSID_Branch>,
public ISupportErrorInfo,
public IDispatchImpl<IBranch, &IID_IBranch, &LIBID_SERVERLib>
{
public:
CBranch()
{
m_pBranchAccountList = NULL;
}
~CBranch()
{
if (m_pBranchAccountList != NULL)
{
m_pBranchAccountList->Release();
}
}
DECLARE_REGISTRY_RESOURCEID(IDR_BRANCH)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CBranch)
COM_INTERFACE_ENTRY(IBranch)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
protected:
CComObject<CBranchAccountList> *m_pBranchAccountList;
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// IBranch
public:
STDMETHOD(get_BranchAccountList)(/*[out, retval]*/ LPDISPATCH *pVal);
};
#endif //__BRANCH_H_
And here is branch.cpp:
// Branch.cpp : Implementation of CBranch
#include "stdafx.h"
#include "Server.h"
#include "BranchAccountList.h"
#include "Branch.h"
/////////////////////////////////////////////////////////////////////////////
// CBranch
STDMETHODIMP CBranch::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IBranch
};
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr,riid))
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP CBranch::get_BranchAccountList(LPDISPATCH *pVal)
{
/*-----------------------------------------------------------*/
/* The BranchAccountList collection is built by "procrastination." */
/* That is, it is not built until first asked for. Once */
/* built, it stays built for the life of the Top Level */
/* Object. That is, further references to the BranchAccountList */
/* property of the Top Level Object return the already */
/* created instance. */
/*-----------------------------------------------------------*/
LPDISPATCH pDisp = NULL;
HRESULT hr;
*pVal = NULL;
if (m_pBranchAccountList == NULL)
{
/*----------------------------------------------------*/
/* Create the BranchAccountList collection object, then */
/* invoke its InitCollection function (a user-defined */
/* function that initializes the collection). */
/*----------------------------------------------------*/
hr = CComObject<CBranchAccountList>::CreateInstance(&m_pBranchAccountList);
if (SUCCEEDED(hr))
{
m_pBranchAccountList->AddRef();
hr = m_pBranchAccountList->InitBranchAccountListCollection();
if (FAILED(hr))
{
delete m_pBranchAccountList;
m_pBranchAccountList = NULL;
return hr;
}
}
}
/*-----------------------------------------------*/
/* Return IDispatch pointer to BranchAccountList object */
/*-----------------------------------------------*/
hr = m_pBranchAccountList->QueryInterface (IID_IDispatch,(void **) pVal);
return hr;
}
Please any help is appreciated. Thanks.
John