Contents

조회 수 11467 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
▶ 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
번호 분류 제목 글쓴이 날짜 조회 수
385 Develop [ios] Objective-C 문자열 조작 메서드 hooni 2013.04.23 26461
384 Develop [ios] Objective-C 에서 자주 사용하는 수학 함수와 유용한 Define hooni 2014.08.08 1879
383 Develop [ios] Objective-C 특정 문자 찾아 제거하기 hooni 2013.04.23 28072
382 Develop [ios] Objective-C 프로퍼티의 ATOMIC / NONATOMIC 속성 hooni 2014.03.17 3007
381 Develop [ios] Objective-C 프로퍼티의 strong, weak, assign file hooni 2014.03.17 4695
380 Develop [ios] Objective-C에서 SQLite 사용하기.. file hooni 2013.04.23 14563
379 Develop [ios] Objective-C에서 형식이 있는 문자열(Format Strings)에 사용할 수 있는 토큰들(Tokens) file hooni 2013.04.23 18790
378 Develop [ios] PHP로 APNS 프로바이더~ file hooni 2013.06.27 16870
377 Develop [ios] Pod 특정 버전 설치하고 사용하기 hooni 2022.05.28 1576
376 Develop [ios] Random Thoughts: Rand() vs. arc4random() hooni 2013.10.31 68062
375 Develop [ios] Requesting Location Permissions in iOS file hooni 2018.08.18 1619
374 Develop [ios] SBCampanion App 초안 file hooni 2015.09.16 670
Board Pagination Prev 1 ... 34 35 36 37 38 39 40 41 42 43 ... 71 Next
/ 71