2010년 06월 03일
[펌]HTTP POST
# by | 2010/06/03 00:58 | C/C++/C#/MFC/Win32 | 트랙백 | 덧글(0)
# by | 2010/06/03 00:58 | C/C++/C#/MFC/Win32 | 트랙백 | 덧글(0)
코딩한 서버를 클라이언트와 붙이면서 데이터 형에서 문제를 많이 일으켰다.
첫째, string 을 tchar로 변환
둘째, 멀티바이트 사용 하는 코딩 과 유니코드 사용(내가 코딩한 것) 것 사이의 문제.
TCHAR을 사용한다고 했지만 서버와 클라 사이의 데이터 이동도 많고
결국에는 내 소스 역시 멀티바이트로(클라가 사람이 많으니 다수를 따라서..) 변환 했고
TCHAR로 처리 되었던 것은 string을 char로 변환해서 마무리 했다.
그 과정에서 찾은 데이터 변환 방법 들...
방법 1. 외국 블로그에서
How to convert std::string to TCHAR*
출처 - http://ukanth.in/blog/?p=180
typedef std::basic_string<TCHAR> tstring;
TCHAR* StringToTCHAR(string& s)
{
tstring tstr;
const char* all = s.c_str();
int len = 1 + strlen(all);
wchar_t* t = new wchar_t[len];
if (NULL == t) throw std::bad_alloc();
mbstowcs(t, all, len);
return (TCHAR*)t;
}
std::string TCHARToString(const TCHAR* ptsz)
{
int len = wcslen((wchar_t*)ptsz);
char* psz = new char[2*len + 1];
wcstombs(psz, (wchar_t*)ptsz, 2*len + 1);
std::string s = psz;
delete [] psz;
return s;
}
추가 - mbstowcs 함수 : multi byte char 을 wide char로 변환
wcstombs 는 mbstowcs 의 반대.
사용 예)
// IdSet->getText() 는 string.
tstring tstr;
const char* all = IdSet->getText().c_str();
int len = strlen(all)+1;
wchar_t* t = new wchar_t[len];
if( t == NULL )
throw std::bad_alloc();
mbstowcs( t, all, len );
방법2. String to char*, char* to TCHAR* (유니코드 사용 환경이였으므로 wchar*)
// IdSet->getText() is stl string
// String to char*
char* strID;
size_t tempSize = IdSet->getText().length();
strID = new char[tempSize];
strcpy( strID, IdSet->getText().c_str() );
// char* to TCHAR*
TCHAR szUniID[256] = {0,};
int len = strlen(strID);
::MultiByteToWideChar( CP_ACP, 0, strID, -1, szUniID, len + 1 );
방법 3. string -> const char* -> char* (멀티바이트 사용)
//IdSet->getText() 은 string
char* id;
const char* strID = IdSet->getText().c_str();
id = const_cast<char*>(strID);
// 합쳐서 사용
id = const_cast<char*>( IdSet->getText().c_str() );
추가 - const char*을 char*로 변환
방법 1. 직접 캐스팅
char* str1;
const char* str2;
str1 = (char*)(str2);
방법 2. 형변환 연산자 const_cast 사용
- const 객체에 대한 포인터를 const가 아닌 객체의 포인터로 변환 할때 사용하는 연산자
str1 = const_cast<char*>(str2);
# by | 2010/04/28 09:59 | C/C++/C#/MFC/Win32 | 트랙백 | 덧글(0)
This post should provide guidance to the individual looking to setup pydbg with the least amount of headache. When last I tried, PaiMei didn't play nice running under cygwin Python. Things worked much better under Python for Windows. I recommend creating a VMware image and then setting up shop in the image. Once you have a suitable image setup, install Python 2.4 for Windows. Next, download and run the ctypes installer for windows.
Now you're ready to install PaiMei. Download it from OpenRCE. Extract the zip file and execute the installer found in the installers directory. If you chose to install under VMware, there is a small hack you may need to implement before pydbg will work correctly inside VMware. To verify that you have a working installation, download my test script, fire up notepad.exe and execute the script. If the script barfs with an error, something is wrong. Otherwise, you are now ready to begin debugging applications from Python.
# by | 2009/10/27 21:22 | 트랙백 | 덧글(0)
# by | 2009/09/04 17:45 | 트랙백 | 덧글(0)
◀ 이전 페이지 다음 페이지 ▶