]> git.saurik.com Git - wxWidgets.git/blame - src/msw/ole/uuid.cpp
Private gsocket files were using 'typedef int bool', removed this
[wxWidgets.git] / src / msw / ole / uuid.cpp
CommitLineData
bbf1f0e5
KB
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".
bbf1f0e5
KB
21#include "wx/wxprec.h"
22
23#if defined(__BORLANDC__)
24#pragma hdrstop
25#endif
26
3096bd2f 27#include "wx/setup.h"
bbf1f0e5 28
47d67540 29#if wxUSE_DRAG_AND_DROP
bbf1f0e5
KB
30
31// standard headers
32#include <rpc.h> // UUID related functions
33
3096bd2f 34#include "wx/msw/ole/uuid.h"
bbf1f0e5
KB
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
46Uuid::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)
5f8e1c16
OK
53#ifdef _UNICODE
54 UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
55#else
bbf1f0e5 56 UuidToString(&m_uuid, &m_pszUuid);
5f8e1c16 57#endif
bbf1f0e5
KB
58
59 // allocate new buffer
5f8e1c16 60 m_pszCForm = new wxChar[UUID_CSTRLEN];
bbf1f0e5 61 // and fill it
5f8e1c16 62 memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN*sizeof(wxChar));
bbf1f0e5
KB
63}
64
65// assignment operator
66Uuid& Uuid::operator=(const Uuid& uuid)
67{
68 m_uuid = uuid.m_uuid;
69
70 // force the string to be allocated by RPC
71 // (we free it later with RpcStringFree)
5f8e1c16
OK
72#ifdef _UNICODE
73 UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
74#else
bbf1f0e5 75 UuidToString(&m_uuid, &m_pszUuid);
5f8e1c16 76#endif
bbf1f0e5
KB
77
78 // allocate new buffer if not done yet
79 if ( !m_pszCForm )
5f8e1c16 80 m_pszCForm = new wxChar[UUID_CSTRLEN];
bbf1f0e5
KB
81
82 // and fill it
5f8e1c16 83 memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN*sizeof(wxChar));
bbf1f0e5
KB
84
85 return *this;
86}
87
88// dtor
89Uuid::~Uuid()
90{
91 // this string must be allocated by RPC!
92 // (otherwise you get a debug breakpoint deep inside RPC DLL)
93 if ( m_pszUuid )
5f8e1c16
OK
94#ifdef _UNICODE
95 RpcStringFree((unsigned short **)&m_pszUuid);
96#else
bbf1f0e5 97 RpcStringFree(&m_pszUuid);
5f8e1c16 98#endif
bbf1f0e5
KB
99
100 // perhaps we should just use a static buffer and not bother
101 // with new and delete?
102 if ( m_pszCForm )
103 delete [] m_pszCForm;
104}
105
106// update string representation of new UUID
107void Uuid::Set(const UUID &uuid)
108{
109 m_uuid = uuid;
110
111 // get string representation
5f8e1c16
OK
112#ifdef _UNICODE
113 UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
114#else
bbf1f0e5 115 UuidToString(&m_uuid, &m_pszUuid);
5f8e1c16 116#endif
bbf1f0e5
KB
117
118 // cache UUID in C format
119 UuidToCForm();
120}
121
122// create a new UUID
123void Uuid::Create()
124{
125 UUID uuid;
126
127 // can't fail
128 UuidCreate(&uuid);
129
130 Set(uuid);
131}
132
133// set the value
5f8e1c16 134bool Uuid::Set(const wxChar *pc)
bbf1f0e5
KB
135{
136 // get UUID from string
5f8e1c16
OK
137#ifdef _UNICODE
138 if ( UuidFromString((unsigned short *)pc, &m_uuid) != RPC_S_OK)
139#else
140 if ( UuidFromString((wxUChar *)pc, &m_uuid) != RPC_S_OK)
141#endif
bbf1f0e5
KB
142 // failed: probably invalid string
143 return FALSE;
144
145 // transform it back to string to normalize it
5f8e1c16
OK
146#ifdef _UNICODE
147 UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
148#else
bbf1f0e5 149 UuidToString(&m_uuid, &m_pszUuid);
5f8e1c16 150#endif
bbf1f0e5
KB
151
152 // update m_pszCForm
153 UuidToCForm();
154
155 return TRUE;
156}
157
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
163void Uuid::UuidToCForm()
164{
165 if ( m_pszCForm == NULL )
5f8e1c16 166 m_pszCForm = new wxChar[UUID_CSTRLEN];
bbf1f0e5 167
f6bcfd97 168 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
KB
169 m_uuid.Data1, m_uuid.Data2, m_uuid.Data3,
170 m_uuid.Data4[1], m_uuid.Data4[2], m_uuid.Data4[3], m_uuid.Data4[4],
171 m_uuid.Data4[5], m_uuid.Data4[6], m_uuid.Data4[7], m_uuid.Data4[8]);
172}
173
174#endif
47d67540 175 // wxUSE_DRAG_AND_DROP