|
완존초보 님이 쓰신 글 :
: typedef struct <- type
: { <- AType = Record
: String a0; <- a0:String;
: Byte a1,a2; <- a1,a2:Byte;
: String a3; <- a3:String;
: } AType <- end;
C++에서는 typedef를 쓰지 마시고 이렇게 쓰세요.
struct AType {
String a0;
unsigned char a1, a2; // 파스칼의 Byte는 C에서는 unsigned char
String a3;
}; // ;을 꼭 쓰세요.
: typedef struct <- type
: { <- CType = Record
: String c0[10]; <- c0[10]:String;
: Word c1[50]; <- c1[50]:Word;
: Integer c2[10]; <- c2[10]:Integer;
: Double c3[20]; <- c3[20]:Double;
: } CType <- end;
마찬가지로,
struct CType {
String c0[10];
unsigned short c1[50]; // 파스칼의 Word는 C에서는 unsigned short
int c2[10]; // 파스칼의 Integer는 C에서는 int
double c3[20]; // C에서는 소문자 double
};
: Integer icnt; <- icnt:Integer;
int icnt;
: Cardinal cm; <- cm:Cardinal;
unsigned int cm;
: AType *A,*B; <- A,B:^AType;
: CType C; <- C:CType;
: ->(1) 아래의 (1)이 부분부터는 대충 바꿔봤는데 cm과 GlobalAlloc함수사이에서 다음과 같은
: 에러메시지가 나옵니다.
: cannot convert 'void*' to 'unsigned int'
GlobalAlloc()의 리턴 값이 void* 인데 unsigned int 변수인 cm에 대입하려 했기 때문입니다.
: ->(2)에서는 3가지로 에러가 나옵니다.
: cannot convert 'unsigned int to 'void*'
: type mismatch in parameter 'hMem'(wanted 'void*', got 'unsigned int')
이번에는 (1)과 반대로 GlobalLock(HGLOBAL hMem)에서 HGLOBAL는 void* 인데 unsigned int 변수인 cm을
사용하려 했기 때문에 에러.
: cannot convert 'void*' to 'AType'
역시 GlobalLock()의 리턴값인 void*를 AType으로 대입하려고 했기 때문입니다.
그런데, 왜 굳이 API 함수인 GlobalAlloc을 쓰시는지요?
그냥 new 연산자로 간단히 쓸 수 있을 텐데요.
예를 들어,
A = new AType[icnt];
:
: icntItem=0; <- icntItem:=0;
: icntItemNum=100; <- icntItemNum:=100;
: ->(1) cm=GlobalAlloc(GHND,icnt*sizeof(AType)); <- cm:=GlobalAlloc(GHND,icnt*sizeof(AType));
: ->(2) A=GlobalLock(cm); <- A:=GlobalLock(cm);
: B=A; <- B:=A;
while (! ... ) { <- while not ... do
begin
A->a0 = C.c0[0]; <- A^.a0:=C.c0[0];
A->a1 = C.c1[0]; <- A^.a1:=C.c1[0];
A->a2 = C.c2[1]; <- A^.a2:=C.c2[1];
A->a3 = C.c3[1]; <- A^.a3:=C.c3[1];
A++; <- Inc(A);
icntItem++; <- Inc(icntItem);
} <- end;
<- A:=B;
<- end;
|