1

I need to create a list of LPSTR and put this in aLPSTR attribute of a struct.

typedef struct _wfs_pin_caps
{
...
LPSTR               lpszExtra; //This attribute should receive
} WFSPINCAPS, * LPWFSPINCAPS;

I need something of this kind.

WFSPINCAPS PinCapabilities;

list<LPSTR> Keys;
Keys[0] = (LPSTR) "value=key";
Keys[1] = (LPSTR) "value1=key1";
Keys[2] = (LPSTR) "value2=key2";

PinCapabilities.lpszExtra = Keys;

I need to pass lists with VARIOUS values...

Matheus Cardozo
  • 135
  • 1
  • 7

2 Answers2

0

It's simple, just do this

struct _wfs_pin_caps {
    // ... other fields ...
    std::list<const LPSTR> lpszExtra;
};
list<const LPSTR> &extra(PinCapabilities.lpszExtra);
extra.push_back(TEXT("value1=key1"));
extra.push_back(TEXT("value2=key2"));
// ... more items ...
extra.push_back(TEXT("valueN=keyN"));

Read about The TEXT macro so you don't do that awkward cast at all, which is wrong BTW.

Note: You should probably need std::vector instead, read their documentation to decide.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
  • Hey guy, i need to pass lists with VARIOUS values – Matheus Cardozo Mar 09 '17 at 14:18
  • Presumably, the struct is not the OP's code to change. `TEXT` is also not for `LPSTR`, it's for `LPTSTR`. If the string were to change to a wide string, `TEXT` would start producing a compiler error. T-strings in general are rather dated nowadays in any case. `TEXT` also doesn't fix the cast, as `TEXT` is unrelated to const correctness. As for `const`, it won't work because `LPSTR` is a `char*`, making `const LPSTR` a `char* const`. The more common spelling is `LPCSTR`. – chris Mar 09 '17 at 14:18
  • @Iharob Al Asimi guy, i need use this struct: typedef struct _wfs_pin_caps { ... LPSTR lpszExtra; //This attribute should receive } WFSPINCAPS, * LPWFSPINCAPS; – Matheus Cardozo Mar 09 '17 at 14:26
  • You can't, create a list of structs then. – Iharob Al Asimi Mar 09 '17 at 14:27
0

This is a pure cen-xfs thing so having just C++ knowledge is not enough. All lpszExtra fields of XFS structures are special formatted C strings.

So the correct way to fill lpszExtra field of a xfs capabilities struct is to use double NULL terminated and NULL separated string. And as all of these fields are key value pairs so the format is: "key1=value1\0key2=value2\0...\0keyN=valueN\0\0" Note here "keyX" does NOT mean PINPAD key definition, but the way all XFS lpszExtra field data is formatted so first key_name =-sign key_value.

How you handle those strings are up to you, but I like to use normal newlines instead of '\0' as key-value pair separators and then just convert to/from that to the XFS specific NULL char separated and double NULL terminated format.

That way you can use normal C string methods for manipulation in your own code.

Easy conversion is allocate memory, make copy and swap '\n' to '\0' and '\0' to "\0\0" while copying from C string to XFS and reverse when converting from XFS to C string.

Note this is aplicable only for those lpszExtra fields in XFS structs.