4 * Copyright 1995 Martin von Loewis
13 #include "wine/obj_base.h"
19 /* This implementation of the BSTR API is 16-bit only. It
20 represents BSTR as a 16:16 far pointer, and the strings
23 /******************************************************************************
24 * BSTR_AllocBytes [Internal]
26 static BSTR16
BSTR_AllocBytes(int n
)
28 void *ptr
= SEGPTR_ALLOC(n
);
29 return (BSTR16
)SEGPTR_GET(ptr
);
32 /******************************************************************************
33 * BSTR_Free [INTERNAL]
35 static void BSTR_Free(BSTR16 in
)
37 SEGPTR_FREE( PTR_SEG_TO_LIN(in
) );
40 /******************************************************************************
41 * BSTR_GetAddr [INTERNAL]
43 static void* BSTR_GetAddr(BSTR16 in
)
45 return in
? PTR_SEG_TO_LIN(in
) : 0;
48 /******************************************************************************
49 * SysAllocString16 [OLE2DISP.2]
51 BSTR16 WINAPI
SysAllocString16(LPOLESTR16 in
)
53 BSTR16 out
=BSTR_AllocBytes(strlen(in
)+1);
55 strcpy(BSTR_GetAddr(out
),in
);
59 /******************************************************************************
60 * SysAllocString32 [OLEAUT32.2]
62 BSTR32 WINAPI
SysAllocString32(LPOLESTR32 in
)
64 /* Delegate this to the SysAllocStringLen32 method. */
65 return SysAllocStringLen32(in
, lstrlen32W(in
));
68 /******************************************************************************
69 * SysReAllocString16 [OLE2DISP.3]
71 INT16 WINAPI
SysReAllocString16(LPBSTR16 old
,LPOLESTR16 in
)
73 BSTR16
new=SysAllocString16(in
);
79 /******************************************************************************
80 * SysReAllocString32 [OLEAUT32.3]
82 INT32 WINAPI
SysReAllocString32(LPBSTR32 old
,LPOLESTR32 in
)
91 * Make sure we free the old string.
94 SysFreeString32(*old
);
97 * Allocate the new string
99 *old
= SysAllocString32(in
);
104 /******************************************************************************
105 * SysAllocStringLen16 [OLE2DISP.4]
107 BSTR16 WINAPI
SysAllocStringLen16(char *in
, int len
)
109 BSTR16 out
=BSTR_AllocBytes(len
+1);
111 strcpy(BSTR_GetAddr(out
),in
);
115 /******************************************************************************
116 * SysAllocStringLen32 [OLEAUT32.4]
118 * In "Inside OLE, second edition" by Kraig Brockshmidt. In the Automation
119 * section, he describes the DWORD value placed before the BSTR data type.
120 * he describes it as a "DWORD count of characters". By experimenting with
121 * a windows application, this count seems to be a DWORD count of bytes in
122 * the string. Meaning that the count is double the number of wide
123 * characters in the string.
125 BSTR32 WINAPI
SysAllocStringLen32(WCHAR
*in
, int len
)
132 * Find the lenth of the buffer passed-in in bytes.
134 bufferSize
= len
* sizeof (WCHAR
);
137 * Allocate a new buffer to hold the string.
138 * dont't forget to keep an empty spot at the begining of the
139 * buffer for the character count and an extra character at the
142 newBuffer
= (DWORD
*)HeapAlloc(GetProcessHeap(),
144 bufferSize
+ sizeof(WCHAR
) + sizeof(DWORD
));
147 * If the memory allocation failed, return a null pointer.
153 * Copy the length of the string in the placeholder.
155 *newBuffer
= bufferSize
;
158 * Skip the byte count.
163 * Copy the information in the buffer.
164 * Since it is valid to pass a NULL pointer here, we'll initialize the
165 * buffer to nul if it is the case.
168 memcpy(newBuffer
, in
, bufferSize
);
170 memset(newBuffer
, 0, bufferSize
);
173 * Make sure that there is a nul character at the end of the
176 stringBuffer
= (WCHAR
*)newBuffer
;
177 stringBuffer
[len
] = L
'\0';
179 return (LPWSTR
)stringBuffer
;
182 /******************************************************************************
183 * SysReAllocStringLen16 [OLE2DISP.5]
185 int WINAPI
SysReAllocStringLen16(BSTR16
*old
,char *in
,int len
)
187 BSTR16
new=SysAllocStringLen16(in
,len
);
194 /******************************************************************************
195 * SysReAllocStringLen32 [OLEAUT32.5]
197 int WINAPI
SysReAllocStringLen32(BSTR32
* old
, WCHAR
* in
, int len
)
206 * Make sure we free the old string.
209 SysFreeString32(*old
);
212 * Allocate the new string
214 *old
= SysAllocStringLen32(in
, len
);
219 /******************************************************************************
220 * SysFreeString16 [OLE2DISP.6]
222 void WINAPI
SysFreeString16(BSTR16 in
)
227 /******************************************************************************
228 * SysFreeString32 [OLEAUT32.6]
230 void WINAPI
SysFreeString32(BSTR32 in
)
232 DWORD
* bufferPointer
;
235 * We have to be careful when we free a BSTR pointer, it points to
236 * the beginning of the string but it skips the byte count contained
239 bufferPointer
= (DWORD
*)in
;
244 * Free the memory from it's "real" origin.
246 HeapFree(GetProcessHeap(), 0, bufferPointer
);
249 /******************************************************************************
250 * SysStringLen16 [OLE2DISP.7]
252 int WINAPI
SysStringLen16(BSTR16 str
)
254 return strlen(BSTR_GetAddr(str
));
257 /******************************************************************************
258 * SysStringLen32 [OLEAUT32.7]
260 * The Windows documentation states that the length returned by this function
261 * is not necessarely the same as the length returned by the _lstrlenW method.
262 * It is the same number that was passed in as the "len" parameter if the
263 * string was allocated with a SysAllocStringLen method call.
265 int WINAPI
SysStringLen32(BSTR32 str
)
267 DWORD
* bufferPointer
;
270 * The length of the string (in bytes) is contained in a DWORD placed
271 * just before the BSTR pointer
273 bufferPointer
= (DWORD
*)str
;
277 return (int)(*bufferPointer
/sizeof(WCHAR
));
280 /******************************************************************************
281 * CreateDispTypeInfo [OLE2DISP.31]
283 OLESTATUS WINAPI
CreateDispTypeInfo(
284 INTERFACEDATA
*pidata
,
286 LPVOID
**pptinfo
/*ITypeInfo*/
288 FIXME(ole
,"(%p,%ld,%p),stub\n",pidata
,lcid
,pptinfo
);
292 /******************************************************************************
293 * RegisterActiveObject [OLE2DISP.35]
295 OLESTATUS WINAPI
RegisterActiveObject(
296 IUnknown
* punk
,REFCLSID rclsid
,DWORD dwFlags
, DWORD
* pdwRegister
299 WINE_StringFromCLSID(rclsid
,buf
);
300 FIXME(ole
,"(%p,%s,0x%08lx,%p):stub\n",punk
,buf
,dwFlags
,pdwRegister
);