source: tol/vbtol/source/vbutils.cpp @ 6d7779d

1941-docker-image-to-testdevel
Last change on this file since 6d7779d was 6d7779d, checked in by Jorge Pérez <josp.jorge@…>, 18 years ago

initial import

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/* tclutils.cpp: This file define a set of utils functions.
2                 GNU/tolTcl Library
3
4   Copyright (C) 2001, 2002, 2003 - Bayes Decisión, SL
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19   USA.
20 */
21
22#include "VButils.h"
23
24/*
25  Convert a Character Array to a BSTR String
26*/
27
28BSTR ChartoBSTR(char* str)
29{
30  int i, Len = strlen(str);
31  unsigned short* FinalStr = new unsigned short[Len + 1];
32
33  for (i=0; i<Len; i++)
34  {
35    unsigned char Part = str[i];
36    FinalStr[i] = Part;
37    FinalStr[i+1] = '\0';
38  }
39  return((BSTR)FinalStr);
40}
41
42FN_PTR VB_Writer = NULL;
43
44void VBTol_gsl_error_handler(const char * reason, const char * file, int line,
45                                                         int gsl_errno)
46{
47  char * buf = new char[strlen(reason)+25];
48
49  sprintf(buf, "GSL Error # %-5d: %s", gsl_errno, reason);
50  if (VB_Writer) {
51    BSTR temp = ChartoBSTR(buf);
52    BSTR ret = SysAllocString(temp);
53    delete[] temp;
54    VB_Writer(ret);
55  }
56  else
57    ::MessageBox(NULL, buf, "C++ DLL", 0);
58  delete[] buf;
59}
60
61void VBTol_HciWriter(const BText & str)
62{
63  if (VB_Writer) {
64    BSTR temp = ChartoBSTR(((BText&)str).Buffer());
65    BSTR ret = SysAllocString(temp);
66    delete[] temp;
67    VB_Writer(ret);
68  }
69  else
70    ::MessageBox(NULL, ((BText&)str).Buffer(), "C++ DLL", 0);
71}
Note: See TracBrowser for help on using the repository browser.