2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002 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
27 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(msi);
34 MSIHANDLEINFO *msihandletable[MSIMAXHANDLES];
36 MSIHANDLE alloc_msihandle(UINT type, UINT size, msihandledestructor destroy)
42 for(i=0; i<MSIMAXHANDLES; i++)
43 if( !msihandletable[i] )
45 if( (i>=MSIMAXHANDLES) || msihandletable[i] )
48 size += sizeof (MSIHANDLEINFO);
49 info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size );
53 info->magic = MSIHANDLE_MAGIC;
55 info->destructor = destroy;
57 msihandletable[i] = info;
59 return (MSIHANDLE) (i+1);
62 void *msihandle2msiinfo(MSIHANDLE handle, UINT type)
67 if( handle>=MSIMAXHANDLES )
69 if( !msihandletable[handle] )
71 if( msihandletable[handle]->magic != MSIHANDLE_MAGIC )
73 if( type && (msihandletable[handle]->type != type) )
76 return &msihandletable[handle][1];
79 UINT WINAPI MsiCloseHandle(MSIHANDLE handle)
81 MSIHANDLEINFO *info = msihandle2msiinfo(handle, 0);
83 TRACE("%lx\n",handle);
86 return ERROR_INVALID_HANDLE;
90 if( info->magic != MSIHANDLE_MAGIC )
92 ERR("Invalid handle!\n");
93 return ERROR_INVALID_HANDLE;
96 if( info->destructor )
97 info->destructor( &info[1] );
99 HeapFree( GetProcessHeap(), 0, info );
100 msihandletable[handle-1] = NULL;
102 TRACE("Destroyed\n");
107 UINT WINAPI MsiCloseAllHandles(void)
113 for(i=0; i<MSIMAXHANDLES; i++)
114 MsiCloseHandle( i+1 );