dcsimg
Results 1 to 8 of 8

Thread: [RESOLVED] VB6 const Uint8 *state ina a DLL call ?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2020
    Location
    Brazil
    Posts
    11

    Resolved [RESOLVED] VB6 const Uint8 *state ina a DLL call ?

    Hi Guys,

    I have this function on SDL2 lib:

    Code:
    const Uint8* SDL_GetKeyboardState(int* numkeys);
    The Function is working (FuncPtr... stdcall), but in VB6 how we represent this ?

    Code:
    const Uint8 *state = SDL_GetKeyboardState(NULL);
    if (state[SDL_SCANCODE_RETURN]) {
        printf("<RETURN> is pressed.\n");
    }
    if (state[SDL_SCANCODE_RIGHT] && state[SDL_SCANCODE_UP]) {
        printf("Right and Up Keys Pressed.\n");
    }
    SDL_SCANCODE_RETURN on SDL_scancode.h is 40

    on IDE debug.print the state as long, we return -30074

    Code:
    Dim state as Long
    
    state = SDL2.GetKeyboardState(0)
                
    Debug.Print "state: " & state ' -30074

    I have a Enum for this like the header in c.

    Code:
    Public Enum SDL_Scancode
        SDL_SCANCODE_A = 4
        SDL_SCANCODE_B = 5
        SDL_SCANCODE_C = 6
        SDL_SCANCODE_D = 7
        SDL_SCANCODE_E = 8
        ...
        SDL_SCANCODE_RETURN = 40
        SDL_SCANCODE_ESCAPE = 41
        SDL_SCANCODE_BACKSPACE = 42
        SDL_SCANCODE_TAB = 43
        SDL_SCANCODE_SPACE = 44
       ...
        SDL_NUM_SCANCODES = 512
    End Enum
    How i can do this if ( if (state[SDL_SCANCODE_RETURN]) ) in VB6 ?

    Thanks in advance,

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,826

    Re: VB6 const Uint8 *state ina a DLL call ?

    Uint8 is a byte.
    Have tried to use a byte instead of a long?

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2020
    Location
    Brazil
    Posts
    11

    Re: VB6 const Uint8 *state ina a DLL call ?

    Quote Originally Posted by Arnoutdv View Post
    Uint8 is a byte.
    Have tried to use a byte instead of a long?
    Thanks for response!

    Now state (is vb6 byte now), but always return 134.

    Code:
                state = SDL2.GetKeyboardState2(0)
                Debug.Print "state: " & state
    And 134 on scancode is SDL_SCANCODE_KP_EQUALSAS400 = 134

    How i do this in VB6 ?

    Code:
    if (state[SDL_SCANCODE_RETURN]) {
        printf("<RETURN> is pressed.\n");
    }
    Example ?

    Code:
    debug.print state[SDL_SCANCODE_RETURN]
    Thaks for the help
    Last edited by xmaxmex; May 21st, 2020 at 08:25 AM.

  4. #4
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,891

    Re: VB6 const Uint8 *state ina a DLL call ?

    The function does return a pointer, to a sequence of "KeyState-Bytes" (a C-Style-ByteArray).

    It's declaration (IMO) be more like the one below:
    Code:
    Option Explicit
    
    Private Declare Function SDL_GetKeyboardState Lib "sdl2" (ByVal pNumKeys As Long) As Long
    
    Public Enum SDL_Scancode
        SDL_SCANCODE_A = 4
        SDL_SCANCODE_B = 5
        SDL_SCANCODE_C = 6
        SDL_SCANCODE_D = 7
        SDL_SCANCODE_E = 8
        ' ...
        SDL_SCANCODE_RETURN = 40
        SDL_SCANCODE_ESCAPE = 41
        SDL_SCANCODE_BACKSPACE = 42
        SDL_SCANCODE_TAB = 43
        SDL_SCANCODE_SPACE = 44
        '...
        SDL_NUM_SCANCODES = 512
    End Enum
    
    Private mKeyStates(0 To SDL_NUM_SCANCODES - 1) As Byte
    
    Public Sub RefreshKeyStates()
      Dim NumKeys As Long, pKeyStateBytes As Long
          NumKeys = SDL_NUM_SCANCODES
          pKeyStateBytes = SDL_GetKeyboardState(VarPtr(NumKeys))
    
      If pKeyStateBytes = 0 Or NumKeys > SDL_NUM_SCANCODES Then Err.Raise vbObjectError, , "unsuccesful call to SDL_GetKeyboardState"
    
      CopyMemory mKeyStates(0), ByVal pKeyStateBytes, NumKeys 
    End Sub
    
    Public Property Get IsDown(ByVal ScanCode As SDL_Scancode) As Boolean
      IsDown = mKeyStates(ScanCode)
    End Property
    For your Class-wrapper, I'd hide the Call as shown in "Sub RefreshKeyStates()" above
    (leaving "nothing to chance" for the users of your Class, regarding "the amount of NumKeys", it's always the state of all Keys which is captured)

    And the companion-property "IsDown" will then ensure, that proper Bool-conversion is done beforehand,
    so the users of your Class can combine several IsDown-queries in an If-expression in an unambigous manner (supporting Not and Or).

    Olaf
    Last edited by Schmidt; May 21st, 2020 at 10:54 AM.

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2020
    Location
    Brazil
    Posts
    11

    Re: VB6 const Uint8 *state ina a DLL call ?

    Quote Originally Posted by Schmidt View Post
    The function does return a pointer, to a sequence of "KeyState-Bytes" (a C-Style-ByteArray).

    It's declaration (IMO) be more like the one below:
    Code:
    Option Explicit
    
    Private Declare Function SDL_GetKeyboardState Lib "sdl2" (ByVal pNumKeys As Long) As Long
    
    Public Enum SDL_Scancode
        SDL_SCANCODE_A = 4
        SDL_SCANCODE_B = 5
        SDL_SCANCODE_C = 6
        SDL_SCANCODE_D = 7
        SDL_SCANCODE_E = 8
        ' ...
        SDL_SCANCODE_RETURN = 40
        SDL_SCANCODE_ESCAPE = 41
        SDL_SCANCODE_BACKSPACE = 42
        SDL_SCANCODE_TAB = 43
        SDL_SCANCODE_SPACE = 44
        '...
        SDL_NUM_SCANCODES = 512
    End Enum
    
    Private mKeyStates(0 To SDL_NUM_SCANCODES - 1) As Byte
    
    Public Sub RefreshKeyStates()
      Dim NumKeys As Long, pKeyStateBytes As Long
          NumKeys = SDL_NUM_SCANCODES
          pKeyStateBytes = SDL_GetKeyboardState(VarPtr(NumKeys))
    
      If pKeyStateBytes = 0 Or NumKeys > SDL_NUM_SCANCODES Then Err.Raise vbObjectError, , "unsuccesful call to SDL_GetKeyboardState"
    
      CopyMemory mKeyStates(0), ByVal pKeyStateBytes, NumKeys 
    End Sub
    
    Public Property Get IsDown(ByVal ScanCode As SDL_Scancode) As Boolean
      IsDown = mKeyStates(ScanCode)
    End Property
    For your Class-wrapper, I'd hide the Call as shown in "Sub RefreshKeyStates()" above
    (leaving "nothing to chance" for the users of your Class, regarding "the amount of NumKeys", it's always the state of all Keys which is captured)

    And the companion-property "IsDown" will then ensure, that proper Bool-conversion is done beforehand,
    so the users of your Class can combine several IsDown-queries in an If-expression in an unambigous manner (supporting Not and Or).

    Olaf

    Olaf, Thanks for the reply and Your time,

    But, allways Crash here on copymemory

    Code:
    CopyMemory mKeyStates(0), ByVal pKeyStateBytes, NumKeys

    This is the entire project, see the Drive link:
    https://drive.google.com/open?id=1d2...uvrlYkQYR-7NVl

    And thanks in advance.
    Last edited by xmaxmex; May 21st, 2020 at 12:33 PM.

  6. #6
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,891

    Re: VB6 const Uint8 *state ina a DLL call ?

    Quote Originally Posted by xmaxmex View Post
    This is the entire project, ...
    Couldn't get this to work (due to a missing GCC-Dll-dependency)...

    But have seen, that the cSDL2-Class was based on the little ChessBoard-Demo I've posted a few years ago (using the RC5-cdecl-caller)...

    And I've had no problem, to do exactly the implementation as proposed:
    (placing the new KeyBoardState-Wrapper-Functions at the end of the cSDL2-Class in that older ChessBoard-Demo)
    Code:
    Option Explicit
    
    Public Enum SDL_EventType
      SDL_FIRSTEVENT = 0
      SDL_QUIT_ = &H100
      SDL_APP_TERMINATING
      SDL_APP_LOWMEMORY
      SDL_APP_WILLENTERBACKGROUND
      SDL_APP_DIDENTERBACKGROUND
      SDL_APP_WILLENTERFOREGROUND
      SDL_APP_DIDENTERFOREGROUND
      SDL_WindowEvent = &H200
      SDL_SysWMEvent
      SDL_KEYDOWN = &H300
      SDL_KEYUP
      SDL_TEXTEDITING
      SDL_TEXTINPUT
      SDL_MOUSEMOTION = &H400
      SDL_MOUSEBUTTONDOWN
      SDL_MOUSEBUTTONUP
      SDL_MOUSEWHEEL
      SDL_JOYAXISMOTION = &H600
      SDL_JOYBALLMOTION
      SDL_JOYHATMOTION
      SDL_JOYBUTTONDOWN
      SDL_JOYBUTTONUP
      SDL_JOYDEVICEADDED
      SDL_JOYDEVICEREMOVED
      SDL_CONTROLLERAXISMOTION = &H650
      SDL_CONTROLLERBUTTONDOWN
      SDL_CONTROLLERBUTTONUP
      SDL_CONTROLLERDEVICEADDED
      SDL_CONTROLLERDEVICEREMOVED
      SDL_CONTROLLERDEVICEREMAPPED
      SDL_FINGERDOWN = &H700
      SDL_FINGERUP
      SDL_FINGERMOTION
      SDL_DOLLARGESTURE = &H800
      SDL_DOLLARRECORD
      SDL_MULTIGESTURE
      SDL_CLIPBOARDUPDATE = &H900
      SDL_DROPFILE = &H1000
      SDL_UserEvent = &H8000&
      SDL_LASTEVENT = &HFFFF&
    End Enum
    
    Public Enum SDL_LOG_CATEGORY
      SDL_LOG_CATEGORY_APPLICATION
      SDL_LOG_CATEGORY_ERROR
      SDL_LOG_CATEGORY_ASSERT
      SDL_LOG_CATEGORY_SYSTEM
      SDL_LOG_CATEGORY_AUDIO
      SDL_LOG_CATEGORY_VIDEO
      SDL_LOG_CATEGORY_RENDER
      SDL_LOG_CATEGORY_INPUT
      SDL_LOG_CATEGORY_TEST
    End Enum
    
    Public Enum SDL_LogPriority
      SDL_LOG_PRIORITY_VERBOSE = 1
      SDL_LOG_PRIORITY_DEBUG
      SDL_LOG_PRIORITY_INFO
      SDL_LOG_PRIORITY_WARN
      SDL_LOG_PRIORITY_ERROR
      SDL_LOG_PRIORITY_CRITICAL
    End Enum
    
    Public Enum SDL_INIT_FLAGS
      SDL_INIT_TIMER = &H1
      SDL_INIT_AUDIO = &H10
      SDL_INIT_VIDEO = &H20
      SDL_INIT_JOYSTICK = &H200
      SDL_INIT_HAPTIC = &H1000
      SDL_INIT_GAMECONTROLLER = &H2000
      SDL_INIT_EVENTS = &H4000
      SDL_INIT_NOPARACHUTE = &H100000
    End Enum
    
    Public Enum SDL_WindowFlags
      SDL_WINDOW_FULLSCREEN = &H1
      SDL_WINDOW_OPENGL = &H2
      SDL_WINDOW_SHOWN = &H4
      SDL_WINDOW_HIDDEN = &H8
      SDL_WINDOW_BORDERLESS = &H10
      SDL_WINDOW_RESIZABLE = &H20
      SDL_WINDOW_MINIMIZED = &H40
      SDL_WINDOW_MAXIMIZED = &H80
      SDL_WINDOW_INPUT_GRABBED = &H100
      SDL_WINDOW_INPUT_FOCUS = &H200
      SDL_WINDOW_MOUSE_FOCUS = &H400
      SDL_WINDOW_FULLSCREEN_DESKTOP = (SDL_WINDOW_FULLSCREEN Or &H1000)
      SDL_WINDOW_FOREIGN = &H800
      SDL_WINDOW_ALLOW_HIGHDPI = &H2000
    End Enum
     
    Public Enum SDL_RendererFlags
      SDL_RENDERER_SOFTWARE = &H1
      SDL_RENDERER_ACCELERATED = &H2
      SDL_RENDERER_PRESENTVSYNC = &H4
      SDL_RENDERER_TARGETTEXTURE = &H8
    End Enum
    
    Public Enum SDL_WINDOWPOS
      SDL_WINDOWPOS_UNDEFINED = &H1FFF0000
      SDL_WINDOWPOS_CENTERED = &H2FFF0000
    End Enum
    '****** end of Public EnumDefs (which will show up on the Class-Interface) *****
    
    'the rest is Private-stuff for Class-internal usage...
    
    'these two are used to convert Zero-terminated 8Bit-CharSequences into VBStrings
    Private Declare Function lstrlenA& Lib "kernel32" (ByVal lpszSrc&)
    Private Declare Function lstrcpyA& Lib "kernel32" (ByVal lpszDest$, ByVal lpszSrc&)
    
    'the SDL-Event-struct is a Union - but most "Sub-Structs" have at least the first 3 Members in common
    Private Type SDL_EVENT
      eType As SDL_EventType
      eTimeStamp As Long
      eID As Long
      eBytes(0 To 63) As Byte
    End Type
    Private mEvt As SDL_EVENT 'this Class-Variable is the one used for Polling
    
    'the below ENum is used as a "speaking Index" in conjunction with the Function-Table (vTbl) directly below
    Private Enum SDL_Methods
      SDL_LogSetPriority
      SDL_Init
      SDL_GetError
      SDL_CreateWindow
      SDL_GetWindowSurface
      SDL_CreateSoftwareRenderer
      SDL_CreateRenderer
      SDL_SetRenderDrawColor
      SDL_RenderClear
      SDL_RenderGetViewport
      SDL_RenderFillRect
      SDL_RenderPresent
      SDL_UpdateWindowSurface
      SDL_PollEvent
      SDL_FreeSurface
      SDL_DestroyRenderer
      SDL_DestroyWindow
      SDL_Quit
      SDL_GetKeyboardState
      '... put additional methods here
      
      SDL_MethodsCount
    End Enum
    
    Public Enum SDL_Scancode
        SDL_SCANCODE_A = 4
        SDL_SCANCODE_B = 5
        SDL_SCANCODE_C = 6
        SDL_SCANCODE_D = 7
        SDL_SCANCODE_E = 8
        SDL_SCANCODE_F = 9
        SDL_SCANCODE_G = 10
        SDL_SCANCODE_H = 11
        SDL_SCANCODE_I = 12
        SDL_SCANCODE_J = 13
        SDL_SCANCODE_K = 14
        SDL_SCANCODE_L = 15
        SDL_SCANCODE_M = 16
        SDL_SCANCODE_N = 17
        SDL_SCANCODE_O = 18
        SDL_SCANCODE_P = 19
        SDL_SCANCODE_Q = 20
        SDL_SCANCODE_R = 21
        SDL_SCANCODE_S = 22
        SDL_SCANCODE_T = 23
        SDL_SCANCODE_U = 24
        SDL_SCANCODE_V = 25
        SDL_SCANCODE_W = 26
        SDL_SCANCODE_X = 27
        SDL_SCANCODE_Y = 28
        SDL_SCANCODE_Z = 29
    
        SDL_SCANCODE_1 = 30
        SDL_SCANCODE_2 = 31
        SDL_SCANCODE_3 = 32
        SDL_SCANCODE_4 = 33
        SDL_SCANCODE_5 = 34
        SDL_SCANCODE_6 = 35
        SDL_SCANCODE_7 = 36
        SDL_SCANCODE_8 = 37
        SDL_SCANCODE_9 = 38
        SDL_SCANCODE_0 = 39
    
        SDL_SCANCODE_RETURN = 40
        SDL_SCANCODE_ESCAPE = 41
        SDL_SCANCODE_BACKSPACE = 42
        SDL_SCANCODE_TAB = 43
        SDL_SCANCODE_SPACE = 44
    
        SDL_SCANCODE_MINUS = 45
        SDL_SCANCODE_EQUALS = 46
        SDL_SCANCODE_LEFTBRACKET = 47
        SDL_SCANCODE_RIGHTBRACKET = 48
        SDL_SCANCODE_BACKSLASH = 49
        SDL_SCANCODE_NONUSHASH = 50
        SDL_SCANCODE_SEMICOLON = 51
        SDL_SCANCODE_APOSTROPHE = 52
        SDL_SCANCODE_GRAVE = 53
        
        SDL_SCANCODE_COMMA = 54
        SDL_SCANCODE_PERIOD = 55
        SDL_SCANCODE_SLASH = 56
    
        SDL_SCANCODE_CAPSLOCK = 57
    
        SDL_SCANCODE_F1 = 58
        SDL_SCANCODE_F2 = 59
        SDL_SCANCODE_F3 = 60
        SDL_SCANCODE_F4 = 61
        SDL_SCANCODE_F5 = 62
        SDL_SCANCODE_F6 = 63
        SDL_SCANCODE_F7 = 64
        SDL_SCANCODE_F8 = 65
        SDL_SCANCODE_F9 = 66
        SDL_SCANCODE_F10 = 67
        SDL_SCANCODE_F11 = 68
        SDL_SCANCODE_F12 = 69
    
        SDL_SCANCODE_PRINTSCREEN = 70
        SDL_SCANCODE_SCROLLLOCK = 71
        SDL_SCANCODE_PAUSE = 72
        SDL_SCANCODE_INSERT = 73
                                
        SDL_SCANCODE_HOME = 74
        SDL_SCANCODE_PAGEUP = 75
        SDL_SCANCODE_DELETE = 76
        SDL_SCANCODE_END = 77
        SDL_SCANCODE_PAGEDOWN = 78
        SDL_SCANCODE_RIGHT = 79
        SDL_SCANCODE_LEFT = 80
        SDL_SCANCODE_DOWN = 81
        SDL_SCANCODE_UP = 82
        
        SDL_SCANCODE_NUMLOCKCLEAR = 83
                                      
        SDL_SCANCODE_KP_DIVIDE = 84
        SDL_SCANCODE_KP_MULTIPLY = 85
        SDL_SCANCODE_KP_MINUS = 86
        SDL_SCANCODE_KP_PLUS = 87
        SDL_SCANCODE_KP_ENTER = 88
        SDL_SCANCODE_KP_1 = 89
        SDL_SCANCODE_KP_2 = 90
        SDL_SCANCODE_KP_3 = 91
        SDL_SCANCODE_KP_4 = 92
        SDL_SCANCODE_KP_5 = 93
        SDL_SCANCODE_KP_6 = 94
        SDL_SCANCODE_KP_7 = 95
        SDL_SCANCODE_KP_8 = 96
        SDL_SCANCODE_KP_9 = 97
        SDL_SCANCODE_KP_0 = 98
        SDL_SCANCODE_KP_PERIOD = 99
    
        SDL_SCANCODE_NONUSBACKSLASH = 100
        SDL_SCANCODE_APPLICATION = 101
        SDL_SCANCODE_POWER = 102
        
        SDL_SCANCODE_KP_EQUALS = 103
        SDL_SCANCODE_F13 = 104
        SDL_SCANCODE_F14 = 105
        SDL_SCANCODE_F15 = 106
        SDL_SCANCODE_F16 = 107
        SDL_SCANCODE_F17 = 108
        SDL_SCANCODE_F18 = 109
        SDL_SCANCODE_F19 = 110
        SDL_SCANCODE_F20 = 111
        SDL_SCANCODE_F21 = 112
        SDL_SCANCODE_F22 = 113
        SDL_SCANCODE_F23 = 114
        SDL_SCANCODE_F24 = 115
        SDL_SCANCODE_EXECUTE = 116
        SDL_SCANCODE_HELP = 117
        SDL_SCANCODE_MENU = 118
        SDL_SCANCODE_SELECT = 119
        SDL_SCANCODE_STOP = 120
        SDL_SCANCODE_AGAIN = 121
        SDL_SCANCODE_UNDO = 122
        SDL_SCANCODE_CUT = 123
        SDL_SCANCODE_COPY = 124
        SDL_SCANCODE_PASTE = 125
        SDL_SCANCODE_FIND = 126
        SDL_SCANCODE_MUTE = 127
        SDL_SCANCODE_VOLUMEUP = 128
        SDL_SCANCODE_VOLUMEDOWN = 129
        SDL_SCANCODE_KP_COMMA = 133
        SDL_SCANCODE_KP_EQUALSAS400 = 134
    
        SDL_SCANCODE_INTERNATIONAL1 = 135
                                         
        SDL_SCANCODE_INTERNATIONAL2 = 136
        SDL_SCANCODE_INTERNATIONAL3 = 137
        SDL_SCANCODE_INTERNATIONAL4 = 138
        SDL_SCANCODE_INTERNATIONAL5 = 139
        SDL_SCANCODE_INTERNATIONAL6 = 140
        SDL_SCANCODE_INTERNATIONAL7 = 141
        SDL_SCANCODE_INTERNATIONAL8 = 142
        SDL_SCANCODE_INTERNATIONAL9 = 143
        SDL_SCANCODE_LANG1 = 144
        SDL_SCANCODE_LANG2 = 145
        SDL_SCANCODE_LANG3 = 146
        SDL_SCANCODE_LANG4 = 147
        SDL_SCANCODE_LANG5 = 148
        SDL_SCANCODE_LANG6 = 149
        SDL_SCANCODE_LANG7 = 150
        SDL_SCANCODE_LANG8 = 151
        SDL_SCANCODE_LANG9 = 152
    
        SDL_SCANCODE_ALTERASE = 153
        SDL_SCANCODE_SYSREQ = 154
        SDL_SCANCODE_CANCEL = 155
        SDL_SCANCODE_CLEAR = 156
        SDL_SCANCODE_PRIOR = 157
        SDL_SCANCODE_RETURN2 = 158
        SDL_SCANCODE_SEPARATOR = 159
        SDL_SCANCODE_OUT = 160
        SDL_SCANCODE_OPER = 161
        SDL_SCANCODE_CLEARAGAIN = 162
        SDL_SCANCODE_CRSEL = 163
        SDL_SCANCODE_EXSEL = 164
    
        SDL_SCANCODE_KP_00 = 176
        SDL_SCANCODE_KP_000 = 177
        SDL_SCANCODE_THOUSANDSSEPARATOR = 178
        SDL_SCANCODE_DECIMALSEPARATOR = 179
        SDL_SCANCODE_CURRENCYUNIT = 180
        SDL_SCANCODE_CURRENCYSUBUNIT = 181
        SDL_SCANCODE_KP_LEFTPAREN = 182
        SDL_SCANCODE_KP_RIGHTPAREN = 183
        SDL_SCANCODE_KP_LEFTBRACE = 184
        SDL_SCANCODE_KP_RIGHTBRACE = 185
        SDL_SCANCODE_KP_TAB = 186
        SDL_SCANCODE_KP_BACKSPACE = 187
        SDL_SCANCODE_KP_A = 188
        SDL_SCANCODE_KP_B = 189
        SDL_SCANCODE_KP_C = 190
        SDL_SCANCODE_KP_D = 191
        SDL_SCANCODE_KP_E = 192
        SDL_SCANCODE_KP_F = 193
        SDL_SCANCODE_KP_XOR = 194
        SDL_SCANCODE_KP_POWER = 195
        SDL_SCANCODE_KP_PERCENT = 196
        SDL_SCANCODE_KP_LESS = 197
        SDL_SCANCODE_KP_GREATER = 198
        SDL_SCANCODE_KP_AMPERSAND = 199
        SDL_SCANCODE_KP_DBLAMPERSAND = 200
        SDL_SCANCODE_KP_VERTICALBAR = 201
        SDL_SCANCODE_KP_DBLVERTICALBAR = 202
        SDL_SCANCODE_KP_COLON = 203
        SDL_SCANCODE_KP_HASH = 204
        SDL_SCANCODE_KP_SPACE = 205
        SDL_SCANCODE_KP_AT = 206
        SDL_SCANCODE_KP_EXCLAM = 207
        SDL_SCANCODE_KP_MEMSTORE = 208
        SDL_SCANCODE_KP_MEMRECALL = 209
        SDL_SCANCODE_KP_MEMCLEAR = 210
        SDL_SCANCODE_KP_MEMADD = 211
        SDL_SCANCODE_KP_MEMSUBTRACT = 212
        SDL_SCANCODE_KP_MEMMULTIPLY = 213
        SDL_SCANCODE_KP_MEMDIVIDE = 214
        SDL_SCANCODE_KP_PLUSMINUS = 215
        SDL_SCANCODE_KP_CLEAR = 216
        SDL_SCANCODE_KP_CLEARENTRY = 217
        SDL_SCANCODE_KP_BINARY = 218
        SDL_SCANCODE_KP_OCTAL = 219
        SDL_SCANCODE_KP_DECIMAL = 220
        SDL_SCANCODE_KP_HEXADECIMAL = 221
    
        SDL_SCANCODE_LCTRL = 224
        
        SDL_SCANCODE_LSHIFT = 225
        SDL_SCANCODE_LALT = 226
        SDL_SCANCODE_LGUI = 227
        SDL_SCANCODE_RCTRL = 228
        SDL_SCANCODE_RSHIFT = 229
        SDL_SCANCODE_RALT = 230
        SDL_SCANCODE_RGUI = 231
    
        SDL_SCANCODE_MODE = 257
                               
        SDL_SCANCODE_AUDIONEXT = 258
        SDL_SCANCODE_AUDIOPREV = 259
        SDL_SCANCODE_AUDIOSTOP = 260
        SDL_SCANCODE_AUDIOPLAY = 261
        SDL_SCANCODE_AUDIOMUTE = 262
        SDL_SCANCODE_MEDIASELECT = 263
        SDL_SCANCODE_WWW = 264
        SDL_SCANCODE_MAIL = 265
        SDL_SCANCODE_CALCULATOR = 266
        SDL_SCANCODE_COMPUTER = 267
        SDL_SCANCODE_AC_SEARCH = 268
        SDL_SCANCODE_AC_HOME = 269
        SDL_SCANCODE_AC_BACK = 270
        SDL_SCANCODE_AC_FORWARD = 271
        SDL_SCANCODE_AC_STOP = 272
        SDL_SCANCODE_AC_REFRESH = 273
        SDL_SCANCODE_AC_BOOKMARKS = 274
        
        SDL_SCANCODE_BRIGHTNESSDOWN = 275
        SDL_SCANCODE_BRIGHTNESSUP = 276
        SDL_SCANCODE_DISPLAYSWITCH = 277
                                        
        SDL_SCANCODE_KBDILLUMTOGGLE = 278
        SDL_SCANCODE_KBDILLUMDOWN = 279
        SDL_SCANCODE_KBDILLUMUP = 280
        SDL_SCANCODE_EJECT = 281
        SDL_SCANCODE_SLEEP = 282
    
        SDL_SCANCODE_APP1 = 283
        SDL_SCANCODE_APP2 = 284
    
        SDL_SCANCODE_AUDIOREWIND = 285
        SDL_SCANCODE_AUDIOFASTFORWARD = 286
    
        SDL_NUM_SCANCODES = 512
    End Enum
    
    Private mKeyStates(0 To SDL_NUM_SCANCODES - 1) As Byte
    
    Private vTbl(0 To SDL_MethodsCount - 1) As Long 'and here's our Private vTbl-Array for the Func-Pointers
    
    Private Sub Class_Initialize()
    Dim DllPath$: DllPath = App.Path & "\SDL2.dll"
        vTbl(SDL_LogSetPriority) = New_c.GetFuncPtr(DllPath, "SDL_LogSetPriority", True)
        vTbl(SDL_Init) = New_c.GetFuncPtr(DllPath, "SDL_Init", True)
        vTbl(SDL_GetError) = New_c.GetFuncPtr(DllPath, "SDL_GetError", True)
        vTbl(SDL_CreateWindow) = New_c.GetFuncPtr(DllPath, "SDL_CreateWindow", True)
        vTbl(SDL_GetWindowSurface) = New_c.GetFuncPtr(DllPath, "SDL_GetWindowSurface", True)
        vTbl(SDL_CreateSoftwareRenderer) = New_c.GetFuncPtr(DllPath, "SDL_CreateSoftwareRenderer", True)
        vTbl(SDL_CreateRenderer) = New_c.GetFuncPtr(DllPath, "SDL_CreateRenderer", True)
        vTbl(SDL_SetRenderDrawColor) = New_c.GetFuncPtr(DllPath, "SDL_SetRenderDrawColor", True)
        vTbl(SDL_RenderClear) = New_c.GetFuncPtr(DllPath, "SDL_RenderClear", True)
        vTbl(SDL_RenderGetViewport) = New_c.GetFuncPtr(DllPath, "SDL_RenderGetViewport", True)
        vTbl(SDL_RenderFillRect) = New_c.GetFuncPtr(DllPath, "SDL_RenderFillRect", True)
        vTbl(SDL_RenderPresent) = New_c.GetFuncPtr(DllPath, "SDL_RenderPresent", True)
        vTbl(SDL_UpdateWindowSurface) = New_c.GetFuncPtr(DllPath, "SDL_UpdateWindowSurface", True)
        vTbl(SDL_PollEvent) = New_c.GetFuncPtr(DllPath, "SDL_PollEvent", True)
        vTbl(SDL_FreeSurface) = New_c.GetFuncPtr(DllPath, "SDL_FreeSurface", True)
        vTbl(SDL_DestroyRenderer) = New_c.GetFuncPtr(DllPath, "SDL_DestroyRenderer", True)
        vTbl(SDL_DestroyWindow) = New_c.GetFuncPtr(DllPath, "SDL_DestroyWindow", True)
        vTbl(SDL_Quit) = New_c.GetFuncPtr(DllPath, "SDL_Quit", True)
        vTbl(SDL_GetKeyboardState) = New_c.GetFuncPtr(DllPath, "SDL_GetKeyboardState", True)
        
        LogSetPriority SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO
    End Sub
    
    Public Function LogSetPriority(ByVal Cat As SDL_LOG_CATEGORY, ByVal Prio As SDL_LogPriority) As Long
      LogSetPriority = New_c.cdeclCall(retLong, vTbl(SDL_LogSetPriority), Cat, Prio)
    End Function
    
    Public Function Init(ByVal Flags As SDL_INIT_FLAGS) As Long
      Init = New_c.cdeclCall(retLong, vTbl(SDL_Init), Flags)
    End Function
    
    Public Function GetError() As String
    Dim pErrStr As Long, SLen As Long
        pErrStr = New_c.cdeclCall(retLong, vTbl(SDL_GetError))
        If pErrStr = 0 Then Exit Function Else SLen = lstrlenA(pErrStr)
        If SLen Then GetError = Space$(SLen): lstrcpyA GetError, pErrStr
    End Function
    
    Public Function CreateWindow(Caption As String, ByVal x&, ByVal y&, ByVal dx&, ByVal dy&, Optional ByVal Flags As SDL_WindowFlags = SDL_WINDOW_RESIZABLE) As Long
      CreateWindow = New_c.cdeclCall(retLong, vTbl(SDL_CreateWindow), StrPtr(StrConv(Caption, vbFromUnicode)), x, y, dx, dy, Flags)
    End Function
    
    Public Function GetWindowSurface(Window As Long) As Long
      GetWindowSurface = New_c.cdeclCall(retLong, vTbl(SDL_GetWindowSurface), Window)
    End Function
    
    Public Function CreateSoftwareRenderer(Surface As Long) As Long
      CreateSoftwareRenderer = New_c.cdeclCall(retLong, vTbl(SDL_CreateSoftwareRenderer), Surface)
    End Function
    
    Public Function CreateRenderer(Window As Long, Optional ByVal Flags As SDL_RendererFlags = SDL_RENDERER_SOFTWARE) As Long
      CreateRenderer = New_c.cdeclCall(retLong, vTbl(SDL_CreateRenderer), Window, -1, Flags)
    End Function
    
    Public Function SetRenderDrawColor(Renderer As Long, ByVal R As Byte, ByVal G As Byte, ByVal B As Byte, Optional ByVal A As Byte = 255) As Long
      SetRenderDrawColor = New_c.cdeclCall(retLong, vTbl(SDL_SetRenderDrawColor), Renderer, R, G, B, A)
    End Function
    
    Public Function RenderClear(Renderer As Long) As Long
      RenderClear = New_c.cdeclCall(retLong, vTbl(SDL_RenderClear), Renderer)
    End Function
    
    Public Sub RenderGetViewport(Renderer As Long, x As Long, y As Long, dx As Long, dy As Long)
    Static Rct(0 To 3) As Long
        New_c.cdeclCall retVoid, vTbl(SDL_RenderGetViewport), Renderer, VarPtr(Rct(0))
        x = Rct(0): y = Rct(1): dx = Rct(2): dy = Rct(3)
    End Sub
    
    Public Function RenderFillRect(Renderer As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long) As Long
    Static Rect(0 To 3) As Long
        Rect(0) = x: Rect(1) = y: Rect(2) = dx: Rect(3) = dy
        RenderFillRect = New_c.cdeclCall(retLong, vTbl(SDL_RenderFillRect), Renderer, VarPtr(Rect(0)))
    End Function
    
    Public Function UpdateWindowSurface(Window As Long) As Long
      UpdateWindowSurface = New_c.cdeclCall(retLong, vTbl(SDL_UpdateWindowSurface), Window)
    End Function
    
    Public Sub RenderPresent(Renderer As Long)
      New_c.cdeclCall retVoid, vTbl(SDL_RenderPresent), Renderer
    End Sub
    
    Public Function PollEvent(eType As SDL_EventType) As Long
      PollEvent = New_c.cdeclCall(retLong, vTbl(SDL_PollEvent), VarPtr(mEvt))
      eType = mEvt.eType
    End Function
    Public Function Event_KeySym() As KeyCodeConstants
      Event_KeySym = mEvt.eBytes(8) + 256& * mEvt.eBytes(9)
    End Function
    
    Public Sub FreeSurface(Surface As Long)
      New_c.cdeclCall retVoid, vTbl(SDL_FreeSurface), Surface
    End Sub
    Public Sub DestroyRenderer(Renderer As Long)
      New_c.cdeclCall retVoid, vTbl(SDL_DestroyRenderer), Renderer
    End Sub
    Public Sub DestroyWindow(Window As Long)
      New_c.cdeclCall retVoid, vTbl(SDL_DestroyWindow), Window
    End Sub
     
    Public Sub RefreshKeyStates()
      Dim NumKeys As Long: NumKeys = SDL_NUM_SCANCODES
      Dim pKState As Long: pKState = New_c.cdeclCall(retLong, vTbl(SDL_GetKeyboardState), VarPtr(NumKeys))
    
      If pKState = 0 Or NumKeys > SDL_NUM_SCANCODES Then Err.Raise vbObjectError, , "unsuccesful call to SDL_GetKeyboardState"
    
      New_c.MemCopy VarPtr(mKeyStates(0)), pKState, NumKeys
    End Sub
    Public Function IsDown(ByVal ScanCode As SDL_Scancode) As Boolean
      IsDown = mKeyStates(ScanCode)
    End Function
    
    Private Sub Class_Terminate()
      New_c.cdeclCall retVoid, vTbl(SDL_Quit)
    End Sub
    The above worked flawlessly with the ChessBoard-Demos modMain.bas,
    where I've put the new Methods to work in the DrawChessBoard-routine:
    Code:
    Option Explicit
    
    Public SDL2 As New cSDL2
    
    Sub Main()
    Dim Window As Long, Renderer As Long, eType As SDL_EventType
    
      If SDL2.Init(SDL_INIT_VIDEO) Then Err.Raise vbObjectError, , SDL2.GetError
     
      'Create a Host-Window and a Renderer
      Window = SDL2.CreateWindow("Chess-Board", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 560)
      If Window = 0 Then Err.Raise vbObjectError, , SDL2.GetError
     
      Renderer = SDL2.CreateRenderer(Window, SDL_RENDERER_ACCELERATED Or SDL_RENDERER_PRESENTVSYNC)
      If Renderer = 0 Then Err.Raise vbObjectError, , SDL2.GetError
     
      Do Until eType = SDL_QUIT_ Or (eType = SDL_KEYDOWN And SDL2.Event_KeySym = vbKeyEscape)
         DrawChessBoard Renderer
        
         SDL2.RenderPresent Renderer 'update the View (flipping the Backbuf, whilst waiting for VSync)
      
         SDL2.PollEvent eType 'poll the Event-Status (before usage in the "Until"-condition at Loop-Entry)
      Loop
      
      SDL2.DestroyRenderer Renderer
      SDL2.DestroyWindow Window
    End Sub
    
    Sub DrawChessBoard(Renderer As Long)
    Dim Row&, Col&, x&, y&, dx&, dy&
    
        SDL2.RefreshKeyStates
        If SDL2.IsDown(SDL_SCANCODE_A) Or SDL2.IsDown(SDL_SCANCODE_S) Then Debug.Print "A or S Key is down"
        
        SDL2.SetRenderDrawColor Renderer, 255, 255, 255
        SDL2.RenderClear Renderer 'fill the entire render-area with the above color (white in this case)
     
        SDL2.RenderGetViewport Renderer, x, y, dx, dy 'get the Size of the viewport
        
        dx = dx \ 8: dy = dy \ 8 'adjust the retrieved client-area-dimensions to 1/8th
        
        For Row = 0 To 7: For Col = Row Mod 2 To 7 Step 2 'now render any second chessboard-rectangle...
          SDL2.SetRenderDrawColor Renderer, 0, 0, 0 '...with black color...
          SDL2.RenderFillRect Renderer, Col * dx, Row * dy, dx, dy '... and fill it
        Next Col, Row
    End Sub
    HTH

    Olaf

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2020
    Location
    Brazil
    Posts
    11

    Re: VB6 const Uint8 *state ina a DLL call ?

    Quote Originally Posted by Schmidt View Post
    Couldn't get this to work (due to a missing GCC-Dll-dependency)...

    But have seen, that the cSDL2-Class was based on the little ChessBoard-Demo I've posted a few years ago (using the RC5-cdecl-caller)...

    And I've had no problem, to do exactly the implementation as proposed:
    (placing the new KeyBoardState-Wrapper-Functions at the end of the cSDL2-Class in that older ChessBoard-Demo)
    Code:
    Option Explicit
    
    Public Enum SDL_EventType
      SDL_FIRSTEVENT = 0
      SDL_QUIT_ = &H100
      SDL_APP_TERMINATING
      SDL_APP_LOWMEMORY
      SDL_APP_WILLENTERBACKGROUND
      SDL_APP_DIDENTERBACKGROUND
      SDL_APP_WILLENTERFOREGROUND
      SDL_APP_DIDENTERFOREGROUND
      SDL_WindowEvent = &H200
      SDL_SysWMEvent
      SDL_KEYDOWN = &H300
      SDL_KEYUP
      SDL_TEXTEDITING
      SDL_TEXTINPUT
      SDL_MOUSEMOTION = &H400
      SDL_MOUSEBUTTONDOWN
      SDL_MOUSEBUTTONUP
      SDL_MOUSEWHEEL
      SDL_JOYAXISMOTION = &H600
      SDL_JOYBALLMOTION
      SDL_JOYHATMOTION
      SDL_JOYBUTTONDOWN
      SDL_JOYBUTTONUP
      SDL_JOYDEVICEADDED
      SDL_JOYDEVICEREMOVED
      SDL_CONTROLLERAXISMOTION = &H650
      SDL_CONTROLLERBUTTONDOWN
      SDL_CONTROLLERBUTTONUP
      SDL_CONTROLLERDEVICEADDED
      SDL_CONTROLLERDEVICEREMOVED
      SDL_CONTROLLERDEVICEREMAPPED
      SDL_FINGERDOWN = &H700
      SDL_FINGERUP
      SDL_FINGERMOTION
      SDL_DOLLARGESTURE = &H800
      SDL_DOLLARRECORD
      SDL_MULTIGESTURE
      SDL_CLIPBOARDUPDATE = &H900
      SDL_DROPFILE = &H1000
      SDL_UserEvent = &H8000&
      SDL_LASTEVENT = &HFFFF&
    End Enum
    
    Public Enum SDL_LOG_CATEGORY
      SDL_LOG_CATEGORY_APPLICATION
      SDL_LOG_CATEGORY_ERROR
      SDL_LOG_CATEGORY_ASSERT
      SDL_LOG_CATEGORY_SYSTEM
      SDL_LOG_CATEGORY_AUDIO
      SDL_LOG_CATEGORY_VIDEO
      SDL_LOG_CATEGORY_RENDER
      SDL_LOG_CATEGORY_INPUT
      SDL_LOG_CATEGORY_TEST
    End Enum
    
    Public Enum SDL_LogPriority
      SDL_LOG_PRIORITY_VERBOSE = 1
      SDL_LOG_PRIORITY_DEBUG
      SDL_LOG_PRIORITY_INFO
      SDL_LOG_PRIORITY_WARN
      SDL_LOG_PRIORITY_ERROR
      SDL_LOG_PRIORITY_CRITICAL
    End Enum
    
    Public Enum SDL_INIT_FLAGS
      SDL_INIT_TIMER = &H1
      SDL_INIT_AUDIO = &H10
      SDL_INIT_VIDEO = &H20
      SDL_INIT_JOYSTICK = &H200
      SDL_INIT_HAPTIC = &H1000
      SDL_INIT_GAMECONTROLLER = &H2000
      SDL_INIT_EVENTS = &H4000
      SDL_INIT_NOPARACHUTE = &H100000
    End Enum
    
    Public Enum SDL_WindowFlags
      SDL_WINDOW_FULLSCREEN = &H1
      SDL_WINDOW_OPENGL = &H2
      SDL_WINDOW_SHOWN = &H4
      SDL_WINDOW_HIDDEN = &H8
      SDL_WINDOW_BORDERLESS = &H10
      SDL_WINDOW_RESIZABLE = &H20
      SDL_WINDOW_MINIMIZED = &H40
      SDL_WINDOW_MAXIMIZED = &H80
      SDL_WINDOW_INPUT_GRABBED = &H100
      SDL_WINDOW_INPUT_FOCUS = &H200
      SDL_WINDOW_MOUSE_FOCUS = &H400
      SDL_WINDOW_FULLSCREEN_DESKTOP = (SDL_WINDOW_FULLSCREEN Or &H1000)
      SDL_WINDOW_FOREIGN = &H800
      SDL_WINDOW_ALLOW_HIGHDPI = &H2000
    End Enum
     
    Public Enum SDL_RendererFlags
      SDL_RENDERER_SOFTWARE = &H1
      SDL_RENDERER_ACCELERATED = &H2
      SDL_RENDERER_PRESENTVSYNC = &H4
      SDL_RENDERER_TARGETTEXTURE = &H8
    End Enum
    
    Public Enum SDL_WINDOWPOS
      SDL_WINDOWPOS_UNDEFINED = &H1FFF0000
      SDL_WINDOWPOS_CENTERED = &H2FFF0000
    End Enum
    '****** end of Public EnumDefs (which will show up on the Class-Interface) *****
    
    'the rest is Private-stuff for Class-internal usage...
    
    'these two are used to convert Zero-terminated 8Bit-CharSequences into VBStrings
    Private Declare Function lstrlenA& Lib "kernel32" (ByVal lpszSrc&)
    Private Declare Function lstrcpyA& Lib "kernel32" (ByVal lpszDest$, ByVal lpszSrc&)
    
    'the SDL-Event-struct is a Union - but most "Sub-Structs" have at least the first 3 Members in common
    Private Type SDL_EVENT
      eType As SDL_EventType
      eTimeStamp As Long
      eID As Long
      eBytes(0 To 63) As Byte
    End Type
    Private mEvt As SDL_EVENT 'this Class-Variable is the one used for Polling
    
    'the below ENum is used as a "speaking Index" in conjunction with the Function-Table (vTbl) directly below
    Private Enum SDL_Methods
      SDL_LogSetPriority
      SDL_Init
      SDL_GetError
      SDL_CreateWindow
      SDL_GetWindowSurface
      SDL_CreateSoftwareRenderer
      SDL_CreateRenderer
      SDL_SetRenderDrawColor
      SDL_RenderClear
      SDL_RenderGetViewport
      SDL_RenderFillRect
      SDL_RenderPresent
      SDL_UpdateWindowSurface
      SDL_PollEvent
      SDL_FreeSurface
      SDL_DestroyRenderer
      SDL_DestroyWindow
      SDL_Quit
      SDL_GetKeyboardState
      '... put additional methods here
      
      SDL_MethodsCount
    End Enum
    
    Public Enum SDL_Scancode
        SDL_SCANCODE_A = 4
        SDL_SCANCODE_B = 5
        SDL_SCANCODE_C = 6
        SDL_SCANCODE_D = 7
        SDL_SCANCODE_E = 8
        SDL_SCANCODE_F = 9
        SDL_SCANCODE_G = 10
        SDL_SCANCODE_H = 11
        SDL_SCANCODE_I = 12
        SDL_SCANCODE_J = 13
        SDL_SCANCODE_K = 14
        SDL_SCANCODE_L = 15
        SDL_SCANCODE_M = 16
        SDL_SCANCODE_N = 17
        SDL_SCANCODE_O = 18
        SDL_SCANCODE_P = 19
        SDL_SCANCODE_Q = 20
        SDL_SCANCODE_R = 21
        SDL_SCANCODE_S = 22
        SDL_SCANCODE_T = 23
        SDL_SCANCODE_U = 24
        SDL_SCANCODE_V = 25
        SDL_SCANCODE_W = 26
        SDL_SCANCODE_X = 27
        SDL_SCANCODE_Y = 28
        SDL_SCANCODE_Z = 29
    
        SDL_SCANCODE_1 = 30
        SDL_SCANCODE_2 = 31
        SDL_SCANCODE_3 = 32
        SDL_SCANCODE_4 = 33
        SDL_SCANCODE_5 = 34
        SDL_SCANCODE_6 = 35
        SDL_SCANCODE_7 = 36
        SDL_SCANCODE_8 = 37
        SDL_SCANCODE_9 = 38
        SDL_SCANCODE_0 = 39
    
        SDL_SCANCODE_RETURN = 40
        SDL_SCANCODE_ESCAPE = 41
        SDL_SCANCODE_BACKSPACE = 42
        SDL_SCANCODE_TAB = 43
        SDL_SCANCODE_SPACE = 44
    
        SDL_SCANCODE_MINUS = 45
        SDL_SCANCODE_EQUALS = 46
        SDL_SCANCODE_LEFTBRACKET = 47
        SDL_SCANCODE_RIGHTBRACKET = 48
        SDL_SCANCODE_BACKSLASH = 49
        SDL_SCANCODE_NONUSHASH = 50
        SDL_SCANCODE_SEMICOLON = 51
        SDL_SCANCODE_APOSTROPHE = 52
        SDL_SCANCODE_GRAVE = 53
        
        SDL_SCANCODE_COMMA = 54
        SDL_SCANCODE_PERIOD = 55
        SDL_SCANCODE_SLASH = 56
    
        SDL_SCANCODE_CAPSLOCK = 57
    
        SDL_SCANCODE_F1 = 58
        SDL_SCANCODE_F2 = 59
        SDL_SCANCODE_F3 = 60
        SDL_SCANCODE_F4 = 61
        SDL_SCANCODE_F5 = 62
        SDL_SCANCODE_F6 = 63
        SDL_SCANCODE_F7 = 64
        SDL_SCANCODE_F8 = 65
        SDL_SCANCODE_F9 = 66
        SDL_SCANCODE_F10 = 67
        SDL_SCANCODE_F11 = 68
        SDL_SCANCODE_F12 = 69
    
        SDL_SCANCODE_PRINTSCREEN = 70
        SDL_SCANCODE_SCROLLLOCK = 71
        SDL_SCANCODE_PAUSE = 72
        SDL_SCANCODE_INSERT = 73
                                
        SDL_SCANCODE_HOME = 74
        SDL_SCANCODE_PAGEUP = 75
        SDL_SCANCODE_DELETE = 76
        SDL_SCANCODE_END = 77
        SDL_SCANCODE_PAGEDOWN = 78
        SDL_SCANCODE_RIGHT = 79
        SDL_SCANCODE_LEFT = 80
        SDL_SCANCODE_DOWN = 81
        SDL_SCANCODE_UP = 82
        
        SDL_SCANCODE_NUMLOCKCLEAR = 83
                                      
        SDL_SCANCODE_KP_DIVIDE = 84
        SDL_SCANCODE_KP_MULTIPLY = 85
        SDL_SCANCODE_KP_MINUS = 86
        SDL_SCANCODE_KP_PLUS = 87
        SDL_SCANCODE_KP_ENTER = 88
        SDL_SCANCODE_KP_1 = 89
        SDL_SCANCODE_KP_2 = 90
        SDL_SCANCODE_KP_3 = 91
        SDL_SCANCODE_KP_4 = 92
        SDL_SCANCODE_KP_5 = 93
        SDL_SCANCODE_KP_6 = 94
        SDL_SCANCODE_KP_7 = 95
        SDL_SCANCODE_KP_8 = 96
        SDL_SCANCODE_KP_9 = 97
        SDL_SCANCODE_KP_0 = 98
        SDL_SCANCODE_KP_PERIOD = 99
    
        SDL_SCANCODE_NONUSBACKSLASH = 100
        SDL_SCANCODE_APPLICATION = 101
        SDL_SCANCODE_POWER = 102
        
        SDL_SCANCODE_KP_EQUALS = 103
        SDL_SCANCODE_F13 = 104
        SDL_SCANCODE_F14 = 105
        SDL_SCANCODE_F15 = 106
        SDL_SCANCODE_F16 = 107
        SDL_SCANCODE_F17 = 108
        SDL_SCANCODE_F18 = 109
        SDL_SCANCODE_F19 = 110
        SDL_SCANCODE_F20 = 111
        SDL_SCANCODE_F21 = 112
        SDL_SCANCODE_F22 = 113
        SDL_SCANCODE_F23 = 114
        SDL_SCANCODE_F24 = 115
        SDL_SCANCODE_EXECUTE = 116
        SDL_SCANCODE_HELP = 117
        SDL_SCANCODE_MENU = 118
        SDL_SCANCODE_SELECT = 119
        SDL_SCANCODE_STOP = 120
        SDL_SCANCODE_AGAIN = 121
        SDL_SCANCODE_UNDO = 122
        SDL_SCANCODE_CUT = 123
        SDL_SCANCODE_COPY = 124
        SDL_SCANCODE_PASTE = 125
        SDL_SCANCODE_FIND = 126
        SDL_SCANCODE_MUTE = 127
        SDL_SCANCODE_VOLUMEUP = 128
        SDL_SCANCODE_VOLUMEDOWN = 129
        SDL_SCANCODE_KP_COMMA = 133
        SDL_SCANCODE_KP_EQUALSAS400 = 134
    
        SDL_SCANCODE_INTERNATIONAL1 = 135
                                         
        SDL_SCANCODE_INTERNATIONAL2 = 136
        SDL_SCANCODE_INTERNATIONAL3 = 137
        SDL_SCANCODE_INTERNATIONAL4 = 138
        SDL_SCANCODE_INTERNATIONAL5 = 139
        SDL_SCANCODE_INTERNATIONAL6 = 140
        SDL_SCANCODE_INTERNATIONAL7 = 141
        SDL_SCANCODE_INTERNATIONAL8 = 142
        SDL_SCANCODE_INTERNATIONAL9 = 143
        SDL_SCANCODE_LANG1 = 144
        SDL_SCANCODE_LANG2 = 145
        SDL_SCANCODE_LANG3 = 146
        SDL_SCANCODE_LANG4 = 147
        SDL_SCANCODE_LANG5 = 148
        SDL_SCANCODE_LANG6 = 149
        SDL_SCANCODE_LANG7 = 150
        SDL_SCANCODE_LANG8 = 151
        SDL_SCANCODE_LANG9 = 152
    
        SDL_SCANCODE_ALTERASE = 153
        SDL_SCANCODE_SYSREQ = 154
        SDL_SCANCODE_CANCEL = 155
        SDL_SCANCODE_CLEAR = 156
        SDL_SCANCODE_PRIOR = 157
        SDL_SCANCODE_RETURN2 = 158
        SDL_SCANCODE_SEPARATOR = 159
        SDL_SCANCODE_OUT = 160
        SDL_SCANCODE_OPER = 161
        SDL_SCANCODE_CLEARAGAIN = 162
        SDL_SCANCODE_CRSEL = 163
        SDL_SCANCODE_EXSEL = 164
    
        SDL_SCANCODE_KP_00 = 176
        SDL_SCANCODE_KP_000 = 177
        SDL_SCANCODE_THOUSANDSSEPARATOR = 178
        SDL_SCANCODE_DECIMALSEPARATOR = 179
        SDL_SCANCODE_CURRENCYUNIT = 180
        SDL_SCANCODE_CURRENCYSUBUNIT = 181
        SDL_SCANCODE_KP_LEFTPAREN = 182
        SDL_SCANCODE_KP_RIGHTPAREN = 183
        SDL_SCANCODE_KP_LEFTBRACE = 184
        SDL_SCANCODE_KP_RIGHTBRACE = 185
        SDL_SCANCODE_KP_TAB = 186
        SDL_SCANCODE_KP_BACKSPACE = 187
        SDL_SCANCODE_KP_A = 188
        SDL_SCANCODE_KP_B = 189
        SDL_SCANCODE_KP_C = 190
        SDL_SCANCODE_KP_D = 191
        SDL_SCANCODE_KP_E = 192
        SDL_SCANCODE_KP_F = 193
        SDL_SCANCODE_KP_XOR = 194
        SDL_SCANCODE_KP_POWER = 195
        SDL_SCANCODE_KP_PERCENT = 196
        SDL_SCANCODE_KP_LESS = 197
        SDL_SCANCODE_KP_GREATER = 198
        SDL_SCANCODE_KP_AMPERSAND = 199
        SDL_SCANCODE_KP_DBLAMPERSAND = 200
        SDL_SCANCODE_KP_VERTICALBAR = 201
        SDL_SCANCODE_KP_DBLVERTICALBAR = 202
        SDL_SCANCODE_KP_COLON = 203
        SDL_SCANCODE_KP_HASH = 204
        SDL_SCANCODE_KP_SPACE = 205
        SDL_SCANCODE_KP_AT = 206
        SDL_SCANCODE_KP_EXCLAM = 207
        SDL_SCANCODE_KP_MEMSTORE = 208
        SDL_SCANCODE_KP_MEMRECALL = 209
        SDL_SCANCODE_KP_MEMCLEAR = 210
        SDL_SCANCODE_KP_MEMADD = 211
        SDL_SCANCODE_KP_MEMSUBTRACT = 212
        SDL_SCANCODE_KP_MEMMULTIPLY = 213
        SDL_SCANCODE_KP_MEMDIVIDE = 214
        SDL_SCANCODE_KP_PLUSMINUS = 215
        SDL_SCANCODE_KP_CLEAR = 216
        SDL_SCANCODE_KP_CLEARENTRY = 217
        SDL_SCANCODE_KP_BINARY = 218
        SDL_SCANCODE_KP_OCTAL = 219
        SDL_SCANCODE_KP_DECIMAL = 220
        SDL_SCANCODE_KP_HEXADECIMAL = 221
    
        SDL_SCANCODE_LCTRL = 224
        
        SDL_SCANCODE_LSHIFT = 225
        SDL_SCANCODE_LALT = 226
        SDL_SCANCODE_LGUI = 227
        SDL_SCANCODE_RCTRL = 228
        SDL_SCANCODE_RSHIFT = 229
        SDL_SCANCODE_RALT = 230
        SDL_SCANCODE_RGUI = 231
    
        SDL_SCANCODE_MODE = 257
                               
        SDL_SCANCODE_AUDIONEXT = 258
        SDL_SCANCODE_AUDIOPREV = 259
        SDL_SCANCODE_AUDIOSTOP = 260
        SDL_SCANCODE_AUDIOPLAY = 261
        SDL_SCANCODE_AUDIOMUTE = 262
        SDL_SCANCODE_MEDIASELECT = 263
        SDL_SCANCODE_WWW = 264
        SDL_SCANCODE_MAIL = 265
        SDL_SCANCODE_CALCULATOR = 266
        SDL_SCANCODE_COMPUTER = 267
        SDL_SCANCODE_AC_SEARCH = 268
        SDL_SCANCODE_AC_HOME = 269
        SDL_SCANCODE_AC_BACK = 270
        SDL_SCANCODE_AC_FORWARD = 271
        SDL_SCANCODE_AC_STOP = 272
        SDL_SCANCODE_AC_REFRESH = 273
        SDL_SCANCODE_AC_BOOKMARKS = 274
        
        SDL_SCANCODE_BRIGHTNESSDOWN = 275
        SDL_SCANCODE_BRIGHTNESSUP = 276
        SDL_SCANCODE_DISPLAYSWITCH = 277
                                        
        SDL_SCANCODE_KBDILLUMTOGGLE = 278
        SDL_SCANCODE_KBDILLUMDOWN = 279
        SDL_SCANCODE_KBDILLUMUP = 280
        SDL_SCANCODE_EJECT = 281
        SDL_SCANCODE_SLEEP = 282
    
        SDL_SCANCODE_APP1 = 283
        SDL_SCANCODE_APP2 = 284
    
        SDL_SCANCODE_AUDIOREWIND = 285
        SDL_SCANCODE_AUDIOFASTFORWARD = 286
    
        SDL_NUM_SCANCODES = 512
    End Enum
    
    Private mKeyStates(0 To SDL_NUM_SCANCODES - 1) As Byte
    
    Private vTbl(0 To SDL_MethodsCount - 1) As Long 'and here's our Private vTbl-Array for the Func-Pointers
    
    Private Sub Class_Initialize()
    Dim DllPath$: DllPath = App.Path & "\SDL2.dll"
        vTbl(SDL_LogSetPriority) = New_c.GetFuncPtr(DllPath, "SDL_LogSetPriority", True)
        vTbl(SDL_Init) = New_c.GetFuncPtr(DllPath, "SDL_Init", True)
        vTbl(SDL_GetError) = New_c.GetFuncPtr(DllPath, "SDL_GetError", True)
        vTbl(SDL_CreateWindow) = New_c.GetFuncPtr(DllPath, "SDL_CreateWindow", True)
        vTbl(SDL_GetWindowSurface) = New_c.GetFuncPtr(DllPath, "SDL_GetWindowSurface", True)
        vTbl(SDL_CreateSoftwareRenderer) = New_c.GetFuncPtr(DllPath, "SDL_CreateSoftwareRenderer", True)
        vTbl(SDL_CreateRenderer) = New_c.GetFuncPtr(DllPath, "SDL_CreateRenderer", True)
        vTbl(SDL_SetRenderDrawColor) = New_c.GetFuncPtr(DllPath, "SDL_SetRenderDrawColor", True)
        vTbl(SDL_RenderClear) = New_c.GetFuncPtr(DllPath, "SDL_RenderClear", True)
        vTbl(SDL_RenderGetViewport) = New_c.GetFuncPtr(DllPath, "SDL_RenderGetViewport", True)
        vTbl(SDL_RenderFillRect) = New_c.GetFuncPtr(DllPath, "SDL_RenderFillRect", True)
        vTbl(SDL_RenderPresent) = New_c.GetFuncPtr(DllPath, "SDL_RenderPresent", True)
        vTbl(SDL_UpdateWindowSurface) = New_c.GetFuncPtr(DllPath, "SDL_UpdateWindowSurface", True)
        vTbl(SDL_PollEvent) = New_c.GetFuncPtr(DllPath, "SDL_PollEvent", True)
        vTbl(SDL_FreeSurface) = New_c.GetFuncPtr(DllPath, "SDL_FreeSurface", True)
        vTbl(SDL_DestroyRenderer) = New_c.GetFuncPtr(DllPath, "SDL_DestroyRenderer", True)
        vTbl(SDL_DestroyWindow) = New_c.GetFuncPtr(DllPath, "SDL_DestroyWindow", True)
        vTbl(SDL_Quit) = New_c.GetFuncPtr(DllPath, "SDL_Quit", True)
        vTbl(SDL_GetKeyboardState) = New_c.GetFuncPtr(DllPath, "SDL_GetKeyboardState", True)
        
        LogSetPriority SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO
    End Sub
    
    Public Function LogSetPriority(ByVal Cat As SDL_LOG_CATEGORY, ByVal Prio As SDL_LogPriority) As Long
      LogSetPriority = New_c.cdeclCall(retLong, vTbl(SDL_LogSetPriority), Cat, Prio)
    End Function
    
    Public Function Init(ByVal Flags As SDL_INIT_FLAGS) As Long
      Init = New_c.cdeclCall(retLong, vTbl(SDL_Init), Flags)
    End Function
    
    Public Function GetError() As String
    Dim pErrStr As Long, SLen As Long
        pErrStr = New_c.cdeclCall(retLong, vTbl(SDL_GetError))
        If pErrStr = 0 Then Exit Function Else SLen = lstrlenA(pErrStr)
        If SLen Then GetError = Space$(SLen): lstrcpyA GetError, pErrStr
    End Function
    
    Public Function CreateWindow(Caption As String, ByVal x&, ByVal y&, ByVal dx&, ByVal dy&, Optional ByVal Flags As SDL_WindowFlags = SDL_WINDOW_RESIZABLE) As Long
      CreateWindow = New_c.cdeclCall(retLong, vTbl(SDL_CreateWindow), StrPtr(StrConv(Caption, vbFromUnicode)), x, y, dx, dy, Flags)
    End Function
    
    Public Function GetWindowSurface(Window As Long) As Long
      GetWindowSurface = New_c.cdeclCall(retLong, vTbl(SDL_GetWindowSurface), Window)
    End Function
    
    Public Function CreateSoftwareRenderer(Surface As Long) As Long
      CreateSoftwareRenderer = New_c.cdeclCall(retLong, vTbl(SDL_CreateSoftwareRenderer), Surface)
    End Function
    
    Public Function CreateRenderer(Window As Long, Optional ByVal Flags As SDL_RendererFlags = SDL_RENDERER_SOFTWARE) As Long
      CreateRenderer = New_c.cdeclCall(retLong, vTbl(SDL_CreateRenderer), Window, -1, Flags)
    End Function
    
    Public Function SetRenderDrawColor(Renderer As Long, ByVal R As Byte, ByVal G As Byte, ByVal B As Byte, Optional ByVal A As Byte = 255) As Long
      SetRenderDrawColor = New_c.cdeclCall(retLong, vTbl(SDL_SetRenderDrawColor), Renderer, R, G, B, A)
    End Function
    
    Public Function RenderClear(Renderer As Long) As Long
      RenderClear = New_c.cdeclCall(retLong, vTbl(SDL_RenderClear), Renderer)
    End Function
    
    Public Sub RenderGetViewport(Renderer As Long, x As Long, y As Long, dx As Long, dy As Long)
    Static Rct(0 To 3) As Long
        New_c.cdeclCall retVoid, vTbl(SDL_RenderGetViewport), Renderer, VarPtr(Rct(0))
        x = Rct(0): y = Rct(1): dx = Rct(2): dy = Rct(3)
    End Sub
    
    Public Function RenderFillRect(Renderer As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long) As Long
    Static Rect(0 To 3) As Long
        Rect(0) = x: Rect(1) = y: Rect(2) = dx: Rect(3) = dy
        RenderFillRect = New_c.cdeclCall(retLong, vTbl(SDL_RenderFillRect), Renderer, VarPtr(Rect(0)))
    End Function
    
    Public Function UpdateWindowSurface(Window As Long) As Long
      UpdateWindowSurface = New_c.cdeclCall(retLong, vTbl(SDL_UpdateWindowSurface), Window)
    End Function
    
    Public Sub RenderPresent(Renderer As Long)
      New_c.cdeclCall retVoid, vTbl(SDL_RenderPresent), Renderer
    End Sub
    
    Public Function PollEvent(eType As SDL_EventType) As Long
      PollEvent = New_c.cdeclCall(retLong, vTbl(SDL_PollEvent), VarPtr(mEvt))
      eType = mEvt.eType
    End Function
    Public Function Event_KeySym() As KeyCodeConstants
      Event_KeySym = mEvt.eBytes(8) + 256& * mEvt.eBytes(9)
    End Function
    
    Public Sub FreeSurface(Surface As Long)
      New_c.cdeclCall retVoid, vTbl(SDL_FreeSurface), Surface
    End Sub
    Public Sub DestroyRenderer(Renderer As Long)
      New_c.cdeclCall retVoid, vTbl(SDL_DestroyRenderer), Renderer
    End Sub
    Public Sub DestroyWindow(Window As Long)
      New_c.cdeclCall retVoid, vTbl(SDL_DestroyWindow), Window
    End Sub
     
    Public Sub RefreshKeyStates()
      Dim NumKeys As Long: NumKeys = SDL_NUM_SCANCODES
      Dim pKState As Long: pKState = New_c.cdeclCall(retLong, vTbl(SDL_GetKeyboardState), VarPtr(NumKeys))
    
      If pKState = 0 Or NumKeys > SDL_NUM_SCANCODES Then Err.Raise vbObjectError, , "unsuccesful call to SDL_GetKeyboardState"
    
      New_c.MemCopy VarPtr(mKeyStates(0)), pKState, NumKeys
    End Sub
    Public Function IsDown(ByVal ScanCode As SDL_Scancode) As Boolean
      IsDown = mKeyStates(ScanCode)
    End Function
    
    Private Sub Class_Terminate()
      New_c.cdeclCall retVoid, vTbl(SDL_Quit)
    End Sub
    The above worked flawlessly with the ChessBoard-Demos modMain.bas,
    where I've put the new Methods to work in the DrawChessBoard-routine:
    Code:
    Option Explicit
    
    Public SDL2 As New cSDL2
    
    Sub Main()
    Dim Window As Long, Renderer As Long, eType As SDL_EventType
    
      If SDL2.Init(SDL_INIT_VIDEO) Then Err.Raise vbObjectError, , SDL2.GetError
     
      'Create a Host-Window and a Renderer
      Window = SDL2.CreateWindow("Chess-Board", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 560)
      If Window = 0 Then Err.Raise vbObjectError, , SDL2.GetError
     
      Renderer = SDL2.CreateRenderer(Window, SDL_RENDERER_ACCELERATED Or SDL_RENDERER_PRESENTVSYNC)
      If Renderer = 0 Then Err.Raise vbObjectError, , SDL2.GetError
     
      Do Until eType = SDL_QUIT_ Or (eType = SDL_KEYDOWN And SDL2.Event_KeySym = vbKeyEscape)
         DrawChessBoard Renderer
        
         SDL2.RenderPresent Renderer 'update the View (flipping the Backbuf, whilst waiting for VSync)
      
         SDL2.PollEvent eType 'poll the Event-Status (before usage in the "Until"-condition at Loop-Entry)
      Loop
      
      SDL2.DestroyRenderer Renderer
      SDL2.DestroyWindow Window
    End Sub
    
    Sub DrawChessBoard(Renderer As Long)
    Dim Row&, Col&, x&, y&, dx&, dy&
    
        SDL2.RefreshKeyStates
        If SDL2.IsDown(SDL_SCANCODE_A) Or SDL2.IsDown(SDL_SCANCODE_S) Then Debug.Print "A or S Key is down"
        
        SDL2.SetRenderDrawColor Renderer, 255, 255, 255
        SDL2.RenderClear Renderer 'fill the entire render-area with the above color (white in this case)
     
        SDL2.RenderGetViewport Renderer, x, y, dx, dy 'get the Size of the viewport
        
        dx = dx \ 8: dy = dy \ 8 'adjust the retrieved client-area-dimensions to 1/8th
        
        For Row = 0 To 7: For Col = Row Mod 2 To 7 Step 2 'now render any second chessboard-rectangle...
          SDL2.SetRenderDrawColor Renderer, 0, 0, 0 '...with black color...
          SDL2.RenderFillRect Renderer, Col * dx, Row * dy, dx, dy '... and fill it
        Next Col, Row
    End Sub
    HTH

    Olaf

    Very Thanks Olaf,

    Its Working Now... the problem was here.

    Code:
    CopyMemory mKeyStates(0), pKState, NumKeys
    
    'change to, Works !
    
    CopyMemory VarPtr(mKeyStates(0)), ByVal pKState, NumKeys
    Yeah, The begin was your Code.

    But for now, without the RC5 DLL.

    Thanks again!

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2020
    Location
    Brazil
    Posts
    11

    Re: VB6 const Uint8 *state ina a DLL call ?

    Quote Originally Posted by Schmidt View Post
    Couldn't get this to work (due to a missing GCC-Dll-dependency)...

    But have seen, that the cSDL2-Class was based on the little ChessBoard-Demo I've posted a few years ago (using the RC5-cdecl-caller)...

    And I've had no problem, to do exactly the implementation as proposed:
    (placing the new KeyBoardState-Wrapper-Functions at the end of the cSDL2-Class in that older ChessBoard-Demo)
    Code:
    Option Explicit
    
    Public Enum SDL_EventType
      SDL_FIRSTEVENT = 0
      SDL_QUIT_ = &H100
      SDL_APP_TERMINATING
      SDL_APP_LOWMEMORY
      SDL_APP_WILLENTERBACKGROUND
      SDL_APP_DIDENTERBACKGROUND
      SDL_APP_WILLENTERFOREGROUND
      SDL_APP_DIDENTERFOREGROUND
      SDL_WindowEvent = &H200
      SDL_SysWMEvent
      SDL_KEYDOWN = &H300
      SDL_KEYUP
      SDL_TEXTEDITING
      SDL_TEXTINPUT
      SDL_MOUSEMOTION = &H400
      SDL_MOUSEBUTTONDOWN
      SDL_MOUSEBUTTONUP
      SDL_MOUSEWHEEL
      SDL_JOYAXISMOTION = &H600
      SDL_JOYBALLMOTION
      SDL_JOYHATMOTION
      SDL_JOYBUTTONDOWN
      SDL_JOYBUTTONUP
      SDL_JOYDEVICEADDED
      SDL_JOYDEVICEREMOVED
      SDL_CONTROLLERAXISMOTION = &H650
      SDL_CONTROLLERBUTTONDOWN
      SDL_CONTROLLERBUTTONUP
      SDL_CONTROLLERDEVICEADDED
      SDL_CONTROLLERDEVICEREMOVED
      SDL_CONTROLLERDEVICEREMAPPED
      SDL_FINGERDOWN = &H700
      SDL_FINGERUP
      SDL_FINGERMOTION
      SDL_DOLLARGESTURE = &H800
      SDL_DOLLARRECORD
      SDL_MULTIGESTURE
      SDL_CLIPBOARDUPDATE = &H900
      SDL_DROPFILE = &H1000
      SDL_UserEvent = &H8000&
      SDL_LASTEVENT = &HFFFF&
    End Enum
    
    Public Enum SDL_LOG_CATEGORY
      SDL_LOG_CATEGORY_APPLICATION
      SDL_LOG_CATEGORY_ERROR
      SDL_LOG_CATEGORY_ASSERT
      SDL_LOG_CATEGORY_SYSTEM
      SDL_LOG_CATEGORY_AUDIO
      SDL_LOG_CATEGORY_VIDEO
      SDL_LOG_CATEGORY_RENDER
      SDL_LOG_CATEGORY_INPUT
      SDL_LOG_CATEGORY_TEST
    End Enum
    
    Public Enum SDL_LogPriority
      SDL_LOG_PRIORITY_VERBOSE = 1
      SDL_LOG_PRIORITY_DEBUG
      SDL_LOG_PRIORITY_INFO
      SDL_LOG_PRIORITY_WARN
      SDL_LOG_PRIORITY_ERROR
      SDL_LOG_PRIORITY_CRITICAL
    End Enum
    
    Public Enum SDL_INIT_FLAGS
      SDL_INIT_TIMER = &H1
      SDL_INIT_AUDIO = &H10
      SDL_INIT_VIDEO = &H20
      SDL_INIT_JOYSTICK = &H200
      SDL_INIT_HAPTIC = &H1000
      SDL_INIT_GAMECONTROLLER = &H2000
      SDL_INIT_EVENTS = &H4000
      SDL_INIT_NOPARACHUTE = &H100000
    End Enum
    
    Public Enum SDL_WindowFlags
      SDL_WINDOW_FULLSCREEN = &H1
      SDL_WINDOW_OPENGL = &H2
      SDL_WINDOW_SHOWN = &H4
      SDL_WINDOW_HIDDEN = &H8
      SDL_WINDOW_BORDERLESS = &H10
      SDL_WINDOW_RESIZABLE = &H20
      SDL_WINDOW_MINIMIZED = &H40
      SDL_WINDOW_MAXIMIZED = &H80
      SDL_WINDOW_INPUT_GRABBED = &H100
      SDL_WINDOW_INPUT_FOCUS = &H200
      SDL_WINDOW_MOUSE_FOCUS = &H400
      SDL_WINDOW_FULLSCREEN_DESKTOP = (SDL_WINDOW_FULLSCREEN Or &H1000)
      SDL_WINDOW_FOREIGN = &H800
      SDL_WINDOW_ALLOW_HIGHDPI = &H2000
    End Enum
     
    Public Enum SDL_RendererFlags
      SDL_RENDERER_SOFTWARE = &H1
      SDL_RENDERER_ACCELERATED = &H2
      SDL_RENDERER_PRESENTVSYNC = &H4
      SDL_RENDERER_TARGETTEXTURE = &H8
    End Enum
    
    Public Enum SDL_WINDOWPOS
      SDL_WINDOWPOS_UNDEFINED = &H1FFF0000
      SDL_WINDOWPOS_CENTERED = &H2FFF0000
    End Enum
    '****** end of Public EnumDefs (which will show up on the Class-Interface) *****
    
    'the rest is Private-stuff for Class-internal usage...
    
    'these two are used to convert Zero-terminated 8Bit-CharSequences into VBStrings
    Private Declare Function lstrlenA& Lib "kernel32" (ByVal lpszSrc&)
    Private Declare Function lstrcpyA& Lib "kernel32" (ByVal lpszDest$, ByVal lpszSrc&)
    
    'the SDL-Event-struct is a Union - but most "Sub-Structs" have at least the first 3 Members in common
    Private Type SDL_EVENT
      eType As SDL_EventType
      eTimeStamp As Long
      eID As Long
      eBytes(0 To 63) As Byte
    End Type
    Private mEvt As SDL_EVENT 'this Class-Variable is the one used for Polling
    
    'the below ENum is used as a "speaking Index" in conjunction with the Function-Table (vTbl) directly below
    Private Enum SDL_Methods
      SDL_LogSetPriority
      SDL_Init
      SDL_GetError
      SDL_CreateWindow
      SDL_GetWindowSurface
      SDL_CreateSoftwareRenderer
      SDL_CreateRenderer
      SDL_SetRenderDrawColor
      SDL_RenderClear
      SDL_RenderGetViewport
      SDL_RenderFillRect
      SDL_RenderPresent
      SDL_UpdateWindowSurface
      SDL_PollEvent
      SDL_FreeSurface
      SDL_DestroyRenderer
      SDL_DestroyWindow
      SDL_Quit
      SDL_GetKeyboardState
      '... put additional methods here
      
      SDL_MethodsCount
    End Enum
    
    Public Enum SDL_Scancode
        SDL_SCANCODE_A = 4
        SDL_SCANCODE_B = 5
        SDL_SCANCODE_C = 6
        SDL_SCANCODE_D = 7
        SDL_SCANCODE_E = 8
        SDL_SCANCODE_F = 9
        SDL_SCANCODE_G = 10
        SDL_SCANCODE_H = 11
        SDL_SCANCODE_I = 12
        SDL_SCANCODE_J = 13
        SDL_SCANCODE_K = 14
        SDL_SCANCODE_L = 15
        SDL_SCANCODE_M = 16
        SDL_SCANCODE_N = 17
        SDL_SCANCODE_O = 18
        SDL_SCANCODE_P = 19
        SDL_SCANCODE_Q = 20
        SDL_SCANCODE_R = 21
        SDL_SCANCODE_S = 22
        SDL_SCANCODE_T = 23
        SDL_SCANCODE_U = 24
        SDL_SCANCODE_V = 25
        SDL_SCANCODE_W = 26
        SDL_SCANCODE_X = 27
        SDL_SCANCODE_Y = 28
        SDL_SCANCODE_Z = 29
    
        SDL_SCANCODE_1 = 30
        SDL_SCANCODE_2 = 31
        SDL_SCANCODE_3 = 32
        SDL_SCANCODE_4 = 33
        SDL_SCANCODE_5 = 34
        SDL_SCANCODE_6 = 35
        SDL_SCANCODE_7 = 36
        SDL_SCANCODE_8 = 37
        SDL_SCANCODE_9 = 38
        SDL_SCANCODE_0 = 39
    
        SDL_SCANCODE_RETURN = 40
        SDL_SCANCODE_ESCAPE = 41
        SDL_SCANCODE_BACKSPACE = 42
        SDL_SCANCODE_TAB = 43
        SDL_SCANCODE_SPACE = 44
    
        SDL_SCANCODE_MINUS = 45
        SDL_SCANCODE_EQUALS = 46
        SDL_SCANCODE_LEFTBRACKET = 47
        SDL_SCANCODE_RIGHTBRACKET = 48
        SDL_SCANCODE_BACKSLASH = 49
        SDL_SCANCODE_NONUSHASH = 50
        SDL_SCANCODE_SEMICOLON = 51
        SDL_SCANCODE_APOSTROPHE = 52
        SDL_SCANCODE_GRAVE = 53
        
        SDL_SCANCODE_COMMA = 54
        SDL_SCANCODE_PERIOD = 55
        SDL_SCANCODE_SLASH = 56
    
        SDL_SCANCODE_CAPSLOCK = 57
    
        SDL_SCANCODE_F1 = 58
        SDL_SCANCODE_F2 = 59
        SDL_SCANCODE_F3 = 60
        SDL_SCANCODE_F4 = 61
        SDL_SCANCODE_F5 = 62
        SDL_SCANCODE_F6 = 63
        SDL_SCANCODE_F7 = 64
        SDL_SCANCODE_F8 = 65
        SDL_SCANCODE_F9 = 66
        SDL_SCANCODE_F10 = 67
        SDL_SCANCODE_F11 = 68
        SDL_SCANCODE_F12 = 69
    
        SDL_SCANCODE_PRINTSCREEN = 70
        SDL_SCANCODE_SCROLLLOCK = 71
        SDL_SCANCODE_PAUSE = 72
        SDL_SCANCODE_INSERT = 73
                                
        SDL_SCANCODE_HOME = 74
        SDL_SCANCODE_PAGEUP = 75
        SDL_SCANCODE_DELETE = 76
        SDL_SCANCODE_END = 77
        SDL_SCANCODE_PAGEDOWN = 78
        SDL_SCANCODE_RIGHT = 79
        SDL_SCANCODE_LEFT = 80
        SDL_SCANCODE_DOWN = 81
        SDL_SCANCODE_UP = 82
        
        SDL_SCANCODE_NUMLOCKCLEAR = 83
                                      
        SDL_SCANCODE_KP_DIVIDE = 84
        SDL_SCANCODE_KP_MULTIPLY = 85
        SDL_SCANCODE_KP_MINUS = 86
        SDL_SCANCODE_KP_PLUS = 87
        SDL_SCANCODE_KP_ENTER = 88
        SDL_SCANCODE_KP_1 = 89
        SDL_SCANCODE_KP_2 = 90
        SDL_SCANCODE_KP_3 = 91
        SDL_SCANCODE_KP_4 = 92
        SDL_SCANCODE_KP_5 = 93
        SDL_SCANCODE_KP_6 = 94
        SDL_SCANCODE_KP_7 = 95
        SDL_SCANCODE_KP_8 = 96
        SDL_SCANCODE_KP_9 = 97
        SDL_SCANCODE_KP_0 = 98
        SDL_SCANCODE_KP_PERIOD = 99
    
        SDL_SCANCODE_NONUSBACKSLASH = 100
        SDL_SCANCODE_APPLICATION = 101
        SDL_SCANCODE_POWER = 102
        
        SDL_SCANCODE_KP_EQUALS = 103
        SDL_SCANCODE_F13 = 104
        SDL_SCANCODE_F14 = 105
        SDL_SCANCODE_F15 = 106
        SDL_SCANCODE_F16 = 107
        SDL_SCANCODE_F17 = 108
        SDL_SCANCODE_F18 = 109
        SDL_SCANCODE_F19 = 110
        SDL_SCANCODE_F20 = 111
        SDL_SCANCODE_F21 = 112
        SDL_SCANCODE_F22 = 113
        SDL_SCANCODE_F23 = 114
        SDL_SCANCODE_F24 = 115
        SDL_SCANCODE_EXECUTE = 116
        SDL_SCANCODE_HELP = 117
        SDL_SCANCODE_MENU = 118
        SDL_SCANCODE_SELECT = 119
        SDL_SCANCODE_STOP = 120
        SDL_SCANCODE_AGAIN = 121
        SDL_SCANCODE_UNDO = 122
        SDL_SCANCODE_CUT = 123
        SDL_SCANCODE_COPY = 124
        SDL_SCANCODE_PASTE = 125
        SDL_SCANCODE_FIND = 126
        SDL_SCANCODE_MUTE = 127
        SDL_SCANCODE_VOLUMEUP = 128
        SDL_SCANCODE_VOLUMEDOWN = 129
        SDL_SCANCODE_KP_COMMA = 133
        SDL_SCANCODE_KP_EQUALSAS400 = 134
    
        SDL_SCANCODE_INTERNATIONAL1 = 135
                                         
        SDL_SCANCODE_INTERNATIONAL2 = 136
        SDL_SCANCODE_INTERNATIONAL3 = 137
        SDL_SCANCODE_INTERNATIONAL4 = 138
        SDL_SCANCODE_INTERNATIONAL5 = 139
        SDL_SCANCODE_INTERNATIONAL6 = 140
        SDL_SCANCODE_INTERNATIONAL7 = 141
        SDL_SCANCODE_INTERNATIONAL8 = 142
        SDL_SCANCODE_INTERNATIONAL9 = 143
        SDL_SCANCODE_LANG1 = 144
        SDL_SCANCODE_LANG2 = 145
        SDL_SCANCODE_LANG3 = 146
        SDL_SCANCODE_LANG4 = 147
        SDL_SCANCODE_LANG5 = 148
        SDL_SCANCODE_LANG6 = 149
        SDL_SCANCODE_LANG7 = 150
        SDL_SCANCODE_LANG8 = 151
        SDL_SCANCODE_LANG9 = 152
    
        SDL_SCANCODE_ALTERASE = 153
        SDL_SCANCODE_SYSREQ = 154
        SDL_SCANCODE_CANCEL = 155
        SDL_SCANCODE_CLEAR = 156
        SDL_SCANCODE_PRIOR = 157
        SDL_SCANCODE_RETURN2 = 158
        SDL_SCANCODE_SEPARATOR = 159
        SDL_SCANCODE_OUT = 160
        SDL_SCANCODE_OPER = 161
        SDL_SCANCODE_CLEARAGAIN = 162
        SDL_SCANCODE_CRSEL = 163
        SDL_SCANCODE_EXSEL = 164
    
        SDL_SCANCODE_KP_00 = 176
        SDL_SCANCODE_KP_000 = 177
        SDL_SCANCODE_THOUSANDSSEPARATOR = 178
        SDL_SCANCODE_DECIMALSEPARATOR = 179
        SDL_SCANCODE_CURRENCYUNIT = 180
        SDL_SCANCODE_CURRENCYSUBUNIT = 181
        SDL_SCANCODE_KP_LEFTPAREN = 182
        SDL_SCANCODE_KP_RIGHTPAREN = 183
        SDL_SCANCODE_KP_LEFTBRACE = 184
        SDL_SCANCODE_KP_RIGHTBRACE = 185
        SDL_SCANCODE_KP_TAB = 186
        SDL_SCANCODE_KP_BACKSPACE = 187
        SDL_SCANCODE_KP_A = 188
        SDL_SCANCODE_KP_B = 189
        SDL_SCANCODE_KP_C = 190
        SDL_SCANCODE_KP_D = 191
        SDL_SCANCODE_KP_E = 192
        SDL_SCANCODE_KP_F = 193
        SDL_SCANCODE_KP_XOR = 194
        SDL_SCANCODE_KP_POWER = 195
        SDL_SCANCODE_KP_PERCENT = 196
        SDL_SCANCODE_KP_LESS = 197
        SDL_SCANCODE_KP_GREATER = 198
        SDL_SCANCODE_KP_AMPERSAND = 199
        SDL_SCANCODE_KP_DBLAMPERSAND = 200
        SDL_SCANCODE_KP_VERTICALBAR = 201
        SDL_SCANCODE_KP_DBLVERTICALBAR = 202
        SDL_SCANCODE_KP_COLON = 203
        SDL_SCANCODE_KP_HASH = 204
        SDL_SCANCODE_KP_SPACE = 205
        SDL_SCANCODE_KP_AT = 206
        SDL_SCANCODE_KP_EXCLAM = 207
        SDL_SCANCODE_KP_MEMSTORE = 208
        SDL_SCANCODE_KP_MEMRECALL = 209
        SDL_SCANCODE_KP_MEMCLEAR = 210
        SDL_SCANCODE_KP_MEMADD = 211
        SDL_SCANCODE_KP_MEMSUBTRACT = 212
        SDL_SCANCODE_KP_MEMMULTIPLY = 213
        SDL_SCANCODE_KP_MEMDIVIDE = 214
        SDL_SCANCODE_KP_PLUSMINUS = 215
        SDL_SCANCODE_KP_CLEAR = 216
        SDL_SCANCODE_KP_CLEARENTRY = 217
        SDL_SCANCODE_KP_BINARY = 218
        SDL_SCANCODE_KP_OCTAL = 219
        SDL_SCANCODE_KP_DECIMAL = 220
        SDL_SCANCODE_KP_HEXADECIMAL = 221
    
        SDL_SCANCODE_LCTRL = 224
        
        SDL_SCANCODE_LSHIFT = 225
        SDL_SCANCODE_LALT = 226
        SDL_SCANCODE_LGUI = 227
        SDL_SCANCODE_RCTRL = 228
        SDL_SCANCODE_RSHIFT = 229
        SDL_SCANCODE_RALT = 230
        SDL_SCANCODE_RGUI = 231
    
        SDL_SCANCODE_MODE = 257
                               
        SDL_SCANCODE_AUDIONEXT = 258
        SDL_SCANCODE_AUDIOPREV = 259
        SDL_SCANCODE_AUDIOSTOP = 260
        SDL_SCANCODE_AUDIOPLAY = 261
        SDL_SCANCODE_AUDIOMUTE = 262
        SDL_SCANCODE_MEDIASELECT = 263
        SDL_SCANCODE_WWW = 264
        SDL_SCANCODE_MAIL = 265
        SDL_SCANCODE_CALCULATOR = 266
        SDL_SCANCODE_COMPUTER = 267
        SDL_SCANCODE_AC_SEARCH = 268
        SDL_SCANCODE_AC_HOME = 269
        SDL_SCANCODE_AC_BACK = 270
        SDL_SCANCODE_AC_FORWARD = 271
        SDL_SCANCODE_AC_STOP = 272
        SDL_SCANCODE_AC_REFRESH = 273
        SDL_SCANCODE_AC_BOOKMARKS = 274
        
        SDL_SCANCODE_BRIGHTNESSDOWN = 275
        SDL_SCANCODE_BRIGHTNESSUP = 276
        SDL_SCANCODE_DISPLAYSWITCH = 277
                                        
        SDL_SCANCODE_KBDILLUMTOGGLE = 278
        SDL_SCANCODE_KBDILLUMDOWN = 279
        SDL_SCANCODE_KBDILLUMUP = 280
        SDL_SCANCODE_EJECT = 281
        SDL_SCANCODE_SLEEP = 282
    
        SDL_SCANCODE_APP1 = 283
        SDL_SCANCODE_APP2 = 284
    
        SDL_SCANCODE_AUDIOREWIND = 285
        SDL_SCANCODE_AUDIOFASTFORWARD = 286
    
        SDL_NUM_SCANCODES = 512
    End Enum
    
    Private mKeyStates(0 To SDL_NUM_SCANCODES - 1) As Byte
    
    Private vTbl(0 To SDL_MethodsCount - 1) As Long 'and here's our Private vTbl-Array for the Func-Pointers
    
    Private Sub Class_Initialize()
    Dim DllPath$: DllPath = App.Path & "\SDL2.dll"
        vTbl(SDL_LogSetPriority) = New_c.GetFuncPtr(DllPath, "SDL_LogSetPriority", True)
        vTbl(SDL_Init) = New_c.GetFuncPtr(DllPath, "SDL_Init", True)
        vTbl(SDL_GetError) = New_c.GetFuncPtr(DllPath, "SDL_GetError", True)
        vTbl(SDL_CreateWindow) = New_c.GetFuncPtr(DllPath, "SDL_CreateWindow", True)
        vTbl(SDL_GetWindowSurface) = New_c.GetFuncPtr(DllPath, "SDL_GetWindowSurface", True)
        vTbl(SDL_CreateSoftwareRenderer) = New_c.GetFuncPtr(DllPath, "SDL_CreateSoftwareRenderer", True)
        vTbl(SDL_CreateRenderer) = New_c.GetFuncPtr(DllPath, "SDL_CreateRenderer", True)
        vTbl(SDL_SetRenderDrawColor) = New_c.GetFuncPtr(DllPath, "SDL_SetRenderDrawColor", True)
        vTbl(SDL_RenderClear) = New_c.GetFuncPtr(DllPath, "SDL_RenderClear", True)
        vTbl(SDL_RenderGetViewport) = New_c.GetFuncPtr(DllPath, "SDL_RenderGetViewport", True)
        vTbl(SDL_RenderFillRect) = New_c.GetFuncPtr(DllPath, "SDL_RenderFillRect", True)
        vTbl(SDL_RenderPresent) = New_c.GetFuncPtr(DllPath, "SDL_RenderPresent", True)
        vTbl(SDL_UpdateWindowSurface) = New_c.GetFuncPtr(DllPath, "SDL_UpdateWindowSurface", True)
        vTbl(SDL_PollEvent) = New_c.GetFuncPtr(DllPath, "SDL_PollEvent", True)
        vTbl(SDL_FreeSurface) = New_c.GetFuncPtr(DllPath, "SDL_FreeSurface", True)
        vTbl(SDL_DestroyRenderer) = New_c.GetFuncPtr(DllPath, "SDL_DestroyRenderer", True)
        vTbl(SDL_DestroyWindow) = New_c.GetFuncPtr(DllPath, "SDL_DestroyWindow", True)
        vTbl(SDL_Quit) = New_c.GetFuncPtr(DllPath, "SDL_Quit", True)
        vTbl(SDL_GetKeyboardState) = New_c.GetFuncPtr(DllPath, "SDL_GetKeyboardState", True)
        
        LogSetPriority SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO
    End Sub
    
    Public Function LogSetPriority(ByVal Cat As SDL_LOG_CATEGORY, ByVal Prio As SDL_LogPriority) As Long
      LogSetPriority = New_c.cdeclCall(retLong, vTbl(SDL_LogSetPriority), Cat, Prio)
    End Function
    
    Public Function Init(ByVal Flags As SDL_INIT_FLAGS) As Long
      Init = New_c.cdeclCall(retLong, vTbl(SDL_Init), Flags)
    End Function
    
    Public Function GetError() As String
    Dim pErrStr As Long, SLen As Long
        pErrStr = New_c.cdeclCall(retLong, vTbl(SDL_GetError))
        If pErrStr = 0 Then Exit Function Else SLen = lstrlenA(pErrStr)
        If SLen Then GetError = Space$(SLen): lstrcpyA GetError, pErrStr
    End Function
    
    Public Function CreateWindow(Caption As String, ByVal x&, ByVal y&, ByVal dx&, ByVal dy&, Optional ByVal Flags As SDL_WindowFlags = SDL_WINDOW_RESIZABLE) As Long
      CreateWindow = New_c.cdeclCall(retLong, vTbl(SDL_CreateWindow), StrPtr(StrConv(Caption, vbFromUnicode)), x, y, dx, dy, Flags)
    End Function
    
    Public Function GetWindowSurface(Window As Long) As Long
      GetWindowSurface = New_c.cdeclCall(retLong, vTbl(SDL_GetWindowSurface), Window)
    End Function
    
    Public Function CreateSoftwareRenderer(Surface As Long) As Long
      CreateSoftwareRenderer = New_c.cdeclCall(retLong, vTbl(SDL_CreateSoftwareRenderer), Surface)
    End Function
    
    Public Function CreateRenderer(Window As Long, Optional ByVal Flags As SDL_RendererFlags = SDL_RENDERER_SOFTWARE) As Long
      CreateRenderer = New_c.cdeclCall(retLong, vTbl(SDL_CreateRenderer), Window, -1, Flags)
    End Function
    
    Public Function SetRenderDrawColor(Renderer As Long, ByVal R As Byte, ByVal G As Byte, ByVal B As Byte, Optional ByVal A As Byte = 255) As Long
      SetRenderDrawColor = New_c.cdeclCall(retLong, vTbl(SDL_SetRenderDrawColor), Renderer, R, G, B, A)
    End Function
    
    Public Function RenderClear(Renderer As Long) As Long
      RenderClear = New_c.cdeclCall(retLong, vTbl(SDL_RenderClear), Renderer)
    End Function
    
    Public Sub RenderGetViewport(Renderer As Long, x As Long, y As Long, dx As Long, dy As Long)
    Static Rct(0 To 3) As Long
        New_c.cdeclCall retVoid, vTbl(SDL_RenderGetViewport), Renderer, VarPtr(Rct(0))
        x = Rct(0): y = Rct(1): dx = Rct(2): dy = Rct(3)
    End Sub
    
    Public Function RenderFillRect(Renderer As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long) As Long
    Static Rect(0 To 3) As Long
        Rect(0) = x: Rect(1) = y: Rect(2) = dx: Rect(3) = dy
        RenderFillRect = New_c.cdeclCall(retLong, vTbl(SDL_RenderFillRect), Renderer, VarPtr(Rect(0)))
    End Function
    
    Public Function UpdateWindowSurface(Window As Long) As Long
      UpdateWindowSurface = New_c.cdeclCall(retLong, vTbl(SDL_UpdateWindowSurface), Window)
    End Function
    
    Public Sub RenderPresent(Renderer As Long)
      New_c.cdeclCall retVoid, vTbl(SDL_RenderPresent), Renderer
    End Sub
    
    Public Function PollEvent(eType As SDL_EventType) As Long
      PollEvent = New_c.cdeclCall(retLong, vTbl(SDL_PollEvent), VarPtr(mEvt))
      eType = mEvt.eType
    End Function
    Public Function Event_KeySym() As KeyCodeConstants
      Event_KeySym = mEvt.eBytes(8) + 256& * mEvt.eBytes(9)
    End Function
    
    Public Sub FreeSurface(Surface As Long)
      New_c.cdeclCall retVoid, vTbl(SDL_FreeSurface), Surface
    End Sub
    Public Sub DestroyRenderer(Renderer As Long)
      New_c.cdeclCall retVoid, vTbl(SDL_DestroyRenderer), Renderer
    End Sub
    Public Sub DestroyWindow(Window As Long)
      New_c.cdeclCall retVoid, vTbl(SDL_DestroyWindow), Window
    End Sub
     
    Public Sub RefreshKeyStates()
      Dim NumKeys As Long: NumKeys = SDL_NUM_SCANCODES
      Dim pKState As Long: pKState = New_c.cdeclCall(retLong, vTbl(SDL_GetKeyboardState), VarPtr(NumKeys))
    
      If pKState = 0 Or NumKeys > SDL_NUM_SCANCODES Then Err.Raise vbObjectError, , "unsuccesful call to SDL_GetKeyboardState"
    
      New_c.MemCopy VarPtr(mKeyStates(0)), pKState, NumKeys
    End Sub
    Public Function IsDown(ByVal ScanCode As SDL_Scancode) As Boolean
      IsDown = mKeyStates(ScanCode)
    End Function
    
    Private Sub Class_Terminate()
      New_c.cdeclCall retVoid, vTbl(SDL_Quit)
    End Sub
    The above worked flawlessly with the ChessBoard-Demos modMain.bas,
    where I've put the new Methods to work in the DrawChessBoard-routine:
    Code:
    Option Explicit
    
    Public SDL2 As New cSDL2
    
    Sub Main()
    Dim Window As Long, Renderer As Long, eType As SDL_EventType
    
      If SDL2.Init(SDL_INIT_VIDEO) Then Err.Raise vbObjectError, , SDL2.GetError
     
      'Create a Host-Window and a Renderer
      Window = SDL2.CreateWindow("Chess-Board", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 560)
      If Window = 0 Then Err.Raise vbObjectError, , SDL2.GetError
     
      Renderer = SDL2.CreateRenderer(Window, SDL_RENDERER_ACCELERATED Or SDL_RENDERER_PRESENTVSYNC)
      If Renderer = 0 Then Err.Raise vbObjectError, , SDL2.GetError
     
      Do Until eType = SDL_QUIT_ Or (eType = SDL_KEYDOWN And SDL2.Event_KeySym = vbKeyEscape)
         DrawChessBoard Renderer
        
         SDL2.RenderPresent Renderer 'update the View (flipping the Backbuf, whilst waiting for VSync)
      
         SDL2.PollEvent eType 'poll the Event-Status (before usage in the "Until"-condition at Loop-Entry)
      Loop
      
      SDL2.DestroyRenderer Renderer
      SDL2.DestroyWindow Window
    End Sub
    
    Sub DrawChessBoard(Renderer As Long)
    Dim Row&, Col&, x&, y&, dx&, dy&
    
        SDL2.RefreshKeyStates
        If SDL2.IsDown(SDL_SCANCODE_A) Or SDL2.IsDown(SDL_SCANCODE_S) Then Debug.Print "A or S Key is down"
        
        SDL2.SetRenderDrawColor Renderer, 255, 255, 255
        SDL2.RenderClear Renderer 'fill the entire render-area with the above color (white in this case)
     
        SDL2.RenderGetViewport Renderer, x, y, dx, dy 'get the Size of the viewport
        
        dx = dx \ 8: dy = dy \ 8 'adjust the retrieved client-area-dimensions to 1/8th
        
        For Row = 0 To 7: For Col = Row Mod 2 To 7 Step 2 'now render any second chessboard-rectangle...
          SDL2.SetRenderDrawColor Renderer, 0, 0, 0 '...with black color...
          SDL2.RenderFillRect Renderer, Col * dx, Row * dy, dx, dy '... and fill it
        Next Col, Row
    End Sub
    HTH

    Olaf

    Very Thanks Olaf,

    Its Working Now... the problem was here.

    Code:
    CopyMemory mKeyStates(0), pKState, NumKeys
    
    'change to, Works !
    
    CopyMemory VarPtr(mKeyStates(0)), ByVal pKState, NumKeys
    Yeah, The begin was your Code.

    But for now, without the RC5 DLL.

    Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width