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, void **out)
44 for(i=0; i<MSIMAXHANDLES; i++)
45 if( !msihandletable[i] )
47 if( (i>=MSIMAXHANDLES) || msihandletable[i] )
50 size += sizeof (MSIHANDLEINFO);
51 info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size );
55 info->magic = MSIHANDLE_MAGIC;
57 info->destructor = destroy;
59 msihandletable[i] = info;
60 *out = (void*) &info[1];
62 return (MSIHANDLE) (i+1);
65 void *msihandle2msiinfo(MSIHANDLE handle, UINT type)
70 if( handle>=MSIMAXHANDLES )
72 if( !msihandletable[handle] )
74 if( msihandletable[handle]->magic != MSIHANDLE_MAGIC )
76 if( type && (msihandletable[handle]->type != type) )
79 return &msihandletable[handle][1];
82 UINT WINAPI MsiCloseHandle(MSIHANDLE handle)
84 MSIHANDLEINFO *info = msihandle2msiinfo(handle, 0);
86 TRACE("%lx\n",handle);
89 return ERROR_INVALID_HANDLE;
93 if( info->magic != MSIHANDLE_MAGIC )
95 ERR("Invalid handle!\n");
96 return ERROR_INVALID_HANDLE;
99 if( info->destructor )
100 info->destructor( &info[1] );
102 HeapFree( GetProcessHeap(), 0, info );
103 msihandletable[handle-1] = NULL;
105 TRACE("Destroyed\n");
110 UINT WINAPI MsiCloseAllHandles(void)
116 for(i=0; i<MSIMAXHANDLES; i++)
117 MsiCloseHandle( i+1 );