Contents

Views 11502 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
▶ CString -> BYTE
BYTE*   temp;
CString   cmd;
에서 cmd 의 값을 temp에 할당하려 할때.

temp=new BYTE[255];
temp=(LPBYTE)(LPCSTR)cmd;
delete []temp;
or
CString str = _T("abcd");
BYTE* pbyte = new BYTE[256];
int nSize;
nSize = str.GetLength();
CopyMemory( pbyte, str.GetBuffer(nSize), nSize );
pbyte[nSize] = 0;
or
strcpy(szNamePlace,(LPCTSTR)name);
or
CString str = "string";
BYTE* pByte;
pByte = (BYTE*)(LPTSTR)(LPCTSTR)str;

▶ BYTE -> CString
CString testString;
BYTE    testByte;
testString.Format( "%s", testByte );

▶ CString -> BYTE *
CString name = "몽룡이";
BYTE byte[26] = {0};
BYTE bName[26] = {0x0,};

sprintf((char*)byte, "%s", name);

memcpy(bName, byte, 26);

CString strTmp1, strTmp2;
strTmp1 = "";
strTmp2 = "";

for(int i=0; i<26; i++) {
     strTmp1.Format("%02X ", bName[i]);
     strTmp2 += strTmp1;
}
MessageBox(strTmp2, "", 0);
//26바이트의 크기의 이름이다.
//남는 공간은 0으로 채워진다

▶  CString -> int
CString의 문자열을 바로 숫자로 바꾸는것은 아직 보지 못했습니다.
아마 atoi()나 atod()의 C함수를 사용해야 될것 같네요.
도움말을 참고하세요.

▶  int -> CString
CString str;
int i = 6;
str.Format("%d",i);  // str에 6의 문자가 들어갑니다.

▶  BYTE -> int, int -> BYTE 
// 바로 형변환으로 가능합니다.
// 주의 : 작은 크기로 들어가기 때문에 
// 255 이상의 값은 엉뚱하게 동작하겠지요.
bt = (BYTE)i;
i = (int)bt;

▶ CString  -> char* 변환
char * ch;
CString *str;

1) ch = (LPSTR)(LPCSTR)str; 
2) ch = str.GetBuffer(str.GetLength());
3) wsprintf( ch, "%s", str);

▶ char*  ->  CString 변환
//1)
str = (LPCSTR)(LPSTR)ch;

//2)
str = ch;

참고)
LPSTR 은 char* 입니다.
LPSTR : char stirng의 32비트 포인터, char* 와 같다.
LPCTSTR : Constant character String의 32비트 포인터

UINT : 32비트 unsigned형 정수
DWORD : unsigned long int형

BYTE : 8비트 unsigned 정수

1.CString 클래스의 GetBuffer()는 CString을 char *로 바꿔줍니다. 
ex)
CString strTemp = _T("test"); 
char *getTemp=NULL; 

getTemp = malloc(strTemp.GetLength()+1); 
strcpy(getTemp, strTemp.GetBuffer(strTemp.GetLength()); 
printf("결과:%sn", getTemp); 

free(getTemp);

2. operator LPCTSTR ()도 마찬가지입니다.
ex)
CString strTemp = _T("test");
char *getTemp = (LPSTR)(LPCSTR)strData;


CString -> BYTE* 변환
CString str="1234";

BYTE *pbyte;
pbyte = (BYTE(LPSTR)(LPCSTR)str;

CString str = _T("abcd");
BYTE* pbyte = new BYTE[256];

int nSize;
nSize = str.GetLength();

CopyMemory( pbyte, str.GetBuffer(nSize), nSize );
pbyte[nSize] = 0;

CString  -> char* 변환
char * ch;
CString *str;

//1)
ch = (LPSTR)(LPCSTR)str; 

//2)
ch = str.GetBuffer(str.GetLength());

//3)
wsprintf( ch, "%s", str);

char*  ->  CString 변환
//1)
str = (LPCSTR)(LPSTR)ch;

//2)
str = ch;

[참고]
CString을 const char* 형태로 변경 -> (LPTSTR)(LPCTSTR)CString

LPCSTR :  A 32-bit pointer to a constant character string.
LPSTR :  A 32-bit pointer to a character string.
LPCTSTR :  A 32-bit pointer to a constant character string that is portable for Unicode and DBCS.
LPTSTR :  A 32-bit pointer to a character string that is portable for Unicode and DBCS.

?

List of Articles
No. Category Subject Author Date Views
153 System/OS [sql] 중복데이터 삭제 쿼리 hooni 2013.04.23 14813
152 Database [sql] 쿼리로 문자열 검색해서 일괄 치환하기 hooni 2014.02.13 10066
151 Database [sql] 한눈에 보이는 Join file hooni 2014.02.19 8549
150 System/OS [svn] Can't convert string from native encoding to 'UTF-8' 메시지가 나오는 경우 hooni 2014.12.18 1163
149 System/OS [svn] SVN trunk 변경사항 되돌리기 (SVN Rollback) hooni 2014.11.27 1714
148 Etc [svn] 콘솔에서 svn 사용시 레티나용 이미지 add 안될 때.. hooni 2013.09.25 37646
147 System/OS [svn] 하나의 SVN에서 멀티 저장소 (One svnserve, multiple repositories) hooni 2015.01.02 1794
146 Develop [swift] NotificationCenter 간단 예제 file hooni 2021.01.27 8340
145 Develop [swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기 file hooni 2021.01.29 1599
144 Develop [swift] UIView에서 subview 찾기 hooni 2022.12.09 2059
143 Develop [swift] 실행시간 측정하기 hooni 2021.09.14 844
142 System/OS [switch] 시스코 스위치 관리자 암호 초기화 방법 hooni 2013.04.23 17290
Board Pagination Prev 1 ... 81 82 83 84 85 86 87 88 89 90 ... 98 Next
/ 98