블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2737)
Unity3D (817)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-25 00:00

//-- 인코딩 지정 변환 예

System::Text::Encoding^ m_encoding;

m_encoding = gcnew System::Text::UTF8Encoding();
m_stat, sql::SQLException* : legacy native c++ pointer

int execute(String^ sql) 
try {
assert(m_stat); 
if (!m_encoding) {
return m_stat->execute(getAnsiString(sql)); //.net -> native
} else {

array<unsigned char>^ bytes = m_encoding->GetBytes(sql);
pin_ptr<unsigned char> s = &bytes[0];
return m_stat->execute((const char*)s);   //.net -> native
}
} catch (sql::SQLException *ex) {
throw gcnew SQLException(ex, sql);
}
}

//-- utf8 로 저장된 문자열 배열을, .net 유니코드 문자열 배열로 변환
array<String^>^ convStrArray(const std::vector<std::string> &arrStr) //native -> .net
{
size_t cnt = arrStr.size();
UTF8Encoding^ encode = gcnew UTF8Encoding(true,true);
        array<String^>^ arr = gcnew array<String^>(cnt);
        for (size_t i = 0; i < cnt; i++)
            arr[i] = gcnew String(arrStr[i].c_str(), 0, arrStr[i].size(), encode);

        return arr;
}


//-- strconv.h, vs2005/8

#pragma once

#include <vcclr.h>
#include <string>

using namespace System;
using namespace System::Runtime::InteropServices;

inline
std::string getAnsiString(String^ s) 
{
    IntPtr ip = Marshal::StringToHGlobalAnsi(s);
    const char* str = static_cast<const char*>(ip.ToPointer());

    std::string ansi(str);
    
    Marshal::FreeHGlobal( ip );

    return ansi;
}

inline
std::wstring getUniString(String^ s)
{
    pin_ptr<const wchar_t> str = PtrToStringChars(s);

    std::wstring uni(str);
    return uni;
반응형

'Programming > C++/CLI' 카테고리의 다른 글

System::String -> char* OR wchar_t*  (0) 2010.05.26
CLI - 초무식, 초단순 암기용 저장글  (0) 2010.05.26
C++/CLI 예제  (0) 2010.05.25
참고 사이트  (0) 2010.05.25
CLI의 기본 타입  (0) 2010.05.25
Posted by blueasa
, |