]>
Commit | Line | Data |
---|---|---|
bbf1f0e5 KB |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: ole/uuid.cpp | |
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 | ||
3096bd2f | 23 | #include "wx/setup.h" |
bbf1f0e5 | 24 | |
1d105d58 | 25 | #if wxUSE_OLE && ( wxUSE_DRAG_AND_DROP || (defined(__WXDEBUG__) && wxUSE_DATAOBJ) ) |
bbf1f0e5 KB |
26 | |
27 | // standard headers | |
7f017c64 | 28 | #if wxCHECK_W32API_VERSION( 1, 0 ) |
9ed0d735 | 29 | #include "wx/msw/wrapwin.h" |
7f017c64 | 30 | #endif |
bbf1f0e5 KB |
31 | #include <rpc.h> // UUID related functions |
32 | ||
3096bd2f | 33 | #include "wx/msw/ole/uuid.h" |
bbf1f0e5 KB |
34 | |
35 | ||
36 | ||
37 | // ============================================================================ | |
38 | // Implementation | |
39 | // ============================================================================ | |
40 | ||
41 | // length of UUID in C format | |
42 | #define UUID_CSTRLEN 100 // real length is 66 | |
43 | ||
44 | // copy ctor | |
45 | Uuid::Uuid(const Uuid& uuid) | |
46 | { | |
0a0e6a5b WS |
47 | // bitwise copy Ok for UUIDs |
48 | m_uuid = uuid.m_uuid; | |
bbf1f0e5 KB |
49 | |
50 | // force the string to be allocated by RPC | |
51 | // (we free it later with RpcStringFree) | |
5f8e1c16 OK |
52 | #ifdef _UNICODE |
53 | UuidToString(&m_uuid, (unsigned short **)&m_pszUuid); | |
54 | #else | |
bbf1f0e5 | 55 | UuidToString(&m_uuid, &m_pszUuid); |
5f8e1c16 | 56 | #endif |
bbf1f0e5 KB |
57 | |
58 | // allocate new buffer | |
5f8e1c16 | 59 | m_pszCForm = new wxChar[UUID_CSTRLEN]; |
bbf1f0e5 | 60 | // and fill it |
5f8e1c16 | 61 | memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN*sizeof(wxChar)); |
bbf1f0e5 KB |
62 | } |
63 | ||
64 | // assignment operator | |
65 | Uuid& Uuid::operator=(const Uuid& uuid) | |
66 | { | |
67 | m_uuid = uuid.m_uuid; | |
68 | ||
69 | // force the string to be allocated by RPC | |
70 | // (we free it later with RpcStringFree) | |
5f8e1c16 OK |
71 | #ifdef _UNICODE |
72 | UuidToString(&m_uuid, (unsigned short **)&m_pszUuid); | |
73 | #else | |
bbf1f0e5 | 74 | UuidToString(&m_uuid, &m_pszUuid); |
5f8e1c16 | 75 | #endif |
bbf1f0e5 KB |
76 | |
77 | // allocate new buffer if not done yet | |
78 | if ( !m_pszCForm ) | |
5f8e1c16 | 79 | m_pszCForm = new wxChar[UUID_CSTRLEN]; |
bbf1f0e5 KB |
80 | |
81 | // and fill it | |
5f8e1c16 | 82 | memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN*sizeof(wxChar)); |
bbf1f0e5 KB |
83 | |
84 | return *this; | |
85 | } | |
86 | ||
87 | // dtor | |
0a0e6a5b WS |
88 | Uuid::~Uuid() |
89 | { | |
bbf1f0e5 KB |
90 | // this string must be allocated by RPC! |
91 | // (otherwise you get a debug breakpoint deep inside RPC DLL) | |
0a0e6a5b | 92 | if ( m_pszUuid ) |
5f8e1c16 OK |
93 | #ifdef _UNICODE |
94 | RpcStringFree((unsigned short **)&m_pszUuid); | |
95 | #else | |
bbf1f0e5 | 96 | RpcStringFree(&m_pszUuid); |
5f8e1c16 | 97 | #endif |
bbf1f0e5 KB |
98 | |
99 | // perhaps we should just use a static buffer and not bother | |
100 | // with new and delete? | |
101 | if ( m_pszCForm ) | |
102 | delete [] m_pszCForm; | |
103 | } | |
104 | ||
105 | // update string representation of new UUID | |
106 | void Uuid::Set(const UUID &uuid) | |
107 | { | |
108 | m_uuid = uuid; | |
109 | ||
110 | // get string representation | |
5f8e1c16 OK |
111 | #ifdef _UNICODE |
112 | UuidToString(&m_uuid, (unsigned short **)&m_pszUuid); | |
113 | #else | |
bbf1f0e5 | 114 | UuidToString(&m_uuid, &m_pszUuid); |
5f8e1c16 | 115 | #endif |
bbf1f0e5 KB |
116 | |
117 | // cache UUID in C format | |
118 | UuidToCForm(); | |
119 | } | |
120 | ||
121 | // create a new UUID | |
122 | void Uuid::Create() | |
123 | { | |
124 | UUID uuid; | |
125 | ||
126 | // can't fail | |
127 | UuidCreate(&uuid); | |
0a0e6a5b | 128 | |
bbf1f0e5 KB |
129 | Set(uuid); |
130 | } | |
131 | ||
132 | // set the value | |
5f8e1c16 | 133 | bool Uuid::Set(const wxChar *pc) |
bbf1f0e5 KB |
134 | { |
135 | // get UUID from string | |
5f8e1c16 OK |
136 | #ifdef _UNICODE |
137 | if ( UuidFromString((unsigned short *)pc, &m_uuid) != RPC_S_OK) | |
138 | #else | |
139 | if ( UuidFromString((wxUChar *)pc, &m_uuid) != RPC_S_OK) | |
140 | #endif | |
bbf1f0e5 | 141 | // failed: probably invalid string |
0a0e6a5b | 142 | return false; |
bbf1f0e5 KB |
143 | |
144 | // transform it back to string to normalize it | |
5f8e1c16 OK |
145 | #ifdef _UNICODE |
146 | UuidToString(&m_uuid, (unsigned short **)&m_pszUuid); | |
147 | #else | |
bbf1f0e5 | 148 | UuidToString(&m_uuid, &m_pszUuid); |
5f8e1c16 | 149 | #endif |
bbf1f0e5 KB |
150 | |
151 | // update m_pszCForm | |
152 | UuidToCForm(); | |
153 | ||
0a0e6a5b | 154 | return true; |
bbf1f0e5 KB |
155 | } |
156 | ||
157 | // stores m_uuid in m_pszCForm in a format required by | |
158 | // DEFINE_GUID macro: i.e. something like | |
159 | // 0x7D8A2281L,0x4C61,0x11D0,0xBA,0xBD,0x00,0x00,0xC0,0x18,0xBA,0x27 | |
160 | // m_pszUuid is of the form (no, it's not quite the same UUID :-) | |
161 | // 6aadc650-67b0-11d0-bac8-0000c018ba27 | |
162 | void Uuid::UuidToCForm() | |
163 | { | |
164 | if ( m_pszCForm == NULL ) | |
5f8e1c16 | 165 | m_pszCForm = new wxChar[UUID_CSTRLEN]; |
bbf1f0e5 | 166 | |
f6bcfd97 | 167 | 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 | 168 | m_uuid.Data1, m_uuid.Data2, m_uuid.Data3, |
aacc44c6 VZ |
169 | m_uuid.Data4[0], m_uuid.Data4[1], m_uuid.Data4[2], m_uuid.Data4[3], |
170 | m_uuid.Data4[4], m_uuid.Data4[5], m_uuid.Data4[6], m_uuid.Data4[7]); | |
bbf1f0e5 KB |
171 | } |
172 | ||
173 | #endif | |
47d67540 | 174 | // wxUSE_DRAG_AND_DROP |