]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/ole/uuid.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/ole/uuid.cpp
3 // Purpose: implements Uuid class, see uuid.h for details
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
18 #if defined(__BORLANDC__)
22 #if wxUSE_OLE && (wxUSE_DRAG_AND_DROP || wxUSE_DATAOBJ)
25 #include "wx/msw/wrapwin.h"
28 #include <rpc.h> // UUID related functions
30 #include "wx/msw/ole/uuid.h"
34 // ============================================================================
36 // ============================================================================
38 // length of UUID in C format
39 #define UUID_CSTRLEN 100 // real length is 66
42 Uuid::Uuid(const Uuid
& uuid
)
44 // bitwise copy Ok for UUIDs
47 // force the string to be allocated by RPC
48 // (we free it later with RpcStringFree)
50 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
52 UuidToString(&m_uuid
, &m_pszUuid
);
55 // allocate new buffer
56 m_pszCForm
= new wxChar
[UUID_CSTRLEN
];
58 memcpy(m_pszCForm
, uuid
.m_pszCForm
, UUID_CSTRLEN
*sizeof(wxChar
));
61 // assignment operator
62 Uuid
& Uuid::operator=(const Uuid
& uuid
)
66 // force the string to be allocated by RPC
67 // (we free it later with RpcStringFree)
69 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
71 UuidToString(&m_uuid
, &m_pszUuid
);
74 // allocate new buffer if not done yet
76 m_pszCForm
= new wxChar
[UUID_CSTRLEN
];
79 memcpy(m_pszCForm
, uuid
.m_pszCForm
, UUID_CSTRLEN
*sizeof(wxChar
));
84 bool Uuid::operator==(const Uuid
& uuid
) const
86 // IsEqualGUID() returns BOOL and not bool so use an explicit comparison to
87 // avoid MSVC warnings about int->bool conversion
88 return IsEqualGUID(m_uuid
, uuid
.m_uuid
) != 0;
94 // this string must be allocated by RPC!
95 // (otherwise you get a debug breakpoint deep inside RPC DLL)
98 RpcStringFree((unsigned short **)&m_pszUuid
);
100 RpcStringFree(&m_pszUuid
);
103 // perhaps we should just use a static buffer and not bother
104 // with new and delete?
106 delete [] m_pszCForm
;
109 // update string representation of new UUID
110 void Uuid::Set(const UUID
&uuid
)
114 // get string representation
116 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
118 UuidToString(&m_uuid
, &m_pszUuid
);
121 // cache UUID in C format
137 bool Uuid::Set(const wxChar
*pc
)
139 // get UUID from string
141 if ( UuidFromString((unsigned short *)pc
, &m_uuid
) != RPC_S_OK
)
143 if ( UuidFromString((wxUChar
*)pc
, &m_uuid
) != RPC_S_OK
)
145 // failed: probably invalid string
148 // transform it back to string to normalize it
150 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
152 UuidToString(&m_uuid
, &m_pszUuid
);
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()
168 if ( m_pszCForm
== NULL
)
169 m_pszCForm
= new wxChar
[UUID_CSTRLEN
];
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
[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]);
178 // wxUSE_DRAG_AND_DROP