C++ 函数指针类型不正确
C++ Function pointer incorrect types
我需要使用以下函数,但我遇到了参数问题:
在这种情况下,IP 地址未设置。
cwbCO_SysHandle system;
LPSTR ipAddress = "";
ULONG ipLength = 32;
cwbCO_GetIPAddress(system, ipAddress, &ipLength);
我知道我需要将一个指向 LPSTR 的指针作为参数传递,但设置以下代码也不起作用:
cwbCO_SysHandle system;
LPSTR ipAddress = "";
ULONG ipLength = 32;
cwbCO_GetIPAddress(system, &ipAddress, &ipLength); //Incompatible types LPSTR* and LPSTR
正确的方法是什么?
语法
UINT CWB_ENTRY cwbCO_GetIPAddress(cwbCO_SysHandle系统, LPSTR IP地址, PULONG长度);
参数
cwbCO_SysHandle系统-输入
Handle that previously was returned by cwbCO_CreateSystem or cwbCO_CreateSystemLike. It is the
IBM i identification.
LPSTR IP 地址 - 输出
Pointer to a buffer that will contain the NULL-terminated IP address in dotted-decimal notation (in
the form "nnn.nnn.nnn.nnn" where each "nnn" is in the range of from 0 to 255).
PULONG 长度 - input/output
Pointer to the length of the IPAddress buffer. If the buffer is too small to hold the output, including
room for the terminating NULL, the size of the buffer
我找到了文档,cwbCO_GetIPAddress
这里的相关部分是(强调):
LPSTR IPAddress - output
Pointer to a buffer that will contain the NULL-terminated IP address in dotted-decimal notation (in the form "nnn.nnn.nnn.nnn" where each "nnn" is in the range of from 0 to 255).
因此您的代码应该更像这样:
cwbCO_SysHandle system;
char ipAddress[32]; //A buffer, not a pointer!
ULONG ipLength = 32;
cwbCO_GetIPAddress(system, ipAddress, &ipLength);
此外,请确保使用 cwbCO_CreateSystem
或 cwbCO_CreateSystemLike
初始化 system
。
我需要使用以下函数,但我遇到了参数问题:
在这种情况下,IP 地址未设置。
cwbCO_SysHandle system;
LPSTR ipAddress = "";
ULONG ipLength = 32;
cwbCO_GetIPAddress(system, ipAddress, &ipLength);
我知道我需要将一个指向 LPSTR 的指针作为参数传递,但设置以下代码也不起作用:
cwbCO_SysHandle system;
LPSTR ipAddress = "";
ULONG ipLength = 32;
cwbCO_GetIPAddress(system, &ipAddress, &ipLength); //Incompatible types LPSTR* and LPSTR
正确的方法是什么?
语法
UINT CWB_ENTRY cwbCO_GetIPAddress(cwbCO_SysHandle系统, LPSTR IP地址, PULONG长度);
参数
cwbCO_SysHandle系统-输入
Handle that previously was returned by cwbCO_CreateSystem or cwbCO_CreateSystemLike. It is the
IBM i identification.
LPSTR IP 地址 - 输出
Pointer to a buffer that will contain the NULL-terminated IP address in dotted-decimal notation (in
the form "nnn.nnn.nnn.nnn" where each "nnn" is in the range of from 0 to 255).
PULONG 长度 - input/output
Pointer to the length of the IPAddress buffer. If the buffer is too small to hold the output, including
room for the terminating NULL, the size of the buffer
我找到了文档,cwbCO_GetIPAddress
这里的相关部分是(强调):
LPSTR IPAddress - output Pointer to a buffer that will contain the NULL-terminated IP address in dotted-decimal notation (in the form "nnn.nnn.nnn.nnn" where each "nnn" is in the range of from 0 to 255).
因此您的代码应该更像这样:
cwbCO_SysHandle system;
char ipAddress[32]; //A buffer, not a pointer!
ULONG ipLength = 32;
cwbCO_GetIPAddress(system, ipAddress, &ipLength);
此外,请确保使用 cwbCO_CreateSystem
或 cwbCO_CreateSystemLike
初始化 system
。