Implemented SHBrowseForFolder() dialog.
[wine/multimedia.git] / ole / ole2disp.c
blobdea2df112724279d3f66688a4eced5ca96adecd4
1 /*
2 * OLE2DISP library
4 * Copyright 1995 Martin von Loewis
5 */
7 #include <string.h>
8 #include "windows.h"
9 #include "ole.h"
10 #include "ole2.h"
11 #include "oleauto.h"
12 #include "wtypes.h"
13 #include "wine/obj_base.h"
14 #include "objbase.h"
15 #include "heap.h"
16 #include "ldt.h"
17 #include "debug.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
21 as ISO-8859 */
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);
54 if(!out)return 0;
55 strcpy(BSTR_GetAddr(out),in);
56 return out;
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);
74 BSTR_Free(*old);
75 *old=new;
76 return 1;
79 /******************************************************************************
80 * SysReAllocString32 [OLEAUT32.3]
82 INT32 WINAPI SysReAllocString32(LPBSTR32 old,LPOLESTR32 in)
85 * Sanity check
87 if (old==NULL)
88 return 0;
91 * Make sure we free the old string.
93 if (*old!=NULL)
94 SysFreeString32(*old);
97 * Allocate the new string
99 *old = SysAllocString32(in);
101 return 1;
104 /******************************************************************************
105 * SysAllocStringLen16 [OLE2DISP.4]
107 BSTR16 WINAPI SysAllocStringLen16(char *in, int len)
109 BSTR16 out=BSTR_AllocBytes(len+1);
110 if(!out)return 0;
111 strcpy(BSTR_GetAddr(out),in);
112 return out;
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)
127 DWORD bufferSize;
128 DWORD* newBuffer;
129 WCHAR* stringBuffer;
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
140 * end for the NULL.
142 newBuffer = (DWORD*)HeapAlloc(GetProcessHeap(),
144 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
147 * If the memory allocation failed, return a null pointer.
149 if (newBuffer==0)
150 return 0;
153 * Copy the length of the string in the placeholder.
155 *newBuffer = bufferSize;
158 * Skip the byte count.
160 newBuffer++;
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.
167 if (in != 0)
168 memcpy(newBuffer, in, bufferSize);
169 else
170 memset(newBuffer, 0, bufferSize);
173 * Make sure that there is a nul character at the end of the
174 * string.
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);
188 BSTR_Free(*old);
189 *old=new;
190 return 1;
194 /******************************************************************************
195 * SysReAllocStringLen32 [OLEAUT32.5]
197 int WINAPI SysReAllocStringLen32(BSTR32* old, WCHAR* in, int len)
200 * Sanity check
202 if (old==NULL)
203 return 0;
206 * Make sure we free the old string.
208 if (*old!=NULL)
209 SysFreeString32(*old);
212 * Allocate the new string
214 *old = SysAllocStringLen32(in, len);
216 return 1;
219 /******************************************************************************
220 * SysFreeString16 [OLE2DISP.6]
222 void WINAPI SysFreeString16(BSTR16 in)
224 BSTR_Free(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
237 * before the string.
239 bufferPointer = (DWORD*)in;
241 bufferPointer--;
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;
275 bufferPointer--;
277 return (int)(*bufferPointer/sizeof(WCHAR));
280 /******************************************************************************
281 * CreateDispTypeInfo [OLE2DISP.31]
283 OLESTATUS WINAPI CreateDispTypeInfo(
284 INTERFACEDATA *pidata,
285 LCID lcid,
286 LPVOID **pptinfo /*ITypeInfo*/
288 FIXME(ole,"(%p,%ld,%p),stub\n",pidata,lcid,pptinfo);
289 return 0;
292 /******************************************************************************
293 * RegisterActiveObject [OLE2DISP.35]
295 OLESTATUS WINAPI RegisterActiveObject(
296 IUnknown * punk,REFCLSID rclsid,DWORD dwFlags, DWORD * pdwRegister
298 char buf[80];
299 WINE_StringFromCLSID(rclsid,buf);
300 FIXME(ole,"(%p,%s,0x%08lx,%p):stub\n",punk,buf,dwFlags,pdwRegister);
301 return 0;