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 static RPC_BINDING_HANDLE LocalBindingHandle = NULL; 24 static HSTRING_TABLE LocalStringTable = NULL; 25 26 27 RPC_STATUS 28 PnpBindRpc(LPCWSTR pszMachine, 29 RPC_BINDING_HANDLE* BindingHandle) 30 { 31 PWSTR pszStringBinding = NULL; 32 RPC_STATUS Status; 33 34 Status = RpcStringBindingComposeW(NULL, 35 L"ncacn_np", 36 (LPWSTR)pszMachine, 37 L"\\pipe\\plugplay", 38 NULL, 39 &pszStringBinding); 40 if (Status != RPC_S_OK) 41 return Status; 42 43 Status = RpcBindingFromStringBindingW(pszStringBinding, 44 BindingHandle); 45 46 RpcStringFreeW(&pszStringBinding); 47 48 return Status; 49 } 50 51 52 RPC_STATUS 53 PnpUnbindRpc(RPC_BINDING_HANDLE *BindingHandle) 54 { 55 if (BindingHandle != NULL) 56 { 57 RpcBindingFree(*BindingHandle); 58 *BindingHandle = NULL; 59 } 60 61 return RPC_S_OK; 62 } 63 64 65 BOOL 66 PnpGetLocalHandles(RPC_BINDING_HANDLE *BindingHandle, 67 HSTRING_TABLE *StringTable) 68 { 69 if (LocalBindingHandle != NULL) 70 { 71 if (BindingHandle != NULL) 72 *BindingHandle = LocalBindingHandle; 73 74 if (StringTable != NULL) 75 *StringTable = LocalStringTable; 76 77 return TRUE; 78 } 79 80 LocalStringTable = pSetupStringTableInitialize(); 81 if (LocalStringTable == NULL) 82 return FALSE; 83 84 if (PnpBindRpc(NULL, &LocalBindingHandle) != RPC_S_OK) 85 { 86 pSetupStringTableDestroy(LocalStringTable); 87 return FALSE; 88 } 89 90 pSetupStringTableAddString(LocalStringTable, L"PLT", 1); 91 92 if (BindingHandle != NULL) 93 *BindingHandle = LocalBindingHandle; 94 95 if (StringTable != NULL) 96 *StringTable = LocalStringTable; 97 98 return TRUE; 99 } 100 101 102 RPC_STATUS 103 PnpUnbindLocalBindingHandle(VOID) 104 { 105 pSetupStringTableDestroy(LocalStringTable); 106 LocalStringTable = NULL; 107 return PnpUnbindRpc(&LocalBindingHandle); 108 } 109 110 111 void __RPC_FAR * __RPC_USER 112 midl_user_allocate(SIZE_T len) 113 { 114 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len); 115 } 116 117 118 void __RPC_USER 119 midl_user_free(void __RPC_FAR * ptr) 120 { 121 HeapFree(GetProcessHeap(), 0, ptr); 122 } 123 124 /* EOF */ 125