Contents

Views 11506 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.

?

  1. 해커스랩 깨기.. 후후.. ㅋㅋ

    Date2013.04.23 CategorySystem/OS Byhooni Views18527
    Read More
  2. 플라스터(Plaster) 수업 내용

    Date2016.05.24 CategoryEtc Byhooni Views0
    Read More
  3. 프로그램 문서 관리 (Doxygen)

    Date2013.04.23 CategoryDevelop Byhooni Views16444
    Read More
  4. 프로그래밍에서 foo, bar 함수의 유래

    Date2013.06.25 CategoryDevelop Byhooni Views21486
    Read More
  5. 프로그래밍 소스 관련 사이트..

    Date2013.04.23 CategoryDevelop Byhooni Views16532
    Read More
  6. 페이팔에서 돈 찾기 (Paypal withdraw)

    Date2014.02.20 CategoryDevelop Byhooni Views11485
    Read More
  7. 티스토리 테이블 html,css 구문

    Date2013.11.03 CategoryEtc Byhooni Views16062
    Read More
  8. 콘솔에서 패스워드 걸린 zip 압축하는 명령

    Date2018.03.02 CategorySystem/OS Byhooni Views1140
    Read More
  9. 컴파일러 수업 자료(교재 : 컴파일러 입문)

    Date2003.04.23 CategorySystem/OS Byhooni Views22077
    Read More
  10. 캘리포니아 운전면허 족보

    Date2017.06.12 CategoryDevelop Byhooni Views896
    Read More
  11. 캘리포니아 운전면허 문제

    Date2017.07.22 CategoryEtc Byhooni Views1191
    Read More
  12. 최근 논문 자료 (2011/01/03, 만현형한테 보낸거..)

    Date2013.04.23 CategoryDevelop Byhooni Views10366
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 98 Next
/ 98