File: oletypes.c

package info (click to toggle)
camlidl 1.12-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,592 kB
  • sloc: ml: 5,238; ansic: 945; cpp: 908; makefile: 358; xml: 213; sh: 74
file content (53 lines) | stat: -rw-r--r-- 1,804 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/***********************************************************************/
/*                                                                     */
/*                              CamlIDL                                */
/*                                                                     */
/*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
/*                                                                     */
/*  Copyright 1999 Institut National de Recherche en Informatique et   */
/*  en Automatique.  All rights reserved.  This file is distributed    */
/*  under the terms of the GNU Library General Public License.         */
/*                                                                     */
/***********************************************************************/

/* $Id: oletypes.c,v 1.2 2000-08-19 11:05:00 xleroy Exp $ */

/* Support for OLE Automation data types */

#include <string.h>
#include <wchar.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/alloc.h>
#include <caml/fail.h>
#include <caml/callback.h>
#include "camlidlruntime.h"
#include "comstuff.h"
#include <oleauto.h>

static void camlidl_free_bstr(void * data)
{
  SysFreeString((BSTR) data);
}

/* Convert a Caml string to a BSTR */

void camlidl_ml2c_Com_BSTR(value s, BSTR * res, camlidl_ctx ctx)
{
  int len = mbstowcs(NULL, String_val(s), 0);
  BSTR bs = SysAllocStringLen(NULL, len);
  if (bs == NULL) raise_out_of_memory();
  camlidl_register_allocation(camlidl_free_bstr, bs, ctx);
  mbstowcs(bs, String_val(s), len);
  *res = bs;
}

/* Convert a BSTR to a Caml string */

value camlidl_c2ml_Com_BSTR(BSTR * bs, camlidl_ctx ctx)
{
  int len = wcstombs(NULL, *bs, 0);
  value res = alloc_string(len);
  wcstombs(String_val(res), *bs, len);
  return res;
}