| 554 | |
| 555 | __drv_allocatesMem(object) |
| 556 | LPTSTR * GetRegMultiSz(_In_ HKEY hKey, _In_ LPCTSTR Val) |
| 557 | /*++ |
| 558 | |
| 559 | Routine Description: |
| 560 | |
| 561 | Get a multi-sz from registry |
| 562 | and return as an array of strings |
| 563 | |
| 564 | Arguments: |
| 565 | |
| 566 | hKey - Registry Key |
| 567 | Val - Value to query |
| 568 | |
| 569 | Return Value: |
| 570 | |
| 571 | array of strings. last entry+1 of array contains NULL |
| 572 | returns NULL on failure |
| 573 | |
| 574 | --*/ |
| 575 | { |
| 576 | LPTSTR buffer; |
| 577 | DWORD size; |
| 578 | DWORD reqSize; |
| 579 | DWORD dataType; |
| 580 | LPTSTR * array; |
| 581 | DWORD szChars; |
| 582 | LONG regErr; |
| 583 | |
| 584 | size = 8192; // initial guess, nothing magic about this |
| 585 | buffer = new TCHAR[(size/sizeof(TCHAR))+2]; |
| 586 | if(!buffer) { |
| 587 | return NULL; |
| 588 | } |
| 589 | reqSize = size; |
| 590 | regErr = RegQueryValueEx(hKey,Val,NULL,&dataType,(PBYTE)buffer,&reqSize); |
| 591 | while((regErr != NO_ERROR)) { |
| 592 | if(GetLastError() != ERROR_MORE_DATA) { |
| 593 | goto failed; |
| 594 | } |
| 595 | if(dataType != REG_MULTI_SZ) { |
| 596 | goto failed; |
| 597 | } |
| 598 | size = reqSize; |
| 599 | delete [] buffer; |
| 600 | buffer = new TCHAR[(size/sizeof(TCHAR))+2]; |
| 601 | if(!buffer) { |
| 602 | goto failed; |
| 603 | } |
| 604 | regErr = RegQueryValueEx(hKey,Val,NULL,&dataType,(PBYTE)buffer,&reqSize); |
| 605 | } |
| 606 | szChars = reqSize/sizeof(TCHAR); |
| 607 | buffer[szChars] = TEXT('\0'); |
| 608 | buffer[szChars+1] = TEXT('\0'); |
| 609 | |
| 610 | array = GetMultiSzIndexArray(buffer); |
| 611 | if(array) { |
| 612 | return array; |
| 613 | } |
no test coverage detected