Click here to Skip to main content
15,921,716 members
Home / Discussions / COM
   

COM

 
AnswerRe: "component not correctly registered" error when Office 2007 installed Pin
«_Superman_»7-Oct-09 14:16
professional«_Superman_»7-Oct-09 14:16 
AnswerRe: "component not correctly registered" error when Office 2007 installed Pin
Md. Marufuzzaman9-Oct-09 9:04
professionalMd. Marufuzzaman9-Oct-09 9:04 
AnswerRe: "component not correctly registered" error when Office 2007 installed Pin
Md. Marufuzzaman9-Oct-09 9:05
professionalMd. Marufuzzaman9-Oct-09 9:05 
Questioncreating a web interface for windows media services, in server 2003 Pin
ramitha7772-Oct-09 17:20
ramitha7772-Oct-09 17:20 
QuestionCOM Tutorials Pin
msr_codeproject2-Oct-09 16:33
msr_codeproject2-Oct-09 16:33 
AnswerRe: COM Tutorials Pin
Richard MacCutchan2-Oct-09 22:43
mveRichard MacCutchan2-Oct-09 22:43 
AnswerRe: COM Tutorials Pin
cariolihome18-Oct-09 10:54
cariolihome18-Oct-09 10:54 
QuestionGet Events from an COM Server Pin
Juergen_802-Oct-09 4:16
Juergen_802-Oct-09 4:16 
Hi All,

now I get connected in my main.cpp file to the server. I hope this will be correct. But how can I get now an event from the server? The server sends some events. I can see that because an Message Dialog will be opened from the server.

Now my questions are the following:

a)
Is the code until now correct? Is it possible to make a test if I get the correct connection or anything else?

b)
How can I get in the main.cpp an event (OnShowMessageDlg) or any message from the server? Do I need to add something to the sink class?

c)
Must I add something in the Sink class to get the an event in the invoke function? Or how should this work?


Let me know If you need any more information.

Once more, thanks for any help.

Juergen

main.cpp File
CComPtr<ICWOLE2> tCWOLE;
HRESULT hr;
hr = CoInitialize(0);

hr = CoCreateInstance(CLSID_CWOLEv2, 0, CLSCTX_LOCAL_SERVER, IID_ICWOLE2, (void**)&tCWOLE);
IConnectionPointContainer   * pConnPtContainer;
hr = tCWOLE->QueryInterface(IID_IConnectionPointContainer,(void**)&pConnPtContainer);
if(FAILED(hr)){
	CoUninitialize();
	return false;
}
CComPtr<IConnectionPoint> ICPoint;
hr = pConnPtContainer->FindConnectionPoint(DIID_ICWOLEEvents,&m_pConnectionPoint);
if(FAILED(hr)){
	CoUninitialize();
	return false;
}

m_sink = new CSink;
LPUNKNOWN pUnk = NULL;
m_sink->QueryInterface(IID_IUnknown,(void**)&pUnk);
hr = m_pConnectionPoint->Advise(pUnk,&m_sink->cookie);
if(FAILED(hr)){
	CoUninitialize();
	return false;
}
pConnPtContainer->Release();
.
.
.
// Here I must get the event from the COM Server, but how can this be done???
// How can I test if I get the information from the correct class??
.
.
.

m_pConnectionPoint->Unadvise(m_sink->cookie);
m_pConnectionPoint->Release();
m_sink->Release();



CSink.h
class CSink : public ICWOLEEvents
{
	public:
		
		CSink::CSink() {m_refCount = 1, cookie = 0;}
		CSink::~CSink()	{}
		
