I imported a DLL that I compiled with rato.hpp:
#ifndef RATO_H
#define RATO_H
extern "C"
{
__declspec(dllexport) void mouse_move(char button, char x, char y, char wheel);
}
#endif
and rato.cpp:
typedef struct {
char button;
char x;
char y;
char wheel;
char unk1;
} MOUSE_IO;
void mouse_move(char button, char x, char y, char wheel)
{
MOUSE_IO io;
io.unk1 = 0;
io.button = button;
io.x = x;
io.y = y;
io.wheel = wheel;
if (!callmouse(&io)) {
mouse_close();
mouse_open();
}
}
When importing it in my CSharp code, I can't cast negative values:
[DllImport("Rato.dll")]
public static extern void mouse_move(char button, char x, char y, char wheel);
mouse_move((char)0,(char)0,(char)-150,0);
I tried to convert, but it doesn't work, it keeps sending positive values instead of negative.
EDIT: Tried to convert to sbyte
but get error
System.OverflowException: 'Value was either too large or too small for a signed byte.'
[DllImport("Rato.dll")]
public static extern void mouse_move(sbyte button, sbyte x, sbyte y, sbyte wheel);
mouse_move(0,0,Convert.ToSByte(-150),0);
How can I sucessfully pass negative char value to C imported DLL?