summaryrefslogtreecommitdiffstats
path: root/libmsi/handle.c
blob: 50f6553590a317f8e86c91f89087ee3ce5eab102 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Implementation of the Microsoft Installer (msi.dll)
 *
 * Copyright 2002-2004 Mike McCormack for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#define COBJMACROS

#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "shlwapi.h"
#include "debug.h"
#include "libmsi.h"
#include "msipriv.h"


void *msihandle2msiinfo(LibmsiObject *obj, unsigned type)
{
    if( !obj )
        return NULL;
    if( type && obj->type != type )
        return NULL;

    msiobj_addref( obj );
    return obj;
}

void *alloc_msiobject(unsigned type, unsigned size, msihandledestructor destroy )
{
    LibmsiObject *info;

    info = msi_alloc_zero( size );
    if( info )
    {
        info->type = type;
        info->refcount = 1;
        info->destructor = destroy;
    }

    return info;
}

void msiobj_addref( LibmsiObject *info )
{
    if( !info )
        return;

    InterlockedIncrement(&info->refcount);
}

int msiobj_release( LibmsiObject *obj )
{
    int ret;

    if( !obj )
        return -1;

    ret = InterlockedDecrement( &obj->refcount );
    if( ret==0 )
    {
        if( obj->destructor )
            obj->destructor( obj );
        msi_free( obj );
        TRACE("object %p destroyed\n", obj);
    }

    return ret;
}

/***********************************************************
 *   MsiCloseHandle   [MSI.@]
 */
unsigned MsiCloseHandle(LibmsiObject *obj)
{
    TRACE("%x\n",obj);

    if( obj )
        msiobj_release( obj );

    return ERROR_SUCCESS;
}