		STDMETHODIMP QueryInterface(REFIID riid, void ** ppvObj); //HRESULT _stdcall
		STDMETHODIMP_(ULONG) AddRef();  // Note the underscore
		STDMETHODIMP_(ULONG) Release();
	
		
		STDMETHODIMP GetTypeInfoCount(UINT *iTInfo);
		STDMETHODIMP GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo);
		STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR **rgszNames, UINT cNames,  LCID lcid, DISPID *rgDispId);
		STDMETHODIMP Invoke(DISPID dispIdMember, 
							REFIID riid, 
							LCID lcid,
							WORD wFlags, DISPPARAMS* pDispParams,
							VARIANT* pVarResult, EXCEPINFO* pExcepInfo,
							UINT* puArgErr);
		
		
		
    public:
		int m_refCount;
		DWORD cookie;
		//void OnConfigurationApply(VARIANT_BOOL *pAccept);
		void OnShowMessageDlg(IMsgDlg *pIMsg, VARIANT_BOOL *Result);

};


CSink.cpp
HRESULT CSink::QueryInterface(REFIID riid, void ** ppvObj)
{

	if (riid == IID_IUnknown){
		*ppvObj = static_cast<void*>(this);
	}
	
	else if (riid == DIID_ICWOLEEvents){
		*ppvObj = static_cast<ICWOLEEvents*>(this);
	}
	else if (riid == IID_IDispatch){
		*ppvObj = static_cast<IDispatch*>(this);
	}
	
	else
	{
	    char clsidStr[256];
	    WCHAR wClsidStr[256];
	    char txt[512];
		
	    StringFromGUID2(riid, (LPOLESTR)&wClsidStr, 256);
		
	    // Convert down to ANSI
	    WideCharToMultiByte(CP_ACP, 0, wClsidStr, -1, clsidStr, 256, NULL, NULL);
		
	    sprintf(txt, "riid is : %s: Unsupported Interface", clsidStr);
		
		*ppvObj = NULL;
		return E_NOINTERFACE;
	}
	
	static_cast<IUnknown*>(*ppvObj)->AddRef();
	return S_OK;
}
/******************************************************************************/
STDMETHODIMP_(ULONG) CSink::AddRef()
{
	return ++m_refCount;
}
/******************************************************************************/
STDMETHODIMP_(ULONG) CSink::AddRef()
{
	return ++m_refCount;
}
/******************************************************************************/
STDMETHODIMP_(ULONG) CSink::Release()
{
	if (--m_refCount == 0)
	{
		delete this;
		return 0;
	}
	return m_refCount;
}
/******************************************************************************/
STDMETHODIMP CSink::GetTypeInfoCount(UINT *iTInfo)
{
	return E_NOTIMPL;
}
/******************************************************************************/
STDMETHODIMP CSink::GetTypeInfo(UINT iTInfo, LCID lcid, 
                                       ITypeInfo **ppTInfo)
{
	
	return E_NOTIMPL;
}
/******************************************************************************/
STDMETHODIMP CSink::GetIDsOfNames(REFIID riid,  
                                         OLECHAR **rgszNames, 
                                         UINT cNames,  LCID lcid,
                                         DISPID *rgDispId)
{
	HRESULT hr = E_FAIL;
	return hr;
}
/******************************************************************************/
STDMETHODIMP CSink::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
                                  WORD wFlags, DISPPARAMS* pDispParams,
                                  VARIANT* pVarResult, EXCEPINFO* pExcepInfo,
                                  UINT* puArgErr)
{

	if ((riid != IID_NULL))
		return E_INVALIDARG;
	
	HRESULT hr = S_OK;  // Initialize
	
	
	return hr;
}
/******************************************************************************/
void CSink::OnShowMessageDlg(IMsgDlg *pIMsg, VARIANT_BOOL *Result){
	// Is this correct???
}


