4 * Copyright 1995 Martin von Loewis
15 /* This implementation of the BSTR API is 16-bit only. It
16 represents BSTR as a 16:16 far pointer, and the strings
20 HGLOBAL BSTRheapsel
=0;
21 #define BSTR_HEAP_SIZE 65536
23 static BSTR
BSTR_AllocBytes(int n
)
28 BSTRheapsel
=GlobalAlloc(GMEM_FIXED
,BSTR_HEAP_SIZE
);
29 LocalInit(BSTRheapsel
,0,BSTR_HEAP_SIZE
-1);
33 mem
=LOCAL_Alloc(BSTRheapsel
,LMEM_FIXED
,n
);
37 return mem
? MAKELONG(mem
,BSTRheapsel
) : 0;
41 static void BSTR_Free(BSTR in
)
44 LOCAL_Free(BSTRheapsel
, (HANDLE
)in
);
46 LOCAL_Free(BSTRheapsel
, LOWORD(in
));
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);
62 strcpy(BSTR_GetAddr(out
),in
);
66 /***********************************************************************
67 * SysReAllocString [OLE2DISP.3]
69 int SysReAllocString(BSTR
*old
,char *in
)
71 BSTR
new=SysAllocString(in
);
77 /***********************************************************************
78 * SysAllocStringLen [OLE2DISP.4]
80 BSTR
SysAllocStringLen(char *in
, int len
)
82 BSTR out
=BSTR_AllocBytes(len
+1);
84 strcpy(BSTR_GetAddr(out
),in
);
88 /***********************************************************************
89 * SysReAllocStringLen [OLE2DISP.5]
91 int SysReAllocStringLen(BSTR
*old
,char *in
,int len
)
93 BSTR
new=SysAllocStringLen(in
,len
);
99 /***********************************************************************
100 * SysFreeString [OLE2DISP.6]
102 void SysFreeString(BSTR in
)
107 /***********************************************************************
108 * SysStringLen [OLE2DISP.7]
110 int SysStringLen(BSTR str
)
112 return strlen(BSTR_GetAddr(str
));