]>
Commit | Line | Data |
---|---|---|
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 | 6 | // Created: 12.09.96 |
bbf1f0e5 | 7 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> |
65571936 | 8 | // Licence: wxWindows licence |
bbf1f0e5 KB |
9 | /////////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | // ============================================================================ | |
12 | // Declarations | |
13 | // ============================================================================ | |
14 | ||
bbf1f0e5 | 15 | // For compilers that support precompilation, includes "wx.h". |
bbf1f0e5 KB |
16 | #include "wx/wxprec.h" |
17 | ||
18 | #if defined(__BORLANDC__) | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
4b6a582b | 22 | #if wxUSE_OLE && (wxUSE_DRAG_AND_DROP || wxUSE_DATAOBJ) |
bbf1f0e5 | 23 | |
57bd4c60 | 24 | #ifndef WX_PRECOMP |
9ed0d735 | 25 | #include "wx/msw/wrapwin.h" |
7f017c64 | 26 | #endif |
57bd4c60 | 27 | |
bbf1f0e5 KB |
28 | #include <rpc.h> // UUID related functions |
29 | ||
3096bd2f | 30 | #include "wx/msw/ole/uuid.h" |
bbf1f0e5 KB |
31 | |
32 | ||
33 | ||
34 | // ============================================================================ | |
35 | // Implementation | |
36 | // ============================================================================ | |
37 | ||
38 | // length of UUID in C format | |
39 | #define UUID_CSTRLEN 100 // real length is 66 | |
40 | ||
41 | // copy ctor | |
42 | Uuid::Uuid(const Uuid& uuid) | |
43 | { | |
0a0e6a5b WS |
44 | // bitwise copy Ok for UUIDs |
45 | m_uuid = uuid.m_uuid; | |
bbf1f0e5 KB |
46 | |
47 | // force the string to be allocated by RPC | |
48 | // (we free it later with RpcStringFree) | |
5f8e1c16 OK |
49 | #ifdef _UNICODE |
50 | UuidToString(&m_uuid, (unsigned short **)&m_pszUuid); | |
51 | #else | |
bbf1f0e5 | 52 | UuidToString(&m_uuid, &m_pszUuid); |
5f8e1c16 | 53 | #endif |
bbf1f0e5 KB |
54 | |
55 | // allocate new buffer | |
5f8e1c16 | 56 | m_pszCForm = new wxChar[UUID_CSTRLEN]; |
bbf1f0e5 | 57 | // and fill it |
5f8e1c16 | 58 | memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN*sizeof(wxChar)); |
bbf1f0e5 KB |
59 | } |
60 | ||
61 | // assignment operator | |
62 | Uuid& Uuid::operator=(const Uuid& uuid) | |
63 | { | |
64 | m_uuid = uuid.m_uuid; | |
65 | ||
66 | // force the string to be allocated by RPC | |
67 | // (we free it later with RpcStringFree) | |
5f8e1c16 OK |
68 | #ifdef _UNICODE |
69 | UuidToString(&m_uuid, (unsigned short **)&m_pszUuid); | |
70 | #else | |
bbf1f0e5 | 71 | UuidToString(&m_uuid, &m_pszUuid); |
5f8e1c16 | 72 | #endif |
bbf1f0e5 KB |
73 | |
74 | // allocate new buffer if not done yet | |
75 | if ( !m_pszCForm ) | |
5f8e1c16 | 76 | m_pszCForm = new wxChar[UUID_CSTRLEN]; |
bbf1f0e5 KB |
77 | |
78 | // and fill it | |
5f8e1c16 | 79 | memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN*sizeof(wxChar)); |
bbf1f0e5 KB |
80 | |
81 | return *this; | |
82 | } | |
83 | ||
2753fd96 VZ |
84 | bool Uuid::operator==(const Uuid& uuid) const |
85 | { | |
a0fa7d39 VZ |
86 | // IsEqualGUID() returns BOOL and not bool so use an explicit comparison to |
87 | // avoid MSVC warnings about int->bool conversion | |
d5027818 | 88 | return IsEqualGUID(m_uuid, uuid.m_uuid) != 0; |
2753fd96 VZ |
89 | } |
90 | ||
bbf1f0e5 | 91 | // dtor |
0a0e6a5b WS |
92 | Uuid::~Uuid() |
93 | { | |
bbf1f0e5 KB |
94 | // this string must be allocated by RPC! |
95 | // (otherwise you get a debug breakpoint deep inside RPC DLL) | |
0a0e6a5b | 96 | if ( m_pszUuid ) |
5f8e1c16 OK |
97 | #ifdef _UNICODE |
98 | RpcStringFree((unsigned short **)&m_pszUuid); | |
99 | #else | |
bbf1f0e5 | 100 | RpcStringFree(&m_pszUuid); |
5f8e1c16 | 101 | #endif |
bbf1f0e5 KB |
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 | |
5f8e1c16 OK |
115 | #ifdef _UNICODE |
116 | UuidToString(&m_uuid, (unsigned short **)&m_pszUuid); | |
117 | #else | |
bbf1f0e5 | 118 | UuidToString(&m_uuid, &m_pszUuid); |
5f8e1c16 | 119 | #endif |
bbf1f0e5 KB |
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); | |
0a0e6a5b | 132 | |
bbf1f0e5 KB |
133 | Set(uuid); |
134 | } | |
135 | ||
136 | // set the value | |
5f8e1c16 | 137 | bool Uuid::Set(const wxChar *pc) |
bbf1f0e5 KB |
138 | { |
139 | // get UUID from string | |
5f8e1c16 OK |
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 | |
bbf1f0e5 | 145 | // failed: probably invalid string |
0a0e6a5b | 146 | return false; |
bbf1f0e5 KB |
147 | |
148 | // transform it back to string to normalize it | |
5f8e1c16 OK |
149 | #ifdef _UNICODE |
150 | UuidToString(&m_uuid, (unsigned short **)&m_pszUuid); | |
151 | #else | |
bbf1f0e5 | 152 | UuidToString(&m_uuid, &m_pszUuid); |
5f8e1c16 | 153 | #endif |
bbf1f0e5 KB |
154 | |
155 | // update m_pszCForm | |
156 | UuidToCForm(); | |
157 | ||
0a0e6a5b | 158 | return true; |
bbf1f0e5 KB |
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 ) | |
5f8e1c16 | 169 | m_pszCForm = new wxChar[UUID_CSTRLEN]; |
bbf1f0e5 | 170 | |
f6bcfd97 | 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"), |
bbf1f0e5 | 172 | m_uuid.Data1, m_uuid.Data2, m_uuid.Data3, |
aacc44c6 VZ |
173 | m_uuid.Data4[0], m_uuid.Data4[1], m_uuid.Data4[2], m_uuid.Data4[3], |
174 | m_uuid.Data4[4], m_uuid.Data4[5], m_uuid.Data4[6], m_uuid.Data4[7]); | |
bbf1f0e5 KB |
175 | } |
176 | ||
177 | #endif | |
47d67540 | 178 | // wxUSE_DRAG_AND_DROP |