Release 970914
[wine.git] / misc / compobj.c
blob40c9444e00d6159991e76de29d9c9f71e5ebef22
1 /*
2 * COMPOBJ library
4 * Copyright 1995 Martin von Loewis
5 */
7 /* At the moment, these are only empty stubs.
8 */
10 #include <ctype.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include "ole.h"
14 #include "ole2.h"
15 #include "stddebug.h"
16 #include "debug.h"
17 #include "compobj.h"
19 DWORD currentMalloc=0;
21 /***********************************************************************
22 * CoBuildVersion [COMPOBJ.1]
24 DWORD WINAPI CoBuildVersion()
26 dprintf_ole(stddeb,"CoBuildVersion()\n");
27 return (rmm<<16)+rup;
30 /***********************************************************************
31 * CoInitialize [COMPOBJ.2]
32 * lpReserved is an IMalloc pointer in 16bit OLE. We just stored it as-is.
34 HRESULT WINAPI CoInitialize(DWORD lpReserved)
36 dprintf_ole(stdnimp,"CoInitialize\n");
37 /* remember the LPMALLOC, maybe somebody wants to read it later on */
38 currentMalloc = lpReserved;
39 return S_OK;
42 /***********************************************************************
43 * CoUnitialize [COMPOBJ.3]
45 void WINAPI CoUnitialize()
47 dprintf_ole(stdnimp,"CoUnitialize()\n");
50 /***********************************************************************
51 * CoGetMalloc [COMPOBJ.4]
53 HRESULT WINAPI CoGetMalloc(DWORD dwMemContext, DWORD * lpMalloc)
55 if(currentMalloc)
57 *lpMalloc = currentMalloc;
58 return S_OK;
60 *lpMalloc = 0;
61 /* 16-bit E_NOTIMPL */
62 return 0x80000001L;
65 /***********************************************************************
66 * CoDisconnectObject
68 OLESTATUS WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
70 dprintf_ole(stdnimp,"CoDisconnectObject:%p %lx\n",lpUnk,reserved);
71 return OLE_OK;
74 /***********************************************************************
75 * IsEqualGUID [COMPOBJ.18]
77 BOOL16 WINAPI IsEqualGUID(GUID* g1, GUID* g2)
79 return !memcmp( g1, g2, sizeof(GUID) );
82 /***********************************************************************
83 * CLSIDFromString [COMPOBJ.20]
86 /* Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6] */
88 OLESTATUS WINAPI CLSIDFromString(const LPCSTR idstr, CLSID *id)
90 BYTE *s = (BYTE *) idstr;
91 BYTE *p;
92 int i;
93 BYTE table[256];
95 dprintf_ole(stddeb,"ClsIDFromString() %s -> %p\n", idstr, id);
97 /* quick lookup table */
98 memset(table, 0, 256);
100 for (i = 0; i < 10; i++) {
101 table['0' + i] = i;
103 for (i = 0; i < 6; i++) {
104 table['A' + i] = i+10;
105 table['a' + i] = i+10;
108 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
110 if (strlen(idstr) != 38)
111 return OLE_ERROR_OBJECT;
113 p = (BYTE *) id;
115 s++; /* skip leading brace */
116 for (i = 0; i < 4; i++) {
117 p[3 - i] = table[*s]<<4 | table[*(s+1)];
118 s += 2;
120 p += 4;
121 s++; /* skip - */
123 for (i = 0; i < 2; i++) {
124 p[1-i] = table[*s]<<4 | table[*(s+1)];
125 s += 2;
127 p += 2;
128 s++; /* skip - */
130 for (i = 0; i < 2; i++) {
131 p[1-i] = table[*s]<<4 | table[*(s+1)];
132 s += 2;
134 p += 2;
135 s++; /* skip - */
137 /* these are just sequential bytes */
138 for (i = 0; i < 2; i++) {
139 *p++ = table[*s]<<4 | table[*(s+1)];
140 s += 2;
142 s++; /* skip - */
144 for (i = 0; i < 6; i++) {
145 *p++ = table[*s]<<4 | table[*(s+1)];
146 s += 2;
149 return OLE_OK;
152 /***********************************************************************
153 * CLSIDFromString [COMPOBJ.19]
156 OLESTATUS WINAPI StringFromCLSID(const CLSID *id, LPSTR idstr)
158 static const char *hex = "0123456789ABCDEF";
159 char *s;
160 int i;
162 sprintf(idstr, "{%08lx-%04x-%04x-%2x%2x-",
163 id->Data1, id->Data2, id->Data3,
164 id->Data4[0], id->Data4[1]);
165 s = &idstr[25];
167 /* 6 hex bytes */
168 for (i = 2; i < 8; i++) {
169 *s++ = hex[id->Data4[i]>>4];
170 *s++ = hex[id->Data4[i] & 0xf];
173 *s++ = '}';
174 *s++ = '\0';
176 for (i = strlen(idstr)-1; i >= 0; i--) {
177 idstr[i] = toupper(idstr[i]);
180 dprintf_ole(stddeb,"StringFromClsID: %p->%s\n", id, idstr);
182 return OLE_OK;