1

When building my C++ application the build fails at this line of code

if (!PyTuple_GetByte(poArgs, 0, &SourceCell.window_type))

with this error

error C2664: 'PyTuple_GetByte' : cannot convert parameter 3 from 'char *' to 'unsigned char *'

This is the called function:

bool PyTuple_GetByte(PyObject* poArgs, int pos, unsigned char* ret);

The third parameter &SourceCell.window_type is type char.

Is there a way to convert/cast the parameter inside the function call like

if (!PyTuple_GetByte(poArgs, 0, reinterpret_cast<unsigned char*>(&SourceCell.window_type)))

or do I have to deal with it in another way?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Klappstuhl
  • 51
  • 2
  • 14

1 Answers1

1

From the error, the signature of the PyTuple_GetByte function was expecting a third parameter of type unsigned char*, but you passed a variable of type char* at its invocation. I think you have two options here.

  1. You can change the signature of function PyTuple_GetByte to expect a char* parameter.

  2. You need to convert your input variable from type char* to type unsigned char*, before you can pass it into PyTuple_GetByte.

The conversion is normally like this:

unsigned char* convert_var = reinterpret_cast<unsigned char*>(&SourceCell.window_type); // (c++ way)

or

unsigned char* convert_var = (unsigned char*)(&SourceCell.window_type); // (c way)
underscore_d
  • 6,309
  • 3
  • 38
  • 64
Meng Tian
  • 26
  • 3