Release 960516
[wine.git] / misc / ole2disp.c
blobe738adcde1d9be1dfdf96ceedc2e515c22675136
1 /*
2 * OLE2DISP library
4 * Copyright 1995 Martin von Loewis
5 */
7 #include "windows.h"
8 #include "ole2.h"
9 #include "global.h"
10 #include "local.h"
11 #include "ldt.h"
12 #include "stddebug.h"
13 #include "debug.h"
15 /* This implementation of the BSTR API is 16-bit only. It
16 represents BSTR as a 16:16 far pointer, and the strings
17 as ISO-8859 */
19 typedef DWORD BSTR;
20 HGLOBAL BSTRheapsel=0;
21 #define BSTR_HEAP_SIZE 65536
23 static BSTR BSTR_AllocBytes(int n)
25 HLOCAL16 mem;
26 if(!BSTRheapsel)
28 BSTRheapsel=GlobalAlloc16(GMEM_FIXED,BSTR_HEAP_SIZE);
29 LocalInit(BSTRheapsel,0,BSTR_HEAP_SIZE-1);
31 if(!BSTRheapsel)
32 return 0;
33 mem=LOCAL_Alloc(BSTRheapsel,LMEM_FIXED,n);
34 #ifdef WINELIB32
35 return (BSTR)mem;
36 #else
37 return mem ? MAKELONG(mem,BSTRheapsel) : 0;
38 #endif
41 static void BSTR_Free(BSTR in)
43 #ifdef WINELIB32
44 LOCAL_Free(BSTRheapsel, (HANDLE)in);
45 #else
46 LOCAL_Free(BSTRheapsel, LOWORD(in));
47 #endif
50 static void* BSTR_GetAddr(BSTR in)
52 return in ? PTR_SEG_TO_LIN(in) : 0;
55 /***********************************************************************
56 * SysAllocString [OLE2DISP.2]
58 BSTR SysAllocString(char *in)
60 BSTR out=BSTR_AllocBytes(strlen(in)+1);
61 if(!out)return 0;
62 strcpy(BSTR_GetAddr(out),in);
63 return out;
66 /***********************************************************************
67 * SysReAllocString [OLE2DISP.3]
69 int SysReAllocString(BSTR *old,char *in)
71 BSTR new=SysAllocString(in);
72 BSTR_Free(*old);
73 *old=new;
74 return 1;
77 /***********************************************************************
78 * SysAllocStringLen [OLE2DISP.4]
80 BSTR SysAllocStringLen(char *in, int len)
82 BSTR out=BSTR_AllocBytes(len+1);
83 if(!out)return 0;
84 strcpy(BSTR_GetAddr(out),in);
85 return out;
88 /***********************************************************************
89 * SysReAllocStringLen [OLE2DISP.5]
91 int SysReAllocStringLen(BSTR *old,char *in,int len)
93 BSTR new=SysAllocStringLen(in,len);
94 BSTR_Free(*old);
95 *old=new;
96 return 1;
99 /***********************************************************************
100 * SysFreeString [OLE2DISP.6]
102 void SysFreeString(BSTR in)
104 BSTR_Free(in);
107 /***********************************************************************
108 * SysStringLen [OLE2DISP.7]
110 int SysStringLen(BSTR str)
112 return strlen(BSTR_GetAddr(str));