]> git.saurik.com Git - wxWidgets.git/blob - src/msw/ole/uuid.cpp
Fixed missing brace in app.cpp
[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_DRAG_AND_DROP
30
31 // standard headers
32 #include <rpc.h> // UUID related functions
33
34 #include <wx/msw/ole/uuid.h>
35
36
37
38 // ============================================================================
39 // Implementation
40 // ============================================================================
41
42 // length of UUID in C format
43 #define UUID_CSTRLEN 100 // real length is 66
44
45 // copy ctor
46 Uuid::Uuid(const Uuid& uuid)
47 {
48 // bitwise copy Ok for UUIDs
49 m_uuid = uuid.m_uuid;
50
51 // force the string to be allocated by RPC
52 // (we free it later with RpcStringFree)
53 UuidToString(&m_uuid, &m_pszUuid);
54
55 // allocate new buffer
56 m_pszCForm = new char[UUID_CSTRLEN];
57 // and fill it
58 memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN);
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)
68 UuidToString(&m_uuid, &m_pszUuid);
69
70 // allocate new buffer if not done yet
71 if ( !m_pszCForm )
72 m_pszCForm = new char[UUID_CSTRLEN];
73
74 // and fill it
75 memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN);
76
77 return *this;
78 }
79
80 // dtor
81 Uuid::~Uuid()
82 {
83 // this string must be allocated by RPC!
84 // (otherwise you get a debug breakpoint deep inside RPC DLL)
85 if ( m_pszUuid )
86 RpcStringFree(&m_pszUuid);
87
88 // perhaps we should just use a static buffer and not bother
89 // with new and delete?
90 if ( m_pszCForm )
91 delete [] m_pszCForm;
92 }
93
94 // update string representation of new UUID
95 void Uuid::Set(const UUID &uuid)
96 {
97 m_uuid = uuid;
98
99 // get string representation
100 UuidToString(&m_uuid, &m_pszUuid);
101
102 // cache UUID in C format
103 UuidToCForm();
104 }
105
106 // create a new UUID
107 void Uuid::Create()
108 {
109 UUID uuid;
110
111 // can't fail
112 UuidCreate(&uuid);
113
114 Set(uuid);
115 }
116
117 // set the value
118 bool Uuid::Set(const char *pc)
119 {
120 // get UUID from string
121 if ( UuidFromString((uchar *)pc, &m_uuid) != RPC_S_OK)
122 // failed: probably invalid string
123 return FALSE;
124
125 // transform it back to string to normalize it
126 UuidToString(&m_uuid, &m_pszUuid);
127
128 // update m_pszCForm
129 UuidToCForm();
130
131 return TRUE;
132 }
133
134 // stores m_uuid in m_pszCForm in a format required by
135 // DEFINE_GUID macro: i.e. something like
136 // 0x7D8A2281L,0x4C61,0x11D0,0xBA,0xBD,0x00,0x00,0xC0,0x18,0xBA,0x27
137 // m_pszUuid is of the form (no, it's not quite the same UUID :-)
138 // 6aadc650-67b0-11d0-bac8-0000c018ba27
139 void Uuid::UuidToCForm()
140 {
141 if ( m_pszCForm == NULL )
142 m_pszCForm = new char[UUID_CSTRLEN];
143
144 wsprintf(m_pszCForm, "0x%8.8X,0x%4.4X,0x%4.4X,0x%2.2X,0x2.2%X,"
145 "0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X",
146 m_uuid.Data1, m_uuid.Data2, m_uuid.Data3,
147 m_uuid.Data4[1], m_uuid.Data4[2], m_uuid.Data4[3], m_uuid.Data4[4],
148 m_uuid.Data4[5], m_uuid.Data4[6], m_uuid.Data4[7], m_uuid.Data4[8]);
149 }
150
151 #endif
152 // wxUSE_DRAG_AND_DROP