Contents

조회 수 11437 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
729 Develop [c] GD라이브러리 설치 테스트 소스 file hooni 2013.04.23 8143
728 Develop [c] 문자열 치환해주는 str_replace() 함수 file hooni 2013.04.23 7385
727 Develop [c] 숫자(int, Number)를 hex코드로 변환하는 소스 file hooni 2013.04.23 8121
726 Develop [c] 내가 만든 암호화 프로그램.. 좋아^^ file hooni 2013.04.23 7021
725 Develop [c] 암호화 알고리즘 DES 구현 ㅋㅋ file hooni 2013.04.23 7433
724 Develop [c] 학교 건물 최단거리 찾는 웹 연동 프로그램 file hooni 2013.04.23 6800
723 Develop [js] 셀렉트박스(select)의 옵션(option) 동적으로 추가/제거 file hooni 2013.04.23 8060
722 Develop [js] 숫자만 입력하게 하는 자바스크립트 hooni 2013.04.23 6795
721 Develop [c] 패킷 에널라이저 예제 소스(성안당) file hooni 2013.04.23 6947
720 Develop [js] 수명체크 프로그램 ㅋㅋ file hooni 2013.04.23 6838
719 Develop 도메인 관련 솔루션 분석할 거.. ㅋㄷ file hooni 2013.04.23 6981
718 Develop 프로그래밍 소스 관련 사이트.. hooni 2013.04.23 16483
Board Pagination Prev 1 ... 33 34 35 36 37 38 39 40 41 42 ... 98 Next
/ 98