- Timestamp:
- Jul 17, 2013 12:35:42 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Installer/InstallHelper/VBoxGuestInstallHelper.cpp
r46593 r47212 5 5 6 6 /* 7 * Copyright (C) 2011-201 2Oracle Corporation7 * Copyright (C) 2011-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 26 26 #include "exdll.h" 27 27 28 #include <iprt/err.h> 29 #include <iprt/initterm.h> 30 #include <iprt/localipc.h> 31 #include <iprt/mem.h> 32 #include <iprt/string.h> 33 28 34 /* Required structures/defines of VBoxTray. */ 29 35 #include "../../VBoxTray/VBoxTrayMsg.h" … … 49 55 PFNSFCFILEEXCEPTION g_pfnSfcFileException = NULL; 50 56 57 /** 58 * @todo Clean up this DLL, use more IPRT in here! 59 */ 51 60 52 61 /** … … 63 72 HRESULT hr = S_OK; 64 73 if (!g_stacktop || !*g_stacktop) 65 hr = __HRESULT_FROM_WIN32(ERROR_ EMPTY);74 hr = __HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE); 66 75 else 67 76 { … … 76 85 } 77 86 } 87 else 88 hr = __HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE); 78 89 } 79 90 return hr; … … 141 152 } 142 153 } 143 return hr;144 }145 146 static HANDLE vboxIPCConnect(void)147 {148 HANDLE hPipe = NULL;149 while (1)150 {151 hPipe = CreateFile(VBOXTRAY_PIPE_IPC, /* Pipe name. */152 GENERIC_READ | /* Read and write access. */153 GENERIC_WRITE,154 0, /* No sharing. */155 NULL, /* Default security attributes. */156 OPEN_EXISTING, /* Opens existing pipe. */157 0, /* Default attributes. */158 NULL); /* No template file. */159 160 /* Break if the pipe handle is valid. */161 if (hPipe != INVALID_HANDLE_VALUE)162 break;163 164 /* Exit if an error other than ERROR_PIPE_BUSY occurs. */165 if (GetLastError() != ERROR_PIPE_BUSY)166 return NULL;167 168 /* All pipe instances are busy, so wait for 20 seconds. */169 if (!WaitNamedPipe(VBOXTRAY_PIPE_IPC, 20000))170 return NULL;171 }172 173 /* The pipe connected; change to message-read mode. */174 DWORD dwMode = PIPE_READMODE_MESSAGE;175 BOOL fSuccess = SetNamedPipeHandleState(hPipe, /* Pipe handle. */176 &dwMode, /* New pipe mode. */177 NULL, /* Don't set maximum bytes. */178 NULL); /* Don't set maximum time. */179 if (!fSuccess)180 return NULL;181 return hPipe;182 }183 184 static void vboxIPCDisconnect(HANDLE hPipe)185 {186 CloseHandle(hPipe);187 }188 189 static HRESULT vboxIPCWriteMessage(HANDLE hPipe, BYTE *pMessage, DWORD cbMessage)190 {191 HRESULT hr = S_OK;192 DWORD cbWritten = 0;193 if (!WriteFile(hPipe, pMessage, cbMessage - cbWritten, &cbWritten, 0))194 hr = HRESULT_FROM_WIN32(GetLastError());195 154 return hr; 196 155 } … … 232 191 if (SUCCEEDED(hr)) 233 192 { 234 HMODULE hSFC = loadSystemDll("sfc_os.dll"); 193 HMODULE hSFC = loadSystemDll("sfc_os.dll"); /** @todo Replace this by RTLdr APIs. */ 235 194 if (NULL != hSFC) 236 195 { … … 445 404 EXDLL_INIT(); 446 405 447 VBOXTRAYIPCHEADER hdr; 448 hdr.ulMsg = VBOXTRAYIPCMSGTYPE_SHOWBALLOONMSG; 449 hdr.cbBody = sizeof(VBOXTRAYIPCMSG_SHOWBALLOONMSG); 450 451 VBOXTRAYIPCMSG_SHOWBALLOONMSG msg; 452 HRESULT hr = vboxPopString(msg.szContent, sizeof(msg.szContent) / sizeof(TCHAR)); 406 char szMsg[256]; 407 char szTitle[128]; 408 HRESULT hr = vboxPopString(szMsg, sizeof(szMsg) / sizeof(char)); 453 409 if (SUCCEEDED(hr)) 454 hr = vboxPopString(msg.szTitle, sizeof(msg.szTitle) / sizeof(TCHAR)); 410 hr = vboxPopString(szTitle, sizeof(szTitle) / sizeof(char)); 411 412 /** @todo Do we need to restore the stack on failure? */ 413 455 414 if (SUCCEEDED(hr)) 456 hr = vboxPopULong(&msg.ulType); 457 if (SUCCEEDED(hr)) 458 hr = vboxPopULong(&msg.ulShowMS); 459 460 if (SUCCEEDED(hr)) 461 { 462 msg.ulFlags = 0; 463 464 HANDLE hPipe = vboxIPCConnect(); 465 if (hPipe) 466 { 467 hr = vboxIPCWriteMessage(hPipe, (BYTE*)&hdr, sizeof(VBOXTRAYIPCHEADER)); 468 if (SUCCEEDED(hr)) 469 hr = vboxIPCWriteMessage(hPipe, (BYTE*)&msg, sizeof(VBOXTRAYIPCMSG_SHOWBALLOONMSG)); 470 vboxIPCDisconnect(hPipe); 471 } 415 { 416 RTR3InitDll(0); 417 418 uint32_t cbMsg = sizeof(VBOXTRAYIPCMSG_SHOWBALLOONMSG) 419 + strlen(szMsg) + 1 /* Include terminating zero */ 420 + strlen(szTitle) + 1; /* Dito. */ 421 Assert(cbMsg); 422 PVBOXTRAYIPCMSG_SHOWBALLOONMSG pIpcMsg = 423 (PVBOXTRAYIPCMSG_SHOWBALLOONMSG)RTMemAlloc(cbMsg); 424 if (pIpcMsg) 425 { 426 /* Stuff in the strings. */ 427 memcpy(pIpcMsg->szMsgContent, szMsg, strlen(szMsg) + 1); 428 memcpy(pIpcMsg->szMsgTitle, szTitle, strlen(szTitle) + 1); 429 430 /* Pop off the values in reverse order from the stack. */ 431 if (SUCCEEDED(hr)) 432 hr = vboxPopULong((ULONG*)&pIpcMsg->uType); 433 if (SUCCEEDED(hr)) 434 hr = vboxPopULong((ULONG*)&pIpcMsg->uShowMS); 435 436 if (SUCCEEDED(hr)) 437 { 438 RTLOCALIPCSESSION hSession; 439 int rc = RTLocalIpcSessionConnect(&hSession, VBOXTRAY_IPC_PIPENAME, 0 /* Flags */); 440 if (RT_SUCCESS(rc)) 441 { 442 VBOXTRAYIPCHEADER ipcHdr = { 0 /* Header version */, 443 VBOXTRAYIPCMSGTYPE_SHOWBALLOONMSG, cbMsg }; 444 445 rc = RTLocalIpcSessionWrite(hSession, &ipcHdr, sizeof(ipcHdr)); 446 if (RT_SUCCESS(rc)) 447 rc = RTLocalIpcSessionWrite(hSession, pIpcMsg, cbMsg); 448 449 int rc2 = RTLocalIpcSessionClose(hSession); 450 if (RT_SUCCESS(rc)) 451 rc = rc2; 452 } 453 454 if (RT_FAILURE(rc)) 455 hr = __HRESULT_FROM_WIN32(ERROR_BROKEN_PIPE); 456 } 457 458 RTMemFree(pIpcMsg); 459 } 460 else 461 hr = __HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); 472 462 } 473 463
Note:
See TracChangeset
for help on using the changeset viewer.