![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 /* 00002 * Utils - Some helper & utility stuff. 00003 * 00004 * @Author Michael <Tharbas> Matzen 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU General Public License as published by the Free 00008 * Software Foundation; either version 2 of the License, or (at your option) 00009 * any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, but WITHOUT 00012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00014 * more details. 00015 * 00016 * You should have received a copy of the GNU General Public License along with 00017 * this program; if not, write to the Free Software Foundation, Inc., 51 00018 * Franklin St, Fifth Floor, Boston, MA 02110, USA 00019 * 00020 */ 00021 #pragma once 00022 00023 #include "stdafx.h" 00024 00025 #include <stdio.h> 00026 #include <stdlib.h> 00027 #include <iostream> 00028 #include <map> 00029 #include <memory> 00030 00031 00035 __inline std::string convertString(const wchar_t* string) 00036 { 00037 size_t size = sizeof(wchar_t)*wcslen(string); 00038 size_t outCharCount; 00039 char *buf = new char[size]; 00040 wcstombs_s(&outCharCount, buf, size, string, size); 00041 std::string ret(buf); 00042 delete[] buf; 00043 return ret; 00044 } 00045 00049 __inline wchar_t* convertString(const std::string& string) 00050 { 00051 //the memory allocated here should theoretically be managed by the DLLBind mechanism, so there is no corresponding delete 00052 //If at a later time, we find a memory leak in the applicable, this could be it. 00053 wchar_t *ret = new wchar_t[string.size()]; 00054 00055 size_t size = (size_t)string.size(); 00056 size_t outCharCount; 00057 mbstowcs_s(&outCharCount, ret, size+1, string.c_str(),size); 00058 return ret; 00059 }
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.