c++pointerstypesargumentslpstr

C++ Function pointer incorrect types


I need to use the following function but I'm in trouble with the args:

In this case the IP Address is not setting.

cwbCO_SysHandle system;
LPSTR ipAddress = "";
ULONG ipLength = 32;
cwbCO_GetIPAddress(system, ipAddress, &ipLength);

I know I need to pass a pointer to the LPSTR as an argument but setting the following code didn't work either:

cwbCO_SysHandle system;
LPSTR ipAddress = "";
ULONG ipLength = 32;
cwbCO_GetIPAddress(system, &ipAddress, &ipLength); //Incompatible types LPSTR* and LPSTR

What's the correct way?

Syntax

UINT CWB_ENTRY cwbCO_GetIPAddress(cwbCO_SysHandle system, LPSTR IPAddress, PULONG length );

Parameters

cwbCO_SysHandle system - input

Handle that previously was returned by cwbCO_CreateSystem or cwbCO_CreateSystemLike. It is the
IBM i identification.

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).

PULONG length - 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

Solution

  • I found documentation, cwbCO_GetIPAddress

    The relevant part here is (emphasis added):

    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).

    So your code should look more like this:

    cwbCO_SysHandle system;
    char ipAddress[32]; //A buffer, not a pointer!
    ULONG ipLength = 32;
    cwbCO_GetIPAddress(system, ipAddress, &ipLength);
    

    Also, make sure you do initialize your system with cwbCO_CreateSystem or cwbCO_CreateSystemLike.