Fixed header dependencies to be fully compatible with the Windows
[wine/multimedia.git] / dlls / msi / handle.c
blob50073f2ec3b5dfbccff0336473f5c56a2bb07e1f
1 /*
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winreg.h"
26 #include "shlwapi.h"
27 #include "wine/debug.h"
28 #include "msi.h"
29 #include "msiquery.h"
30 #include "msipriv.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(msi);
34 MSIHANDLEINFO *msihandletable[MSIMAXHANDLES];
36 MSIHANDLE alloc_msihandle(UINT type, UINT size, msihandledestructor destroy)
38 MSIHANDLEINFO *info;
39 UINT i;
41 /* find a slot */
42 for(i=0; i<MSIMAXHANDLES; i++)
43 if( !msihandletable[i] )
44 break;
45 if( (i>=MSIMAXHANDLES) || msihandletable[i] )
46 return 0;
48 size += sizeof (MSIHANDLEINFO);
49 info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size );
50 if( !info )
51 return 0;
53 info->magic = MSIHANDLE_MAGIC;
54 info->type = type;
55 info->destructor = destroy;
57 msihandletable[i] = info;
59 return (MSIHANDLE) (i+1);
62 void *msihandle2msiinfo(MSIHANDLE handle, UINT type)
64 handle--;
65 if( handle<0 )
66 return NULL;
67 if( handle>=MSIMAXHANDLES )
68 return NULL;
69 if( !msihandletable[handle] )
70 return NULL;
71 if( msihandletable[handle]->magic != MSIHANDLE_MAGIC )
72 return NULL;
73 if( type && (msihandletable[handle]->type != type) )
74 return NULL;
76 return &msihandletable[handle][1];
79 UINT WINAPI MsiCloseHandle(MSIHANDLE handle)
81 MSIHANDLEINFO *info = msihandle2msiinfo(handle, 0);
83 TRACE("%lx\n",handle);
85 if( !info )
86 return ERROR_INVALID_HANDLE;
88 info--;
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");
104 return 0;
107 UINT WINAPI MsiCloseAllHandles(void)
109 UINT i;
111 TRACE("\n");
113 for(i=0; i<MSIMAXHANDLES; i++)
114 MsiCloseHandle( i+1 );
116 return 0;