OSDN Git Service

c3f01c2f0f474e1ab785231643810a4c98d9381c
[mingw/mingw-org-wsl.git] / include / rpcproxy.h
1 /**
2  * @file rpcproxy.h
3  * @copy 2012 MinGW.org project
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  * 
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 /*
25  *  -DREGISTER_PROXY_DLL Generates DllMain, DllRegisterServer, and
26  *    DllUnregisterServer
27  *  -DPROXY_CLSID=clsid Specifies a class ID to be used by the proxy DLL.
28  *  -DPROXY_CLSID_IS={..} Specifies the class ID to be used by the proxy DLL.
29  *  -DNT35_STRICT No new features
30 */
31 #ifndef _RPCPROXY_H
32 #define _RPCPROXY_H
33 #pragma GCC system_header
34
35 #if defined  __cplusplus  && !defined CINTERFACE
36 #warning "rpcproxy type definitions require CINTERFACE"
37 #else
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 #include <rpc.h>
42 #include <rpcndr.h>
43 #include <string.h>
44
45 #define CStdStubBuffer_METHODS CStdStubBuffer_QueryInterface,CStdStubBuffer_AddRef,\
46 CStdStubBuffer_Release,CStdStubBuffer_Connect,CStdStubBuffer_Disconnect,CStdStubBuffer_Invoke,\
47 CStdStubBuffer_IsIIDSupported,CStdStubBuffer_CountRefs,CStdStubBuffer_DebugServerQueryInterface,\
48 CStdStubBuffer_DebugServerRelease
49 #define IID_GENERIC_CHECK_IID(name,pIID,index) memcmp(pIID,name##_ProxyVtblList[index]->header.piid,16)
50 #define IID_BS_LOOKUP_SETUP int result, low=-1;
51 #define IID_BS_LOOKUP_INITIAL_TEST(name,sz,split) if ((result = name##_CHECK_IID(split))>0) { low=sz-split;} else if (!result) { low = split; goto found_label; }
52 #define IID_BS_LOOKUP_NEXT_TEST(name,split) if ((result = name##_CHECK_IID(low+split))>=0) { low=low+split; if (!result) goto found_label; }
53 #define IID_BS_LOOKUP_RETURN_RESULT(name,sz,index) low+=1; if ((low>=sz )||(result=name##_CHECK_IID(low))) goto not_found_label; found_label: (index)=low; return 1; not_found_label: return 0;
54 #define REGISTER_PROXY_DLL_ROUTINES(pProxyFileList, pClsID) \
55 HINSTANCE hProxyDll = 0; \
56 BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) \
57 { \
58 if(fdwReason == DLL_PROCESS_ATTACH) hProxyDll = hinstDLL; \
59 return TRUE; \
60 } \
61 HRESULT STDAPICALLTYPE DllRegisterServer(void) \
62 {\
63 return NdrDllRegisterProxy(hProxyDll, pProxyFileList, pClsID); \
64 }\
65 HRESULT STDAPICALLTYPE DllUnregisterServer(void)\
66 {\
67 return NdrDllUnregisterProxy(hProxyDll, pProxyFileList, pClsID);\
68 }
69 #ifdef PROXY_CLSID
70 #define CLSID_PSFACTORYBUFFER extern CLSID PROXY_CLSID;
71 #else
72 #ifdef PROXY_CLSID_IS
73 #define CLSID_PSFACTORYBUFFER const CLSID CLSID_PSFactoryBuffer = PROXY_CLSID_IS;
74 #define PROXY_CLSID CLSID_PSFactoryBuffer
75 #else
76 #define CLSID_PSFACTORYBUFFER
77 #endif
78 #endif
79 #ifndef PROXY_CLSID
80 #define GET_DLL_CLSID (aProxyFileList[0]->pStubVtblList[0] != 0 ? aProxyFileList[0]->pStubVtblList[0]->header.piid : 0)
81 #else
82 #define GET_DLL_CLSID &PROXY_CLSID
83 #endif
84 #define EXTERN_PROXY_FILE(name) EXTERN_C const ProxyFileInfo name##_ProxyFileInfo;
85 #define PROXYFILE_LIST_START const ProxyFileInfo * aProxyFileList[] = {
86 #define REFERENCE_PROXY_FILE(name) & name##_ProxyFileInfo
87 #define PROXYFILE_LIST_END 0 };
88 #define DLLDATA_GETPROXYDLLINFO(pPFList,pClsid) \
89 void RPC_ENTRY GetProxyDllInfo( const ProxyFileInfo*** pInfo, const CLSID ** pId ) \
90 { *pInfo = pPFList; *pId = pClsid; };
91 #define DLLGETCLASSOBJECTROUTINE(pPFlist, pClsid,pFactory) HRESULT STDAPICALLTYPE DllGetClassObject(REFCLSID rclsid,REFIID riid,void **ppv) \
92 { return NdrDllGetClassObject(rclsid,riid,ppv,pPFlist,pClsid,pFactory ); }
93 #define DLLCANUNLOADNOW(pFactory) HRESULT STDAPICALLTYPE DllCanUnloadNow(void) \
94 { return NdrDllCanUnloadNow( pFactory ); }
95 #define DLLDUMMYPURECALL void __cdecl _purecall(void) { }
96 #define CSTDSTUBBUFFERRELEASE(pFactory) ULONG STDMETHODCALLTYPE CStdStubBuffer_Release(IRpcStubBuffer *This) \
97 { return NdrCStdStubBuffer_Release(This,(IPSFactoryBuffer *)pFactory); }
98 #ifdef PROXY_DELEGATION
99 #define CSTDSTUBBUFFER2RELEASE(pFactory) ULONG STDMETHODCALLTYPE CStdStubBuffer2_Release(IRpcStubBuffer *This) \
100 { return NdrCStdStubBuffer2_Release(This,(IPSFactoryBuffer *)pFactory); }
101 #else
102 #define CSTDSTUBBUFFER2RELEASE(pFactory)
103 #endif
104
105 #ifdef REGISTER_PROXY_DLL
106 #define DLLREGISTRY_ROUTINES(pProxyFileList,pClsID ) REGISTER_PROXY_DLL_ROUTINES(pProxyFileList,pClsID)
107 #else
108 #define DLLREGISTRY_ROUTINES(pProxyFileList,pClsID)
109 #endif
110 #define DLLDATA_ROUTINES(pProxyFileList,pClsID) \
111 CLSID_PSFACTORYBUFFER \
112 CStdPSFactoryBuffer gPFactory = {0,0,0,0}; \
113 DLLDATA_GETPROXYDLLINFO(pProxyFileList,pClsID) \
114 DLLGETCLASSOBJECTROUTINE(pProxyFileList,pClsID,&gPFactory) \
115 DLLCANUNLOADNOW(&gPFactory) \
116 CSTDSTUBBUFFERRELEASE(&gPFactory) \
117 CSTDSTUBBUFFER2RELEASE(&gPFactory) \
118 DLLDUMMYPURECALL \
119 DLLREGISTRY_ROUTINES(pProxyFileList, pClsID)
120
121 #define DLLDATA_STANDARD_ROUTINES DLLDATA_ROUTINES( (const ProxyFileInfo**) pProxyFileList, &CLSID_PSFactoryBuffer)
122
123 struct tagCInterfaceStubVtbl;
124 struct tagCInterfaceProxyVtbl;
125 typedef struct tagCInterfaceStubVtbl *PCInterfaceStubVtblList;
126 typedef struct tagCInterfaceProxyVtbl *PCInterfaceProxyVtblList;
127 typedef const char *PCInterfaceName;
128 typedef int __stdcall IIDLookupRtn(const IID*,int*);
129 typedef IIDLookupRtn *PIIDLookup;
130 typedef struct tagProxyFileInfo {
131     const PCInterfaceProxyVtblList *pProxyVtblList;
132     const PCInterfaceStubVtblList *pStubVtblList;
133     const PCInterfaceName * pNamesArray;
134     const IID ** pDelegatedIIDs;
135     const PIIDLookup pIIDLookupRtn;
136     unsigned short TableSize;
137     unsigned short TableVersion;
138     unsigned long Filler1;
139     unsigned long Filler2;
140     unsigned long Filler3;
141     unsigned long Filler4;
142 }ProxyFileInfo;
143 typedef ProxyFileInfo ExtendedProxyFileInfo;
144
145 typedef struct tagCInterfaceProxyHeader {
146 #ifdef USE_STUBLESS_PROXY
147     const void *pStublessProxyInfo;
148 #endif
149     const IID *piid;
150 } CInterfaceProxyHeader;
151 typedef struct tagCInterfaceProxyVtbl {
152     CInterfaceProxyHeader header;
153 __extension__ void *Vtbl[0];
154 } CInterfaceProxyVtbl;
155
156 typedef void (__RPC_STUB *PRPC_STUB_FUNCTION)(IRpcStubBuffer*,IRpcChannelBuffer*,PRPC_MESSAGE,DWORD*);
157 typedef struct tagCInterfaceStubHeader {
158     const IID *piid;
159     const MIDL_SERVER_INFO *pServerInfo;
160     unsigned long DispatchTableCount;
161     const PRPC_STUB_FUNCTION *pDispatchTable;
162 } CInterfaceStubHeader;
163 typedef struct tagCInterfaceStubVtbl {
164     CInterfaceStubHeader header;
165     IRpcStubBufferVtbl Vtbl;
166 } CInterfaceStubVtbl;
167 typedef struct tagCStdStubBuffer {
168     const struct IRpcStubBufferVtbl * lpVtbl;
169     long RefCount;
170     struct IUnknown *pvServerObject;
171     const struct ICallFactoryVtbl * pCallFactoryVtbl;
172     const IID * pAsyncIID;
173     struct IPSFactoryBuffer * pPSFactory;
174     const struct IReleaseMarshalBuffersVtbl * pRMBVtbl;
175 } CStdStubBuffer;
176 typedef struct tagCStdPSFactoryBuffer {
177     const IPSFactoryBufferVtbl *lpVtbl;
178     long RefCount;
179     const ProxyFileInfo ** pProxyFileList;
180     long Filler1;
181 } CStdPSFactoryBuffer;
182 void RPC_ENTRY NdrProxyInitialize(void*,PRPC_MESSAGE,PMIDL_STUB_MESSAGE,PMIDL_STUB_DESC,unsigned int);
183 void RPC_ENTRY NdrProxyGetBuffer(void*,PMIDL_STUB_MESSAGE);
184 void RPC_ENTRY NdrProxySendReceive(void*,MIDL_STUB_MESSAGE*);
185 void RPC_ENTRY NdrProxyFreeBuffer(void*,MIDL_STUB_MESSAGE*);
186 HRESULT RPC_ENTRY NdrProxyErrorHandler(DWORD);
187 void RPC_ENTRY NdrStubInitialize(PRPC_MESSAGE,PMIDL_STUB_MESSAGE,PMIDL_STUB_DESC,IRpcChannelBuffer*);
188 void __RPC_STUB NdrStubForwardingFunction(IRpcStubBuffer*,IRpcChannelBuffer*,PRPC_MESSAGE,DWORD*);
189 void RPC_ENTRY NdrStubGetBuffer(IRpcStubBuffer*,IRpcChannelBuffer*,PMIDL_STUB_MESSAGE);
190 HRESULT RPC_ENTRY NdrStubErrorHandler(DWORD);
191 HRESULT STDMETHODCALLTYPE CStdStubBuffer_QueryInterface(IRpcStubBuffer*,REFIID,void**);
192 ULONG STDMETHODCALLTYPE CStdStubBuffer_AddRef(IRpcStubBuffer*);
193 ULONG STDMETHODCALLTYPE CStdStubBuffer_Release(IRpcStubBuffer*);
194 ULONG STDMETHODCALLTYPE NdrCStdStubBuffer_Release(IRpcStubBuffer*,IPSFactoryBuffer*);
195 HRESULT STDMETHODCALLTYPE CStdStubBuffer_Connect(IRpcStubBuffer*,IUnknown*);
196 void STDMETHODCALLTYPE CStdStubBuffer_Disconnect(IRpcStubBuffer*);
197 HRESULT STDMETHODCALLTYPE CStdStubBuffer_Invoke(IRpcStubBuffer*,RPCOLEMESSAGE*,IRpcChannelBuffer*);
198 IRpcStubBuffer* STDMETHODCALLTYPE CStdStubBuffer_IsIIDSupported(IRpcStubBuffer*,REFIID);
199 ULONG STDMETHODCALLTYPE CStdStubBuffer_CountRefs(IRpcStubBuffer*);
200 HRESULT STDMETHODCALLTYPE CStdStubBuffer_DebugServerQueryInterface(IRpcStubBuffer*,void**);
201 void STDMETHODCALLTYPE CStdStubBuffer_DebugServerRelease(IRpcStubBuffer*,void*);
202 HRESULT RPC_ENTRY NdrDllGetClassObject(REFCLSID,REFIID,void**,const ProxyFileInfo**,const CLSID*,CStdPSFactoryBuffer*);
203 HRESULT RPC_ENTRY NdrDllCanUnloadNow(CStdPSFactoryBuffer*);
204 #ifndef NT35_STRICT
205 HRESULT RPC_ENTRY NdrDllRegisterProxy(HMODULE,const ProxyFileInfo**,const CLSID*);
206 HRESULT RPC_ENTRY NdrDllUnregisterProxy(HMODULE,const ProxyFileInfo**,const CLSID*);
207 #define STUB_FORWARDING_FUNCTION NdrStubForwardingFunction
208 ULONG STDMETHODCALLTYPE
209 CStdStubBuffer2_Release(IRpcStubBuffer*);
210 ULONG STDMETHODCALLTYPE
211 NdrCStdStubBuffer2_Release(IRpcStubBuffer*,IPSFactoryBuffer*);
212 #define CStdStubBuffer_DELEGATING_METHODS 0, 0, CStdStubBuffer2_Release, 0, 0, 0, 0, 0, 0, 0
213 #endif
214
215 #ifdef __cplusplus
216 }
217 #endif
218 #endif  /* defined  __cplusplus  && !defined CINTERFACE  */
219 #endif  /* ndef _RPCPROXY_H  */
220