root/swishctl/src/AnsiBSTR.cpp

Revision 1236, 2.5 kB (checked in by augur, 5 years ago)

Added license and copyright information.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * $Id$
3  *
4  * SwishCtl - SWISH-E API ActiveX Control
5  * Copyright (c) 2003 Peoples Resource Centre Wellington NZ
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 // AnsiBSTR.cpp: implementation of the CAnsiBSTR class.
23 //
24 //////////////////////////////////////////////////////////////////////
25
26 #include "stdafx.h"
27 #include "AnsiBSTR.h"
28
29 //////////////////////////////////////////////////////////////////////
30 // Construction/Destruction
31 //////////////////////////////////////////////////////////////////////
32
33 CAnsiBSTR::CAnsiBSTR(const char *source)
34 {
35         int sourcelen = strlen( source );
36         //m_cstr = NULL;       
37         wchar_t *wbuffer = (wchar_t *)calloc( sourcelen + 1, sizeof(wchar_t));
38
39         if ( ! wbuffer ) return;       
40
41         MultiByteToWideChar(  CP_ACP,         // code page
42                 NULL,         // character-type options
43                 source, // string to map
44                 sourcelen,       // number of bytes in string
45                 wbuffer,  // wide-character buffer
46                 sourcelen + 1        // size of buffer
47                 );
48         this->Attach(SysAllocString( wbuffer ));
49         free( wbuffer );
50 }
51
52 CAnsiBSTR::~CAnsiBSTR()
53 {
54         //if ( m_cstr ) free( m_cstr );
55 }
56
57
58
59 CAnsiBSTR::CAnsiBSTR(BSTR bstr)
60 {
61         //m_cstr = NULL;       
62         this->Attach( bstr );
63 }
64
65 // -----------------------------
66
67
68 CAnsiStr::~CAnsiStr()
69 {
70         if ( m_cstr ) free( m_cstr );
71 }
72
73 char * CAnsiStr::c_str()
74 {
75         return m_cstr;
76 }
77
78 CAnsiStr::CAnsiStr(BSTR bstr)
79 {
80         m_cstr = NULL; 
81
82         int sourcelen = SysStringLen(bstr);
83        
84         m_cstr = (char *) calloc( sourcelen + 1, sizeof(char));
85
86         if ( ! m_cstr ) return;         
87        
88         WideCharToMultiByte( 
89                 CP_ACP,          // code page
90                 NULL,        // performance and mapping flags
91                 bstr,    // wide-character string
92                 sourcelen,          // number of chars in string
93                 m_cstr ,     // buffer for new string
94                 sourcelen + 1,          // size of buffer
95                 NULL,     // default for unmappable chars NULL
96                 NULL  // set when default char used
97                 );
98        
99         m_cstr [sourcelen] = '\0';
100 }
101
Note: See TracBrowser for help on using the browser.