Contents

Views 11450 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. [c++] String Tokenizer (나중에 c 코드로 변경해서 사용할 것)

    Date2013.04.23 CategoryDevelop Byhooni Views11690
    Read More
  2. [network] tcp/ip 설명 html파일 9장(ppt 포함)

    Date2013.04.23 CategoryPPT Byhooni Views11650
    Read More
  3. php.ini 설정 안됐을때.. ㅋㅋ

    Date2013.04.23 CategorySystem/OS Byhooni Views11639
    Read More
  4. [java] 초간단 싱글톤(Singleton) 패턴 샘플 코드

    Date2013.11.18 CategoryDevelop Byhooni Views11593
    Read More
  5. [php] 쉘에서 실행할 때 인수(파라미터) 받기..

    Date2003.04.23 CategoryDevelop Byhooni Views11588
    Read More
  6. [c] 도스 공격(DoS Attack) 프로그램

    Date2013.04.23 CategoryDevelop Byhooni Views11575
    Read More
  7. [c] 시간 관련 함수 설명과 예제..

    Date2003.04.23 CategoryDevelop Byhooni Views11523
    Read More
  8. [c] home env stack overflow

    Date2003.04.23 CategoryDevelop Byhooni Views11515
    Read More
  9. [ios] Background 에서 네트워크 사용

    Date2013.07.22 CategoryDevelop Byhooni Views11509
    Read More
  10. [c] 테트리스(Tetris) 게임(도스용) 소스코드

    Date2003.04.23 CategoryDevelop Byhooni Views11465
    Read More
  11. [c++] mfc 이용한 기본적인 형변환 예제

    Date2013.04.23 CategoryDevelop Byhooni Views11450
    Read More
  12. [ios] UIButton multi-line iOS7

    Date2014.01.09 CategoryDevelop Byhooni Views11433
    Read More
Board Pagination Prev 1 ... 30 31 32 33 34 35 36 37 38 39 ... 98 Next
/ 98