Zitat von
Remko:
How to convert this part?
Code:
pwszTemp = (LPWSTR)((LPBYTE)pDispSpecOptions + dwPrefixOffset);
lstrcpyW(pwszTemp, pwszPrefix);
This is rather easy.
Delphi-Quellcode:
var
pwswTemp: PWideChar;
...
pwszTemp := PWideChar(PChar(pDispSpecOptions) + dwPrefixOffset);
lstrcpyW(pwszTemp, pwszPrefix);
It takes the pointer to the structure and moves it for dwPrefixOffset bytes. To increment it uses the + operator which is defined in C for any pointer type and integer. In Delphi the operator is only defined for PChar, but that is good enough to increment the pointer for the desired amount of bytes.
The resulting pointer is typecasted to PWideChar because obviously at this address a C
Unicode string resides.
The
Win32 funtion lstrcpyW now copies the C
Unicode string residing at pwszPrefix into pwszTemp.
To add some help for the many C string types:
LP = Long Pointer. Can be ignored. It is from a time when there were 16-bit and 32-bit pointers. It denotes 32-bit pointers.
C = const. Not fully the same as const in Delphi. Can usually be dropped.
W = Wide.
Unicode.
T =
ANSI or
Unicode depending on the preprocessor symbol
UNICODE. Since most
Win32 functinos come in
ANSI and
Unicode variant (suffix A and W) this allows to write a program which can be compiled in
ANSI or
Unicode without change of source.
STR = string.
LPCTSTR =
Unicode or
ANSI C string where the pointer cannot be changed because it is const. const PWideChar/PChar as parameter or PWideChar/PChar as parameter or variable.
LPWSTR =
Unicode C string where the pointer can be changed. PWideChar as parameter or variable.
LPSTR =
ANSI C string where the pointer can be changed. PChar as parameter or variable.