]> git.saurik.com Git - wxWidgets.git/blame - src/msw/ole/uuid.cpp
fix spurious assert failure in DestroyGripper() which happened if the dialog hadn...
[wxWidgets.git] / src / msw / ole / uuid.cpp
CommitLineData
bbf1f0e5 1///////////////////////////////////////////////////////////////////////////////
521bf4ff 2// Name: src/msw/ole/uuid.cpp
bbf1f0e5
KB
3// Purpose: implements Uuid class, see uuid.h for details
4// Author: Vadim Zeitlin
0a0e6a5b 5// Modified by:
bbf1f0e5
KB
6// Created: 12.09.96
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 9// Licence: wxWindows licence
bbf1f0e5
KB
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// Declarations
14// ============================================================================
15
bbf1f0e5 16// For compilers that support precompilation, includes "wx.h".
bbf1f0e5
KB
17#include "wx/wxprec.h"
18
19#if defined(__BORLANDC__)
20#pragma hdrstop
21#endif
22
1d105d58 23#if wxUSE_OLE && ( wxUSE_DRAG_AND_DROP || (defined(__WXDEBUG__) && wxUSE_DATAOBJ) )
bbf1f0e5 24
57bd4c60 25#ifndef WX_PRECOMP
9ed0d735 26 #include "wx/msw/wrapwin.h"
7f017c64 27#endif
57bd4c60 28
bbf1f0e5
KB
29#include <rpc.h> // UUID related functions
30
3096bd2f 31#include "wx/msw/ole/uuid.h"
bbf1f0e5
KB
32
33
34
35// ============================================================================
36// Implementation
37// ============================================================================
38
39// length of UUID in C format
40#define UUID_CSTRLEN 100 // real length is 66
41
42// copy ctor
43Uuid::Uuid(const Uuid& uuid)
44{
0a0e6a5b
WS
45 // bitwise copy Ok for UUIDs
46 m_uuid = uuid.m_uuid;
bbf1f0e5
KB
47
48 // force the string to be allocated by RPC
49 // (we free it later with RpcStringFree)
5f8e1c16
OK
50#ifdef _UNICODE
51 UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
52#else
bbf1f0e5 53 UuidToString(&m_uuid, &m_pszUuid);
5f8e1c16 54#endif
bbf1f0e5
KB
55
56 // allocate new buffer
5f8e1c16 57 m_pszCForm = new wxChar[UUID_CSTRLEN];
bbf1f0e5 58 // and fill it
5f8e1c16 59 memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN*sizeof(wxChar));
bbf1f0e5
KB
60}
61
62// assignment operator
63Uuid& Uuid::operator=(const Uuid& uuid)
64{
65 m_uuid = uuid.m_uuid;
66
67 // force the string to be allocated by RPC
68 // (we free it later with RpcStringFree)
5f8e1c16
OK
69#ifdef _UNICODE
70 UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
71#else
bbf1f0e5 72 UuidToString(&m_uuid, &m_pszUuid);
5f8e1c16 73#endif
bbf1f0e5
KB
74
75 // allocate new buffer if not done yet
76 if ( !m_pszCForm )
5f8e1c16 77 m_pszCForm = new wxChar[UUID_CSTRLEN];
bbf1f0e5
KB
78
79 // and fill it
5f8e1c16 80 memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN*sizeof(wxChar));
bbf1f0e5
KB
81
82 return *this;
83}
84
85// dtor
0a0e6a5b
WS
86Uuid::~Uuid()
87{
bbf1f0e5
KB
88 // this string must be allocated by RPC!
89 // (otherwise you get a debug breakpoint deep inside RPC DLL)
0a0e6a5b 90 if ( m_pszUuid )
5f8e1c16
OK
91#ifdef _UNICODE
92 RpcStringFree((unsigned short **)&m_pszUuid);
93#else
bbf1f0e5 94 RpcStringFree(&m_pszUuid);
5f8e1c16 95#endif
bbf1f0e5
KB
96
97 // perhaps we should just use a static buffer and not bother
98 // with new and delete?
99 if ( m_pszCForm )
100 delete [] m_pszCForm;
101}
102
103// update string representation of new UUID
104void Uuid::Set(const UUID &uuid)
105{
106 m_uuid = uuid;
107
108 // get string representation
5f8e1c16
OK
109#ifdef _UNICODE
110 UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
111#else
bbf1f0e5 112 UuidToString(&m_uuid, &m_pszUuid);
5f8e1c16 113#endif
bbf1f0e5
KB
114
115 // cache UUID in C format
116 UuidToCForm();
117}
118
119// create a new UUID
120void Uuid::Create()
121{
122 UUID uuid;
123
124 // can't fail
125 UuidCreate(&uuid);
0a0e6a5b 126
bbf1f0e5
KB
127 Set(uuid);
128}
129
130// set the value
5f8e1c16 131bool Uuid::Set(const wxChar *pc)
bbf1f0e5
KB
132{
133 // get UUID from string
5f8e1c16
OK
134#ifdef _UNICODE
135 if ( UuidFromString((unsigned short *)pc, &m_uuid) != RPC_S_OK)
136#else
137 if ( UuidFromString((wxUChar *)pc, &m_uuid) != RPC_S_OK)
138#endif
bbf1f0e5 139 // failed: probably invalid string
0a0e6a5b 140 return false;
bbf1f0e5
KB
141
142 // transform it back to string to normalize it
5f8e1c16
OK
143#ifdef _UNICODE
144 UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
145#else
bbf1f0e5 146 UuidToString(&m_uuid, &m_pszUuid);
5f8e1c16 147#endif
bbf1f0e5
KB
148
149 // update m_pszCForm
150 UuidToCForm();
151
0a0e6a5b 152 return true;
bbf1f0e5
KB
153}
154
155// stores m_uuid in m_pszCForm in a format required by
156// DEFINE_GUID macro: i.e. something like
157// 0x7D8A2281L,0x4C61,0x11D0,0xBA,0xBD,0x00,0x00,0xC0,0x18,0xBA,0x27
158// m_pszUuid is of the form (no, it's not quite the same UUID :-)
159// 6aadc650-67b0-11d0-bac8-0000c018ba27
160void Uuid::UuidToCForm()
161{
162 if ( m_pszCForm == NULL )
5f8e1c16 163 m_pszCForm = new wxChar[UUID_CSTRLEN];
bbf1f0e5 164
f6bcfd97 165 wsprintf(m_pszCForm, wxT("0x%8.8X,0x%4.4X,0x%4.4X,0x%2.2X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X"),
bbf1f0e5 166 m_uuid.Data1, m_uuid.Data2, m_uuid.Data3,
aacc44c6
VZ
167 m_uuid.Data4[0], m_uuid.Data4[1], m_uuid.Data4[2], m_uuid.Data4[3],
168 m_uuid.Data4[4], m_uuid.Data4[5], m_uuid.Data4[6], m_uuid.Data4[7]);
bbf1f0e5
KB
169}
170
171#endif
47d67540 172 // wxUSE_DRAG_AND_DROP