我正在尝试移植一个内部有一个联合的 C 结构。中的默认结构Winapi.Winsock2.pas
缺少记录中的某些字段。但这是正确的方法吗?谢谢。
typedef struct _WSACOMPLETION {
WSACOMPLETIONTYPE Type;
union {
struct {
HWND hWnd;
UINT uMsg;
WPARAM context;
} WindowMessage;
struct {
LPWSAOVERLAPPED lpOverlapped;
} Event;
struct {
LPWSAOVERLAPPED lpOverlapped;
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpfnCompletionProc;
} Apc;
struct {
LPWSAOVERLAPPED lpOverlapped;
HANDLE hPort;
ULONG_PTR Key;
} Port;
} Parameters;
} WSACOMPLETION;
_WSACOMPLETION = record
&Type: WSACOMPLETIONTYPE;
case Parameters: Integer of
0: (hWnd: HWND; uMsg: UINT; context: WPARAM); // WindowMessage
1: (lpOverlapped: LPWSAOVERLAPPED); // Event
2: (lpOverlapped: LPWSAOVERLAPPED; lpfnCompletionProc: LPWSAOVERLAPPED_COMPLETION_ROUTINE); // Apc
3: (lpOverlapped: LPWSAOVERLAPPED; hPort: HANDLE; Key: ULONG_PTR); //Port
end;
编译器抱怨Error: E2004 Identifier redeclared: 'lpOverlapped'
更新 2:
经过一番思考,我想出了这个。
_WSACOMPLETION = record
&Type: WSACOMPLETIONTYPE;
case Parameters: Integer of
0: (WindowMessage: record
hWnd: HWND;
uMsg: UINT;
context: WPARAM;
end);
1: (Event: record
lpOverlapped: LPWSAOVERLAPPED;
end);
2: (Apc: record
lpOverlapped: LPWSAOVERLAPPED;
lpfnCompletionProc: LPWSAOVERLAPPED_COMPLETION_ROUTINE
end);
3: (Port: record
lpOverlapped: LPWSAOVERLAPPED;
hPort: HANDLE;
Key: ULONG_PTR;
end)
end;