Test.idl
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: test_programm.exe
[
  uuid(90B4344B-90CD-4527-BC00-4F4D45C793D6),
  version(2.13),
  helpstring("CW  CWOLE")
]
library CW_CWOLE
{
    // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("stdole2.tlb");

    // Forward declare all types defined in this typelib
    interface ICWOLE2;
    dispinterface ICWOLEEvents;
.
.
.
.
.

    [
      uuid(6775FB91-B5BE-11D6-A996-0050BA24C7B9),
      version(1.1),
      helpstring("Event dispatch interface for CW CWOLE")
    ]
    dispinterface ICWOLEEvents {
        properties:
        methods:
            [id(0x00000001)]
            void OnConfigurationApply([in, out] VARIANT_BOOL* pAccept);
            [id(0x00000002)]
            void OnShowMessageDlg(
                            [in] IMsgDlg* pIMsg, 
                            [out, retval] VARIANT_BOOL* Result);
    };

    typedef [uuid(5CBBA151-1C47-4D6C-B14C-C527E333F812), version(1.2)]
    enum {
        ECS_DEFAULT = 0,
        ECS_FRONT = 1,
        ECS_LEFT = 2,
        ECS_RIGHT = 3,
        ECS_LEFTUP = 4,
        ECS_RIGHTUP = 5,
        ECS_TOP = 6,
        ECS_BACK = 7,
        ECS_BACKLEFTUP = 8,
        ECS_BACKRIGHTUP = 9,
        ECS_BOTTOM = 10
    } ECamSetup;

    typedef [uuid(9545E3CA-6401-4418-A040-DA3A89E2C792), version(1.3)]
    enum {
        EPM_PERSP = 0,
        EPM_ORTHO = 1,
        EPM_2D = 2
    } EProjectionMode;

    [
      uuid(F560F763-2948-11D7-A9BF-0050BA24C7B9),
      version(2.13),
      helpstring("CWOLE2")
    ]
    coclass CWOLEv2 {
        [default] interface ICWOLE2;
        [default, source] dispinterface ICWOLEEvents;
    };

AnswerRe: Get Events from an COM Server Pin
Stuart Dootson2-Oct-09 5:46
professionalStuart Dootson2-Oct-09 5:46 
GeneralRe: Get Events from an COM Server Pin
Juergen_804-Oct-09 22:55
Juergen_804-Oct-09 22:55 
GeneralRe: Get Events from an COM Server Pin
Stuart Dootson5-Oct-09 0:00
professionalStuart Dootson5-Oct-09 0:00 
GeneralRe: Get Events from an COM Server Pin
Juergen_805-Oct-09 0:07
Juergen_805-Oct-09 0:07 
GeneralRe: Get Events from an COM Server Pin
Stuart Dootson5-Oct-09 0:15
professionalStuart Dootson5-Oct-09 0:15 
GeneralRe: Get Events from an COM Server Pin
Juergen_805-Oct-09 4:05
Juergen_805-Oct-09 4:05 
GeneralRe: Get Events from an COM Server Pin
Stuart Dootson5-Oct-09 4:19
professionalStuart Dootson5-Oct-09 4:19 
GeneralRe: Get Events from an COM Server Pin
Juergen_808-Oct-09 2:36
Juergen_808-Oct-09 2:36 
GeneralRe: Get Events from an COM Server Pin
Stuart Dootson8-Oct-09 7:44
professionalStuart Dootson8-Oct-09 7:44 
AnswerRe: Get Events from an COM Server Pin
Juergen_802-Nov-09 2:49
Juergen_802-Nov-09 2:49 
QuestionHow to update DOM in IE by using IHTMLDocument , and IHTMLElement Pin
am 20091-Oct-09 7:17
am 20091-Oct-09 7:17 
QuestionGetting Excel sheet names Pin
gtag1-Oct-09 1:01
gtag1-Oct-09 1:01 
AnswerRe: Getting Excel sheet names Pin
Stuart Dootson1-Oct-09 22:16
professionalStuart Dootson1-Oct-09 22:16 
GeneralRe: Getting Excel sheet names [modified] Pin
gtag2-Oct-09 6:17
gtag2-Oct-09 6:17 
GeneralRe: Getting Excel sheet names Pin
Stuart Dootson2-Oct-09 8:59
professionalStuart Dootson2-Oct-09 8:59 
GeneralRe: Getting Excel sheet names Pin
gtag2-Oct-09 23:53
gtag2-Oct-09 23:53 
GeneralRe: Getting Excel sheet names Pin
Stuart Dootson3-Oct-09 0:11
professionalStuart Dootson3-Oct-09 0:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.