71ff88425703f6a751d4834bf407b629e8ce5101
[reactos.git] / dll / win32 / setupapi / rpc.c
1 /*
2 * RPC support routines
3 *
4 * Copyright 2005 Eric Kohl
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "setupapi_private.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
24
25 static RPC_BINDING_HANDLE LocalBindingHandle = NULL;
26 static HSTRING_TABLE LocalStringTable = NULL;
27
28
29 RPC_STATUS
30 PnpBindRpc(LPCWSTR pszMachine,
31 RPC_BINDING_HANDLE* BindingHandle)
32 {
33 PWSTR pszStringBinding = NULL;
34 RPC_STATUS Status;
35
36 Status = RpcStringBindingComposeW(NULL,
37 L"ncacn_np",
38 (LPWSTR)pszMachine,
39 L"\\pipe\\umpnpmgr",
40 NULL,
41 &pszStringBinding);
42 if (Status != RPC_S_OK)
43 return Status;
44
45 Status = RpcBindingFromStringBindingW(pszStringBinding,
46 BindingHandle);
47
48 RpcStringFreeW(&pszStringBinding);
49
50 return Status;
51 }
52
53
54 RPC_STATUS
55 PnpUnbindRpc(RPC_BINDING_HANDLE *BindingHandle)
56 {
57 if (BindingHandle != NULL)
58 {
59 RpcBindingFree(*BindingHandle);
60 *BindingHandle = NULL;
61 }
62
63 return RPC_S_OK;
64 }
65
66
67 BOOL
68 PnpGetLocalHandles(RPC_BINDING_HANDLE *BindingHandle,
69 HSTRING_TABLE *StringTable)
70 {
71 if (LocalBindingHandle != NULL)
72 {
73 if (BindingHandle != NULL)
74 *BindingHandle = LocalBindingHandle;
75
76 if (StringTable != NULL)
77 *StringTable = LocalStringTable;
78
79 return TRUE;
80 }
81
82 LocalStringTable = StringTableInitialize();
83 if (LocalStringTable == NULL)
84 return FALSE;
85
86 if (PnpBindRpc(NULL, &LocalBindingHandle) != RPC_S_OK)
87 {
88 StringTableDestroy(LocalStringTable);
89 return FALSE;
90 }
91
92 StringTableAddString(LocalStringTable, L"PLT", 1);
93
94 if (BindingHandle != NULL)
95 *BindingHandle = LocalBindingHandle;
96
97 if (StringTable != NULL)
98 *StringTable = LocalStringTable;
99
100 return TRUE;
101 }
102
103
104 RPC_STATUS
105 PnpUnbindLocalBindingHandle(VOID)
106 {
107 StringTableDestroy(LocalStringTable);
108 LocalStringTable = NULL;
109 return PnpUnbindRpc(&LocalBindingHandle);
110 }
111
112
113 void __RPC_FAR * __RPC_USER
114 midl_user_allocate(size_t len)
115 {
116 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
117 }
118
119
120 void __RPC_USER
121 midl_user_free(void __RPC_FAR * ptr)
122 {
123 HeapFree(GetProcessHeap(), 0, ptr);
124 }
125
126 /* EOF */