]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/ole/uuid.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: implements Uuid class, see uuid.h for details
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
17 #pragma implementation "uuid.h"
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
23 #if defined(__BORLANDC__)
29 #if wxUSE_DRAG_AND_DROP
32 #include <rpc.h> // UUID related functions
34 #include <wx/msw/ole/uuid.h>
38 // ============================================================================
40 // ============================================================================
42 // length of UUID in C format
43 #define UUID_CSTRLEN 100 // real length is 66
46 Uuid::Uuid(const Uuid
& uuid
)
48 // bitwise copy Ok for UUIDs
51 // force the string to be allocated by RPC
52 // (we free it later with RpcStringFree)
54 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
56 UuidToString(&m_uuid
, &m_pszUuid
);
59 // allocate new buffer
60 m_pszCForm
= new wxChar
[UUID_CSTRLEN
];
62 memcpy(m_pszCForm
, uuid
.m_pszCForm
, UUID_CSTRLEN
*sizeof(wxChar
));
65 // assignment operator
66 Uuid
& Uuid::operator=(const Uuid
& uuid
)
70 // force the string to be allocated by RPC
71 // (we free it later with RpcStringFree)
73 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
75 UuidToString(&m_uuid
, &m_pszUuid
);
78 // allocate new buffer if not done yet
80 m_pszCForm
= new wxChar
[UUID_CSTRLEN
];
83 memcpy(m_pszCForm
, uuid
.m_pszCForm
, UUID_CSTRLEN
*sizeof(wxChar
));
91 // this string must be allocated by RPC!
92 // (otherwise you get a debug breakpoint deep inside RPC DLL)
95 RpcStringFree((unsigned short **)&m_pszUuid
);
97 RpcStringFree(&m_pszUuid
);
100 // perhaps we should just use a static buffer and not bother
101 // with new and delete?
103 delete [] m_pszCForm
;
106 // update string representation of new UUID
107 void Uuid::Set(const UUID
&uuid
)
111 // get string representation
113 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
115 UuidToString(&m_uuid
, &m_pszUuid
);
118 // cache UUID in C format
134 bool Uuid::Set(const wxChar
*pc
)
136 // get UUID from string
138 if ( UuidFromString((unsigned short *)pc
, &m_uuid
) != RPC_S_OK
)
140 if ( UuidFromString((wxUChar
*)pc
, &m_uuid
) != RPC_S_OK
)
142 // failed: probably invalid string
145 // transform it back to string to normalize it
147 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
149 UuidToString(&m_uuid
, &m_pszUuid
);
158 // stores m_uuid in m_pszCForm in a format required by
159 // DEFINE_GUID macro: i.e. something like
160 // 0x7D8A2281L,0x4C61,0x11D0,0xBA,0xBD,0x00,0x00,0xC0,0x18,0xBA,0x27
161 // m_pszUuid is of the form (no, it's not quite the same UUID :-)
162 // 6aadc650-67b0-11d0-bac8-0000c018ba27
163 void Uuid::UuidToCForm()
165 if ( m_pszCForm
== NULL
)
166 m_pszCForm
= new wxChar
[UUID_CSTRLEN
];
168 wsprintf(m_pszCForm
, _T("0x%8.8X,0x%4.4X,0x%4.4X,0x%2.2X,0x2.2%X,"
169 "0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X"),
170 m_uuid
.Data1
, m_uuid
.Data2
, m_uuid
.Data3
,
171 m_uuid
.Data4
[1], m_uuid
.Data4
[2], m_uuid
.Data4
[3], m_uuid
.Data4
[4],
172 m_uuid
.Data4
[5], m_uuid
.Data4
[6], m_uuid
.Data4
[7], m_uuid
.Data4
[8]);
176 // wxUSE_DRAG_AND_DROP