4 * Copyright 1995 Martin von Loewis
14 #include "wine/obj_base.h"
20 /* This implementation of the BSTR API is 16-bit only. It
21 represents BSTR as a 16:16 far pointer, and the strings
24 /******************************************************************************
25 * BSTR_AllocBytes [Internal]
27 static BSTR16
BSTR_AllocBytes(int n
)
29 void *ptr
= SEGPTR_ALLOC(n
);
30 return (BSTR16
)SEGPTR_GET(ptr
);
33 /******************************************************************************
34 * BSTR_Free [INTERNAL]
36 static void BSTR_Free(BSTR16 in
)
38 SEGPTR_FREE( PTR_SEG_TO_LIN(in
) );
41 /******************************************************************************
42 * BSTR_GetAddr [INTERNAL]
44 static void* BSTR_GetAddr(BSTR16 in
)
46 return in
? PTR_SEG_TO_LIN(in
) : 0;
49 /******************************************************************************
50 * SysAllocString16 [OLE2DISP.2]
52 BSTR16 WINAPI
SysAllocString16(LPOLESTR16 in
)
54 BSTR16 out
=BSTR_AllocBytes(strlen(in
)+1);
56 strcpy(BSTR_GetAddr(out
),in
);
60 /******************************************************************************
61 * SysAllocString32 [OLEAUT32.2]
63 BSTR WINAPI
SysAllocString(LPOLESTR in
)
65 /* Delegate this to the SysAllocStringLen32 method. */
66 return SysAllocStringLen(in
, lstrlenW(in
));
69 /******************************************************************************
70 * SysReAllocString16 [OLE2DISP.3]
72 INT16 WINAPI
SysReAllocString16(LPBSTR16 old
,LPOLESTR16 in
)
74 BSTR16
new=SysAllocString16(in
);
80 /******************************************************************************
81 * SysReAllocString32 [OLEAUT32.3]
83 INT WINAPI
SysReAllocString(LPBSTR old
,LPOLESTR in
)
92 * Make sure we free the old string.
98 * Allocate the new string
100 *old
= SysAllocString(in
);
105 /******************************************************************************
106 * SysAllocStringLen16 [OLE2DISP.4]
108 BSTR16 WINAPI
SysAllocStringLen16(char *in
, int len
)
110 BSTR16 out
=BSTR_AllocBytes(len
+1);
112 strcpy(BSTR_GetAddr(out
),in
);
116 /******************************************************************************
117 * SysAllocStringLen32 [OLEAUT32.4]
119 * In "Inside OLE, second edition" by Kraig Brockshmidt. In the Automation
120 * section, he describes the DWORD value placed before the BSTR data type.
121 * he describes it as a "DWORD count of characters". By experimenting with
122 * a windows application, this count seems to be a DWORD count of bytes in
123 * the string. Meaning that the count is double the number of wide
124 * characters in the string.
126 BSTR WINAPI
SysAllocStringLen(WCHAR
*in
, int len
)
133 * Find the lenth of the buffer passed-in in bytes.
135 bufferSize
= len
* sizeof (WCHAR
);
138 * Allocate a new buffer to hold the string.
139 * dont't forget to keep an empty spot at the begining of the
140 * buffer for the character count and an extra character at the
143 newBuffer
= (DWORD
*)HeapAlloc(GetProcessHeap(),
145 bufferSize
+ sizeof(WCHAR
) + sizeof(DWORD
));
148 * If the memory allocation failed, return a null pointer.
154 * Copy the length of the string in the placeholder.
156 *newBuffer
= bufferSize
;
159 * Skip the byte count.
164 * Copy the information in the buffer.
165 * Since it is valid to pass a NULL pointer here, we'll initialize the
166 * buffer to nul if it is the case.
169 memcpy(newBuffer
, in
, bufferSize
);
171 memset(newBuffer
, 0, bufferSize
);
174 * Make sure that there is a nul character at the end of the
177 stringBuffer
= (WCHAR
*)newBuffer
;
178 stringBuffer
[len
] = L
'\0';
180 return (LPWSTR
)stringBuffer
;
183 /******************************************************************************
184 * SysReAllocStringLen16 [OLE2DISP.5]
186 int WINAPI
SysReAllocStringLen16(BSTR16
*old
,char *in
,int len
)
188 BSTR16
new=SysAllocStringLen16(in
,len
);
195 /******************************************************************************
196 * SysReAllocStringLen32 [OLEAUT32.5]
198 int WINAPI
SysReAllocStringLen(BSTR
* old
, WCHAR
* in
, int len
)
207 * Make sure we free the old string.
213 * Allocate the new string
215 *old
= SysAllocStringLen(in
, len
);
220 /******************************************************************************
221 * SysFreeString16 [OLE2DISP.6]
223 void WINAPI
SysFreeString16(BSTR16 in
)
228 /******************************************************************************
229 * SysFreeString32 [OLEAUT32.6]
231 void WINAPI
SysFreeString(BSTR in
)
233 DWORD
* bufferPointer
;
236 * We have to be careful when we free a BSTR pointer, it points to
237 * the beginning of the string but it skips the byte count contained
240 bufferPointer
= (DWORD
*)in
;
245 * Free the memory from it's "real" origin.
247 HeapFree(GetProcessHeap(), 0, bufferPointer
);
250 /******************************************************************************
251 * SysStringLen16 [OLE2DISP.7]
253 int WINAPI
SysStringLen16(BSTR16 str
)
255 return strlen(BSTR_GetAddr(str
));
258 /******************************************************************************
259 * SysStringLen32 [OLEAUT32.7]
261 * The Windows documentation states that the length returned by this function
262 * is not necessarely the same as the length returned by the _lstrlenW method.
263 * It is the same number that was passed in as the "len" parameter if the
264 * string was allocated with a SysAllocStringLen method call.
266 int WINAPI
SysStringLen(BSTR str
)
268 DWORD
* bufferPointer
;
271 * The length of the string (in bytes) is contained in a DWORD placed
272 * just before the BSTR pointer
274 bufferPointer
= (DWORD
*)str
;
278 return (int)(*bufferPointer
/sizeof(WCHAR
));
281 /******************************************************************************
282 * SysStringByteLen [OLEAUT32.149]
284 * The Windows documentation states that the length returned by this function
285 * is not necessarely the same as the length returned by the _lstrlenW method.
286 * It is the same number that was passed in as the "len" parameter if the
287 * string was allocated with a SysAllocStringLen method call.
289 int WINAPI
SysStringByteLen(BSTR str
)
291 return SysStringLen(str
)*sizeof(WCHAR
);
294 /******************************************************************************
295 * CreateDispTypeInfo [OLE2DISP.31]
297 OLESTATUS WINAPI
CreateDispTypeInfo16(
298 INTERFACEDATA
*pidata
,
300 LPVOID
**pptinfo
/*ITypeInfo*/
302 FIXME(ole
,"(%p,%ld,%p),stub\n",pidata
,lcid
,pptinfo
);
306 /******************************************************************************
307 * RegisterActiveObject [OLE2DISP.35]
309 OLESTATUS WINAPI
RegisterActiveObject16(
310 IUnknown
* punk
,REFCLSID rclsid
,DWORD dwFlags
, DWORD
* pdwRegister
313 WINE_StringFromCLSID(rclsid
,buf
);
314 FIXME(ole
,"(%p,%s,0x%08lx,%p):stub\n",punk
,buf
,dwFlags
,pdwRegister
);
318 /******************************************************************************
319 * OleTranslateColor [OLEAUT32.421]
321 INT WINAPI
OleTranslateColor(
326 FIXME(ole
,"():stub\n");