4 * Copyright 1995 Martin von Loewis
12 #include "interfaces.h"
17 /* This implementation of the BSTR API is 16-bit only. It
18 represents BSTR as a 16:16 far pointer, and the strings
21 /******************************************************************************
22 * BSTR_AllocBytes [Internal]
24 static BSTR16
BSTR_AllocBytes(int n
)
26 void *ptr
= SEGPTR_ALLOC(n
);
27 return (BSTR16
)SEGPTR_GET(ptr
);
30 /******************************************************************************
31 * BSTR_Free [INTERNAL]
33 static void BSTR_Free(BSTR16 in
)
35 SEGPTR_FREE( PTR_SEG_TO_LIN(in
) );
38 /******************************************************************************
39 * BSTR_GetAddr [INTERNAL]
41 static void* BSTR_GetAddr(BSTR16 in
)
43 return in
? PTR_SEG_TO_LIN(in
) : 0;
46 /******************************************************************************
47 * SysAllocString16 [OLE2DISP.2]
49 BSTR16 WINAPI
SysAllocString16(LPOLESTR16 in
)
51 BSTR16 out
=BSTR_AllocBytes(strlen(in
)+1);
53 strcpy(BSTR_GetAddr(out
),in
);
57 /******************************************************************************
58 * SysAllocString32 [OLEAUT32.2]
60 BSTR32 WINAPI
SysAllocString32(LPOLESTR32 in
)
62 /* Delegate this to the SysAllocStringLen32 method. */
63 return SysAllocStringLen32(in
, lstrlen32W(in
));
66 /******************************************************************************
67 * SysReAllocString16 [OLE2DISP.3]
69 INT16 WINAPI
SysReAllocString16(LPBSTR16 old
,LPOLESTR16 in
)
71 BSTR16
new=SysAllocString16(in
);
77 /******************************************************************************
78 * SysReAllocString32 [OLEAUT32.3]
80 INT32 WINAPI
SysReAllocString32(LPBSTR32 old
,LPOLESTR32 in
)
89 * Make sure we free the old string.
92 SysFreeString32(*old
);
95 * Allocate the new string
97 *old
= SysAllocString32(in
);
102 /******************************************************************************
103 * SysAllocStringLen16 [OLE2DISP.4]
105 BSTR16 WINAPI
SysAllocStringLen16(char *in
, int len
)
107 BSTR16 out
=BSTR_AllocBytes(len
+1);
109 strcpy(BSTR_GetAddr(out
),in
);
113 /******************************************************************************
114 * SysAllocStringLen32 [OLEAUT32.4]
116 * In "Inside OLE, second edition" by Kraig Brockshmidt. In the Automation
117 * section, he describes the DWORD value placed before the BSTR data type.
118 * he describes it as a "DWORD count of characters". By experimenting with
119 * a windows application, this count seems to be a DWORD count of bytes in
120 * the string. Meaning that the count is double the number of wide
121 * characters in the string.
123 BSTR32 WINAPI
SysAllocStringLen32(WCHAR
*in
, int len
)
130 * Find the lenth of the buffer passed-in in bytes.
132 bufferSize
= len
* sizeof (WCHAR
);
135 * Allocate a new buffer to hold the string.
136 * dont't forget to keep an empty spot at the begining of the
137 * buffer for the character count and an extra character at the
140 newBuffer
= (DWORD
*)HeapAlloc(GetProcessHeap(),
142 bufferSize
+ sizeof(WCHAR
) + sizeof(DWORD
));
145 * If the memory allocation failed, return a null pointer.
151 * Copy the length of the string in the placeholder.
153 *newBuffer
= bufferSize
;
156 * Skip the byte count.
161 * Copy the information in the buffer.
162 * Since it is valid to pass a NULL pointer here, we'll initialize the
163 * buffer to nul if it is the case.
166 memcpy(newBuffer
, in
, bufferSize
);
168 memset(newBuffer
, 0, bufferSize
);
171 * Make sure that there is a nul character at the end of the
174 stringBuffer
= (WCHAR
*)newBuffer
;
175 stringBuffer
[len
] = L
'\0';
177 return (LPWSTR
)stringBuffer
;
180 /******************************************************************************
181 * SysReAllocStringLen16 [OLE2DISP.5]
183 int WINAPI
SysReAllocStringLen16(BSTR16
*old
,char *in
,int len
)
185 BSTR16
new=SysAllocStringLen16(in
,len
);
192 /******************************************************************************
193 * SysReAllocStringLen32 [OLEAUT32.5]
195 int WINAPI
SysReAllocStringLen32(BSTR32
* old
, WCHAR
* in
, int len
)
204 * Make sure we free the old string.
207 SysFreeString32(*old
);
210 * Allocate the new string
212 *old
= SysAllocStringLen32(in
, len
);
217 /******************************************************************************
218 * SysFreeString16 [OLE2DISP.6]
220 void WINAPI
SysFreeString16(BSTR16 in
)
225 /******************************************************************************
226 * SysFreeString32 [OLEAUT32.6]
228 void WINAPI
SysFreeString32(BSTR32 in
)
230 DWORD
* bufferPointer
;
233 * We have to be careful when we free a BSTR pointer, it points to
234 * the beginning of the string but it skips the byte count contained
237 bufferPointer
= (DWORD
*)in
;
242 * Free the memory from it's "real" origin.
244 HeapFree(GetProcessHeap(), 0, bufferPointer
);
247 /******************************************************************************
248 * SysStringLen16 [OLE2DISP.7]
250 int WINAPI
SysStringLen16(BSTR16 str
)
252 return strlen(BSTR_GetAddr(str
));
255 /******************************************************************************
256 * SysStringLen32 [OLEAUT32.7]
258 * The Windows documentation states that the length returned by this function
259 * is not necessarely the same as the length returned by the _lstrlenW method.
260 * It is the same number that was passed in as the "len" parameter if the
261 * string was allocated with a SysAllocStringLen method call.
263 int WINAPI
SysStringLen32(BSTR32 str
)
265 DWORD
* bufferPointer
;
268 * The length of the string (in bytes) is contained in a DWORD placed
269 * just before the BSTR pointer
271 bufferPointer
= (DWORD
*)str
;
275 return (int)(*bufferPointer
/sizeof(WCHAR
));
278 /******************************************************************************
279 * CreateDispTypeInfo [OLE2DISP.31]
281 OLESTATUS WINAPI
CreateDispTypeInfo(
282 INTERFACEDATA
*pidata
,
284 LPVOID
**pptinfo
/*ITypeInfo*/
286 FIXME(ole
,"(%p,%ld,%p),stub\n",pidata
,lcid
,pptinfo
);
290 /******************************************************************************
291 * RegisterActiveObject [OLE2DISP.35]
293 OLESTATUS WINAPI
RegisterActiveObject(
294 IUnknown
* punk
,REFCLSID rclsid
,DWORD dwFlags
, DWORD
* pdwRegister
297 WINE_StringFromCLSID(rclsid
,buf
);
298 FIXME(ole
,"(%p,%s,0x%08lx,%p):stub\n",punk
,buf
,dwFlags
,pdwRegister
);