source: trunk/Utilities/JsObjectDispatch/Foo.h @ 124

Last change on this file since 124 was 124, checked in by roman, 12 years ago
  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1////////////////////////////////////////////////////////////
2// Copyright (C) Roman Ryltsov, 2008-2012
3// Created by Roman Ryltsov roman@alax.info
4//
5// $Id: Foo.h 124 2012-09-15 12:27:26Z roman $
6
7#pragma once
8
9#include <atlstr.h>
10#include "resource.h"       // main symbols
11#include "JsObjectDispatch_i.h"
12
13#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
14#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
15#endif
16
17using namespace ATL;
18
19// CFoo
20
21class ATL_NO_VTABLE CFoo :
22        public CComObjectRootEx<CComSingleThreadModel>,
23        public CComCoClass<CFoo, &CLSID_Foo>,
24        public IDispatchImpl<IFoo>
25{
26public:
27
28DECLARE_REGISTRY_RESOURCEID(IDR_FOO)
29
30BEGIN_COM_MAP(CFoo)
31        COM_INTERFACE_ENTRY(IFoo)
32        COM_INTERFACE_ENTRY(IDispatch)
33END_COM_MAP()
34
35public:
36// CFoo
37        static VOID TraceProperty(CComPtr<IDispatch> pDispatch, DISPID nIdentifier, BOOL bTraceGetResultFailure = TRUE)
38        {
39                CComVariant vPropertyValue;
40                const HRESULT nGetResult = pDispatch.GetProperty(nIdentifier, &vPropertyValue);
41                if(SUCCEEDED(nGetResult))
42                {
43                        CComVariant vStringPropertyValue;
44                        const HRESULT nChangeTypeResult = vStringPropertyValue.ChangeType(VT_BSTR, &vPropertyValue);
45                        if(SUCCEEDED(nChangeTypeResult))
46                        {
47                                ATLTRACE(_T("nIdentifier 0x%x, vPropertyValue.vt 0x%x, vStringPropertyValue.bstrVal \"%s\"\n"), nIdentifier, vPropertyValue.vt, CString(vStringPropertyValue.bstrVal));
48                        } else
49                                ATLTRACE(_T("nIdentifier 0x%x, vPropertyValue.vt 0x%x, nChangeTypeResult 0x%08x\n"), nIdentifier, vPropertyValue.vt, nChangeTypeResult);
50                } else
51                        if(bTraceGetResultFailure)
52                                ATLTRACE(_T("nIdentifier 0x%x, nGetResult 0x%08x\n"), nIdentifier, nGetResult);
53        }
54        static VOID TraceProperty(CComPtr<IDispatch> pDispatch, LPCWSTR pszName, BOOL bTraceGetResultFailure = TRUE)
55        {
56                ATLASSERT(pszName);
57                CComVariant vPropertyValue;
58                const HRESULT nGetResult = pDispatch.GetPropertyByName(pszName, &vPropertyValue);
59                if(SUCCEEDED(nGetResult))
60                {
61                        CComVariant vStringPropertyValue;
62                        const HRESULT nChangeTypeResult = vStringPropertyValue.ChangeType(VT_BSTR, &vPropertyValue);
63                        if(SUCCEEDED(nChangeTypeResult))
64                        {
65                                ATLTRACE(_T("pszName %ls, vPropertyValue.vt 0x%x, vStringPropertyValue.bstrVal \"%s\"\n"), pszName, vPropertyValue.vt, CString(vStringPropertyValue.bstrVal));
66                        } else
67                                ATLTRACE(_T("pszName %ls, vPropertyValue.vt 0x%x, nChangeTypeResult 0x%08x\n"), pszName, vPropertyValue.vt, nChangeTypeResult);
68                } else
69                        if(bTraceGetResultFailure)
70                                ATLTRACE(_T("pszName %ls, nGetResult 0x%08x\n"), pszName, nGetResult);
71        }
72
73// IFoo
74        STDMETHOD(Bar)(VARIANT vValue) throw()
75        {
76                ATLTRACE(_T("-------- vValue.vt 0x%x -------- -------- --------\n"), vValue.vt);
77                if(vValue.vt != VT_DISPATCH)
78                {
79                        ATLTRACE(_T("vValue.lVal 0x%x\n"), vValue.lVal);
80                        return S_FALSE;
81                }
82                ATLASSERT(vValue.vt == VT_DISPATCH);
83                CComQIPtr<IDispatchEx> pDispatchEx = vValue.pdispVal;
84                #if defined(_DEBUG)
85                if(pDispatchEx)
86                {
87                        DISPID nIdentifier = DISPID_STARTENUM;
88                        for(; ; )
89                        {
90                                if(pDispatchEx->GetNextDispID(fdexEnumAll, nIdentifier, &nIdentifier) != S_OK)
91                                        break;
92                                CComBSTR sName;
93                                ATLVERIFY(SUCCEEDED(pDispatchEx->GetMemberName(nIdentifier, &sName)));
94                                ATLTRACE(_T("nIdentifier %d, sName %s\n"), nIdentifier, CString(sName));
95                                TraceProperty((IDispatchEx*) pDispatchEx, sName);
96                        }
97                }
98                #endif // defined(_DEBUG)
99                //TraceProperty(vValue.pdispVal, (DISPID) DISPID_VALUE);
100                for(DISPID nIdentifier = -1000; nIdentifier <= 1000; nIdentifier++)
101                        TraceProperty(vValue.pdispVal, nIdentifier, FALSE);
102                return S_OK;
103        }
104};
105
106OBJECT_ENTRY_AUTO(__uuidof(Foo), CFoo)
Note: See TracBrowser for help on using the repository browser.