Make the MSI icon control work.
[wine/multimedia.git] / dlls / msi / record.c
blob8bdc3c4cf479c0e0a0b9c23b5daeffd7b847f26c
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002-2004 Mike McCormack for CodeWeavers
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winerror.h"
29 #include "wine/debug.h"
30 #include "msi.h"
31 #include "msiquery.h"
32 #include "msipriv.h"
33 #include "objidl.h"
34 #include "winnls.h"
35 #include "ole2.h"
37 #include "winreg.h"
38 #include "shlwapi.h"
40 #include "query.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msi);
44 #define MSIFIELD_NULL 0
45 #define MSIFIELD_INT 1
46 #define MSIFIELD_STR 2
47 #define MSIFIELD_WSTR 3
48 #define MSIFIELD_STREAM 4
50 static void MSI_FreeField( MSIFIELD *field )
52 switch( field->type )
54 case MSIFIELD_NULL:
55 case MSIFIELD_INT:
56 break;
57 case MSIFIELD_WSTR:
58 HeapFree( GetProcessHeap(), 0, field->u.szwVal);
59 break;
60 case MSIFIELD_STREAM:
61 IStream_Release( field->u.stream );
62 break;
63 default:
64 ERR("Invalid field type %d\n", field->type);
68 static void MSI_CloseRecord( MSIOBJECTHDR *arg )
70 MSIRECORD *rec = (MSIRECORD *) arg;
71 UINT i;
73 for( i=0; i<=rec->count; i++ )
74 MSI_FreeField( &rec->fields[i] );
77 MSIRECORD *MSI_CreateRecord( unsigned int cParams )
79 MSIRECORD *rec;
80 UINT len;
82 TRACE("%d\n", cParams);
84 if( cParams>65535 )
85 return NULL;
87 len = sizeof (MSIRECORD) + sizeof (MSIFIELD)*cParams;
88 rec = alloc_msiobject( MSIHANDLETYPE_RECORD, len, MSI_CloseRecord );
89 if( rec )
90 rec->count = cParams;
91 return rec;
94 MSIHANDLE WINAPI MsiCreateRecord( unsigned int cParams )
96 MSIRECORD *rec;
97 MSIHANDLE ret = 0;
99 TRACE("%d\n", cParams);
101 rec = MSI_CreateRecord( cParams );
102 if( rec )
103 ret = alloc_msihandle( &rec->hdr );
104 msiobj_release( &rec->hdr );
105 return ret;
108 unsigned int MSI_RecordGetFieldCount( MSIRECORD *rec )
110 return rec->count;
113 unsigned int WINAPI MsiRecordGetFieldCount( MSIHANDLE handle )
115 MSIRECORD *rec;
116 UINT ret;
118 TRACE("%ld\n", handle );
120 rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
121 if( !rec )
122 return -1;
124 msiobj_lock( &rec->hdr );
125 ret = MSI_RecordGetFieldCount( rec );
126 msiobj_unlock( &rec->hdr );
127 msiobj_release( &rec->hdr );
129 return ret;
132 static BOOL string2intW( LPCWSTR str, int *out )
134 int x = 0;
135 LPCWSTR p = str;
137 if( *p == '-' ) /* skip the minus sign */
138 p++;
139 while ( *p )
141 if( (*p < '0') || (*p > '9') )
142 return FALSE;
143 x *= 10;
144 x += (*p - '0');
145 p++;
148 if( str[0] == '-' ) /* check if it's negative */
149 x = -x;
150 *out = x;
152 return TRUE;
155 int MSI_RecordGetInteger( MSIRECORD *rec, unsigned int iField)
157 int ret = 0;
159 TRACE("%p %d\n", rec, iField );
161 if( iField > rec->count )
162 return MSI_NULL_INTEGER;
164 switch( rec->fields[iField].type )
166 case MSIFIELD_INT:
167 return rec->fields[iField].u.iVal;
168 case MSIFIELD_WSTR:
169 if( string2intW( rec->fields[iField].u.szwVal, &ret ) )
170 return ret;
171 return MSI_NULL_INTEGER;
172 default:
173 break;
176 return MSI_NULL_INTEGER;
179 int WINAPI MsiRecordGetInteger( MSIHANDLE handle, unsigned int iField)
181 MSIRECORD *rec;
182 UINT ret;
184 TRACE("%ld %d\n", handle, iField );
186 rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
187 if( !rec )
188 return MSI_NULL_INTEGER;
190 msiobj_lock( &rec->hdr );
191 ret = MSI_RecordGetInteger( rec, iField );
192 msiobj_unlock( &rec->hdr );
193 msiobj_release( &rec->hdr );
195 return ret;
198 UINT WINAPI MsiRecordClearData( MSIHANDLE handle )
200 MSIRECORD *rec;
201 UINT i;
203 TRACE("%ld\n", handle );
205 rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
206 if( !rec )
207 return ERROR_INVALID_HANDLE;
209 msiobj_lock( &rec->hdr );
210 for( i=0; i<=rec->count; i++)
212 MSI_FreeField( &rec->fields[i] );
213 rec->fields[i].type = MSIFIELD_NULL;
214 rec->fields[i].u.iVal = 0;
216 msiobj_unlock( &rec->hdr );
217 msiobj_release( &rec->hdr );
219 return ERROR_SUCCESS;
222 UINT MSI_RecordSetInteger( MSIRECORD *rec, unsigned int iField, int iVal )
224 TRACE("%p %u %d\n", rec, iField, iVal);
226 if( iField > rec->count )
227 return ERROR_INVALID_PARAMETER;
229 MSI_FreeField( &rec->fields[iField] );
230 rec->fields[iField].type = MSIFIELD_INT;
231 rec->fields[iField].u.iVal = iVal;
233 return ERROR_SUCCESS;
236 UINT WINAPI MsiRecordSetInteger( MSIHANDLE handle, unsigned int iField, int iVal )
238 MSIRECORD *rec;
239 UINT ret;
241 TRACE("%ld %u %d\n", handle, iField, iVal);
243 rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
244 if( !rec )
245 return ERROR_INVALID_HANDLE;
247 msiobj_lock( &rec->hdr );
248 ret = MSI_RecordSetInteger( rec, iField, iVal );
249 msiobj_unlock( &rec->hdr );
250 msiobj_release( &rec->hdr );
251 return ret;
254 BOOL MSI_RecordIsNull( MSIRECORD *rec, unsigned int iField )
256 BOOL r = TRUE;
258 TRACE("%p %d\n", rec, iField );
260 r = ( iField > rec->count ) ||
261 ( rec->fields[iField].type == MSIFIELD_NULL );
263 return r;
266 BOOL WINAPI MsiRecordIsNull( MSIHANDLE handle, unsigned int iField )
268 MSIRECORD *rec;
269 UINT ret;
271 TRACE("%ld %d\n", handle, iField );
273 rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
274 if( !rec )
275 return 0;
276 msiobj_lock( &rec->hdr );
277 ret = MSI_RecordIsNull( rec, iField );
278 msiobj_unlock( &rec->hdr );
279 msiobj_release( &rec->hdr );
280 return ret;
284 UINT MSI_RecordGetStringA(MSIRECORD *rec, unsigned int iField,
285 LPSTR szValue, DWORD *pcchValue)
287 UINT len=0, ret;
288 CHAR buffer[16];
290 TRACE("%p %d %p %p\n", rec, iField, szValue, pcchValue);
292 if( iField > rec->count )
293 return ERROR_INVALID_PARAMETER;
295 ret = ERROR_SUCCESS;
296 switch( rec->fields[iField].type )
298 case MSIFIELD_INT:
299 wsprintfA(buffer, "%d", rec->fields[iField].u.iVal);
300 len = lstrlenA( buffer );
301 lstrcpynA(szValue, buffer, *pcchValue);
302 break;
303 case MSIFIELD_WSTR:
304 len = WideCharToMultiByte( CP_ACP, 0, rec->fields[iField].u.szwVal, -1,
305 NULL, 0 , NULL, NULL);
306 WideCharToMultiByte( CP_ACP, 0, rec->fields[iField].u.szwVal, -1,
307 szValue, *pcchValue, NULL, NULL);
308 if( *pcchValue && len>*pcchValue )
309 szValue[*pcchValue-1] = 0;
310 if( len )
311 len--;
312 break;
313 case MSIFIELD_NULL:
314 if( *pcchValue > 0 )
315 szValue[0] = 0;
316 break;
317 default:
318 ret = ERROR_INVALID_PARAMETER;
319 break;
322 if( *pcchValue < len )
323 ret = ERROR_MORE_DATA;
324 *pcchValue = len;
326 return ret;
329 UINT WINAPI MsiRecordGetStringA(MSIHANDLE handle, unsigned int iField,
330 LPSTR szValue, DWORD *pcchValue)
332 MSIRECORD *rec;
333 UINT ret;
335 TRACE("%ld %d %p %p\n", handle, iField, szValue, pcchValue);
337 rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
338 if( !rec )
339 return ERROR_INVALID_HANDLE;
340 msiobj_lock( &rec->hdr );
341 ret = MSI_RecordGetStringA( rec, iField, szValue, pcchValue);
342 msiobj_unlock( &rec->hdr );
343 msiobj_release( &rec->hdr );
344 return ret;
347 const WCHAR *MSI_RecordGetString( MSIRECORD *rec, unsigned int iField )
349 if( iField > rec->count )
350 return NULL;
352 if( rec->fields[iField].type != MSIFIELD_WSTR )
353 return NULL;
355 return rec->fields[iField].u.szwVal;
358 UINT MSI_RecordGetStringW(MSIRECORD *rec, unsigned int iField,
359 LPWSTR szValue, DWORD *pcchValue)
361 UINT len=0, ret;
362 WCHAR buffer[16];
363 static const WCHAR szFormat[] = { '%','d',0 };
365 TRACE("%p %d %p %p\n", rec, iField, szValue, pcchValue);
367 if( iField > rec->count )
368 return ERROR_INVALID_PARAMETER;
370 ret = ERROR_SUCCESS;
371 switch( rec->fields[iField].type )
373 case MSIFIELD_INT:
374 wsprintfW(buffer, szFormat, rec->fields[iField].u.iVal);
375 len = lstrlenW( buffer );
376 lstrcpynW(szValue, buffer, *pcchValue);
377 break;
378 case MSIFIELD_WSTR:
379 len = lstrlenW( rec->fields[iField].u.szwVal );
380 lstrcpynW(szValue, rec->fields[iField].u.szwVal, *pcchValue);
381 break;
382 case MSIFIELD_NULL:
383 len = 1;
384 if( *pcchValue > 0 )
385 szValue[0] = 0;
386 default:
387 break;
390 if( *pcchValue < len )
391 ret = ERROR_MORE_DATA;
392 *pcchValue = len;
394 return ret;
397 UINT WINAPI MsiRecordGetStringW(MSIHANDLE handle, unsigned int iField,
398 LPWSTR szValue, DWORD *pcchValue)
400 MSIRECORD *rec;
401 UINT ret;
403 TRACE("%ld %d %p %p\n", handle, iField, szValue, pcchValue);
405 rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
406 if( !rec )
407 return ERROR_INVALID_HANDLE;
409 msiobj_lock( &rec->hdr );
410 ret = MSI_RecordGetStringW( rec, iField, szValue, pcchValue );
411 msiobj_unlock( &rec->hdr );
412 msiobj_release( &rec->hdr );
413 return ret;
416 static UINT msi_get_stream_size( IStream *stm )
418 STATSTG stat;
419 HRESULT r;
421 r = IStream_Stat( stm, &stat, STATFLAG_NONAME );
422 if( FAILED(r) )
423 return 0;
424 return stat.cbSize.QuadPart;
427 UINT MSI_RecordDataSize(MSIRECORD *rec, unsigned int iField)
429 TRACE("%p %d\n", rec, iField);
431 if( iField > rec->count )
432 return 0;
434 switch( rec->fields[iField].type )
436 case MSIFIELD_INT:
437 return sizeof (INT);
438 case MSIFIELD_WSTR:
439 return lstrlenW( rec->fields[iField].u.szwVal );
440 case MSIFIELD_NULL:
441 break;
442 case MSIFIELD_STREAM:
443 return msi_get_stream_size( rec->fields[iField].u.stream );
445 return 0;
448 UINT WINAPI MsiRecordDataSize(MSIHANDLE handle, unsigned int iField)
450 MSIRECORD *rec;
451 UINT ret;
453 TRACE("%ld %d\n", handle, iField);
455 rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
456 if( !rec )
457 return 0;
458 msiobj_lock( &rec->hdr );
459 ret = MSI_RecordDataSize( rec, iField);
460 msiobj_unlock( &rec->hdr );
461 msiobj_release( &rec->hdr );
462 return ret;
465 UINT MSI_RecordSetStringA( MSIRECORD *rec, unsigned int iField, LPCSTR szValue )
467 LPWSTR str;
469 TRACE("%p %d %s\n", rec, iField, debugstr_a(szValue));
471 if( iField > rec->count )
472 return ERROR_INVALID_FIELD;
474 MSI_FreeField( &rec->fields[iField] );
475 if( szValue && szValue[0] )
477 str = strdupAtoW( szValue );
478 rec->fields[iField].type = MSIFIELD_WSTR;
479 rec->fields[iField].u.szwVal = str;
481 else
483 rec->fields[iField].type = MSIFIELD_NULL;
484 rec->fields[iField].u.szwVal = NULL;
487 return 0;
490 UINT WINAPI MsiRecordSetStringA( MSIHANDLE handle, unsigned int iField, LPCSTR szValue )
492 MSIRECORD *rec;
493 UINT ret;
495 TRACE("%ld %d %s\n", handle, iField, debugstr_a(szValue));
497 rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
498 if( !rec )
499 return ERROR_INVALID_HANDLE;
500 msiobj_lock( &rec->hdr );
501 ret = MSI_RecordSetStringA( rec, iField, szValue );
502 msiobj_unlock( &rec->hdr );
503 msiobj_release( &rec->hdr );
504 return ret;
507 UINT MSI_RecordSetStringW( MSIRECORD *rec, unsigned int iField, LPCWSTR szValue )
509 LPWSTR str;
511 TRACE("%p %d %s\n", rec, iField, debugstr_w(szValue));
513 if( iField > rec->count )
514 return ERROR_INVALID_FIELD;
516 MSI_FreeField( &rec->fields[iField] );
518 if( szValue && szValue[0] )
520 str = strdupW( szValue );
521 rec->fields[iField].type = MSIFIELD_WSTR;
522 rec->fields[iField].u.szwVal = str;
524 else
526 rec->fields[iField].type = MSIFIELD_NULL;
527 rec->fields[iField].u.szwVal = NULL;
530 return 0;
533 UINT WINAPI MsiRecordSetStringW( MSIHANDLE handle, unsigned int iField, LPCWSTR szValue )
535 MSIRECORD *rec;
536 UINT ret;
538 TRACE("%ld %d %s\n", handle, iField, debugstr_w(szValue));
540 rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
541 if( !rec )
542 return ERROR_INVALID_HANDLE;
544 msiobj_lock( &rec->hdr );
545 ret = MSI_RecordSetStringW( rec, iField, szValue );
546 msiobj_unlock( &rec->hdr );
547 msiobj_release( &rec->hdr );
548 return ret;
551 /* read the data in a file into an IStream */
552 static UINT RECORD_StreamFromFile(LPCWSTR szFile, IStream **pstm)
554 DWORD sz, szHighWord = 0, read;
555 HANDLE handle;
556 HGLOBAL hGlob = 0;
557 HRESULT hr;
558 ULARGE_INTEGER ulSize;
560 TRACE("reading %s\n", debugstr_w(szFile));
562 /* read the file into memory */
563 handle = CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
564 if( handle == INVALID_HANDLE_VALUE )
565 return GetLastError();
566 sz = GetFileSize(handle, &szHighWord);
567 if( sz != INVALID_FILE_SIZE && szHighWord == 0 )
569 hGlob = GlobalAlloc(GMEM_FIXED, sz);
570 if( hGlob )
572 BOOL r = ReadFile(handle, hGlob, sz, &read, NULL);
573 if( !r )
575 GlobalFree(hGlob);
576 hGlob = 0;
580 CloseHandle(handle);
581 if( !hGlob )
582 return ERROR_FUNCTION_FAILED;
584 /* make a stream out of it, and set the correct file size */
585 hr = CreateStreamOnHGlobal(hGlob, TRUE, pstm);
586 if( FAILED( hr ) )
588 GlobalFree(hGlob);
589 return ERROR_FUNCTION_FAILED;
592 /* set the correct size - CreateStreamOnHGlobal screws it up */
593 ulSize.QuadPart = sz;
594 IStream_SetSize(*pstm, ulSize);
596 TRACE("read %s, %ld bytes into IStream %p\n", debugstr_w(szFile), sz, *pstm);
598 return ERROR_SUCCESS;
601 UINT MSI_RecordSetStreamW(MSIRECORD *rec, unsigned int iField, LPCWSTR szFilename)
603 IStream *stm = NULL;
604 HRESULT r;
606 if( (iField == 0) || (iField > rec->count) )
607 return ERROR_INVALID_PARAMETER;
609 /* no filename means we should seek back to the start of the stream */
610 if( !szFilename )
612 LARGE_INTEGER ofs;
613 ULARGE_INTEGER cur;
615 if( rec->fields[iField].type != MSIFIELD_STREAM )
616 return ERROR_INVALID_FIELD;
618 stm = rec->fields[iField].u.stream;
619 if( !stm )
620 return ERROR_INVALID_FIELD;
622 ofs.QuadPart = 0;
623 r = IStream_Seek( stm, ofs, STREAM_SEEK_SET, &cur );
624 if( FAILED( r ) )
625 return ERROR_FUNCTION_FAILED;
627 else
629 /* read the file into a stream and save the stream in the record */
630 r = RECORD_StreamFromFile(szFilename, &stm);
631 if( r != ERROR_SUCCESS )
632 return r;
634 /* if all's good, store it in the record */
635 MSI_FreeField( &rec->fields[iField] );
636 rec->fields[iField].type = MSIFIELD_STREAM;
637 rec->fields[iField].u.stream = stm;
640 return ERROR_SUCCESS;
643 UINT WINAPI MsiRecordSetStreamA(MSIHANDLE hRecord, unsigned int iField, LPCSTR szFilename)
645 LPWSTR wstr = NULL;
646 UINT ret;
648 TRACE("%ld %d %s\n", hRecord, iField, debugstr_a(szFilename));
650 if( szFilename )
652 wstr = strdupAtoW( szFilename );
653 if( !wstr )
654 return ERROR_OUTOFMEMORY;
656 ret = MsiRecordSetStreamW(hRecord, iField, wstr);
657 HeapFree(GetProcessHeap(),0,wstr);
659 return ret;
662 UINT WINAPI MsiRecordSetStreamW(MSIHANDLE handle, unsigned int iField, LPCWSTR szFilename)
664 MSIRECORD *rec;
665 UINT ret;
667 TRACE("%ld %d %s\n", handle, iField, debugstr_w(szFilename));
669 rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
670 if( !rec )
671 return ERROR_INVALID_HANDLE;
673 msiobj_lock( &rec->hdr );
674 ret = MSI_RecordSetStreamW( rec, iField, szFilename );
675 msiobj_unlock( &rec->hdr );
676 msiobj_release( &rec->hdr );
677 return ret;
680 UINT MSI_RecordReadStream(MSIRECORD *rec, unsigned int iField, char *buf, DWORD *sz)
682 ULONG count;
683 HRESULT r;
684 IStream *stm;
686 TRACE("%p %d %p %p\n", rec, iField, buf, sz);
688 if( !sz )
689 return ERROR_INVALID_PARAMETER;
691 if( iField > rec->count)
692 return ERROR_INVALID_PARAMETER;
694 if( rec->fields[iField].type != MSIFIELD_STREAM )
695 return ERROR_INVALID_DATATYPE;
697 stm = rec->fields[iField].u.stream;
698 if( !stm )
699 return ERROR_INVALID_PARAMETER;
701 /* if there's no buffer pointer, calculate the length to the end */
702 if( !buf )
704 LARGE_INTEGER ofs;
705 ULARGE_INTEGER end, cur;
707 ofs.QuadPart = cur.QuadPart = 0;
708 end.QuadPart = 0;
709 r = IStream_Seek( stm, ofs, STREAM_SEEK_SET, &cur );
710 IStream_Seek( stm, ofs, STREAM_SEEK_END, &end );
711 ofs.QuadPart = cur.QuadPart;
712 IStream_Seek( stm, ofs, STREAM_SEEK_SET, &cur );
713 *sz = end.QuadPart - cur.QuadPart;
715 return ERROR_SUCCESS;
718 /* read the data */
719 count = 0;
720 r = IStream_Read( stm, buf, *sz, &count );
721 if( FAILED( r ) )
723 *sz = 0;
724 return ERROR_FUNCTION_FAILED;
727 *sz = count;
729 return ERROR_SUCCESS;
732 UINT WINAPI MsiRecordReadStream(MSIHANDLE handle, unsigned int iField, char *buf, DWORD *sz)
734 MSIRECORD *rec;
735 UINT ret;
737 TRACE("%ld %d %p %p\n", handle, iField, buf, sz);
739 rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
740 if( !rec )
741 return ERROR_INVALID_HANDLE;
742 msiobj_lock( &rec->hdr );
743 ret = MSI_RecordReadStream( rec, iField, buf, sz );
744 msiobj_unlock( &rec->hdr );
745 msiobj_release( &rec->hdr );
746 return ret;
749 UINT MSI_RecordSetIStream( MSIRECORD *rec, unsigned int iField, IStream *stm )
751 TRACE("%p %d %p\n", rec, iField, stm);
753 if( iField > rec->count )
754 return ERROR_INVALID_FIELD;
756 MSI_FreeField( &rec->fields[iField] );
758 rec->fields[iField].type = MSIFIELD_STREAM;
759 rec->fields[iField].u.stream = stm;
760 IStream_AddRef( stm );
762 return ERROR_SUCCESS;
765 UINT MSI_RecordGetIStream( MSIRECORD *rec, unsigned int iField, IStream **pstm)
767 TRACE("%p %d %p\n", rec, iField, pstm);
769 if( iField > rec->count )
770 return ERROR_INVALID_FIELD;
772 if( rec->fields[iField].type != MSIFIELD_STREAM )
773 return ERROR_INVALID_FIELD;
775 *pstm = rec->fields[iField].u.stream;
776 IStream_AddRef( *pstm );
778 return ERROR_SUCCESS;
781 static UINT msi_dump_stream_to_file( IStream *stm, LPCWSTR name )
783 ULARGE_INTEGER size;
784 LARGE_INTEGER pos;
785 IStream *out;
786 DWORD stgm;
787 HRESULT r;
789 stgm = STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_FAILIFTHERE;
790 r = SHCreateStreamOnFileW( name, stgm, &out );
791 if( FAILED( r ) )
792 return ERROR_FUNCTION_FAILED;
794 pos.QuadPart = 0;
795 r = IStream_Seek( stm, pos, STREAM_SEEK_END, &size );
796 if( FAILED( r ) )
797 goto end;
799 pos.QuadPart = 0;
800 r = IStream_Seek( stm, pos, STREAM_SEEK_SET, NULL );
801 if( FAILED( r ) )
802 goto end;
804 r = IStream_CopyTo( stm, out, size, NULL, NULL );
806 end:
807 IStream_Release( out );
808 if( FAILED( r ) )
809 return ERROR_FUNCTION_FAILED;
810 return ERROR_SUCCESS;
813 UINT MSI_RecordStreamToFile( MSIRECORD *rec, unsigned int iField, LPCWSTR name )
815 IStream *stm = NULL;
816 UINT r;
818 TRACE("%p %u %s\n", rec, iField, debugstr_w(name));
820 msiobj_lock( &rec->hdr );
822 r = MSI_RecordGetIStream( rec, iField, &stm );
823 if( r == ERROR_SUCCESS )
825 r = msi_dump_stream_to_file( stm, name );
826 IStream_Release( stm );
829 msiobj_unlock( &rec->hdr );
831 return r;