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