Simon Morgan
6 posts
I used to have controller support working. It has stopped working. I have no idea why it has stopped working. LoadLibrary always returns NULL. I'm linking against XInput9_1_0.lib. I'm trying to load xinput1_4.dll and xinput1_3.dll. I've tried using an official Xbox 360 controller and a Logitech F310 both of which support XInput. Can somebody please help?

Simon Morgan
6 posts
I found the cause (I think) but don't know what was causing it. This code didn't work:

 1 2 3 4 5 HMODULE XInputLibrary = LoadLibrary("xinput1_4.dll"); if (!XInputLibrary) { HMODULE XInputLibrary = LoadLibrary("xinput1_3.dll"); } 

and this did:

 1 2 3 4 5 HMODULE XInputLibrary = LoadLibrary("xinput1_4.dll"); if (!XInputLibrary) { XInputLibrary = LoadLibrary("xinput1_3.dll"); } 

Declared values seem to be non-NULL by default and I can see why this would obviously screw with the if statement, but I don't see why this would be a problem in practise because XInputLibrary is immediately assigned the return value of LoadLibrary.
505 posts
drguildo
I found the cause (I think) but don't know what was causing it. This code didn't work:

 1 2 3 4 5 HMODULE XInputLibrary = LoadLibrary("xinput1_4.dll"); if (!XInputLibrary) { HMODULE XInputLibrary = LoadLibrary("xinput1_3.dll"); } 

and this did:

 1 2 3 4 5 HMODULE XInputLibrary = LoadLibrary("xinput1_4.dll"); if (!XInputLibrary) { XInputLibrary = LoadLibrary("xinput1_3.dll"); } 

Declared values seem to be non-NULL by default and I can see why this would obviously screw with the if statement, but I don't see why this would be a problem in practise because XInputLibrary is immediately assigned the return value of LoadLibrary.

Because the second assignment to XInputLibrary in

 1 2 3 4 5 HMODULE XInputLibrary = LoadLibrary("xinput1_4.dll"); if (!XInputLibrary) { HMODULE XInputLibrary = LoadLibrary("xinput1_3.dll"); } 

is assigned to a whole new variable which is thrown away when it exits the block. Leaving you with the null in the original variable. This is called variable shadowing.
Simon Morgan
6 posts
ratchetfreak
Because the second assignment to XInputLibrary in

 1 2 3 4 5 HMODULE XInputLibrary = LoadLibrary("xinput1_4.dll"); if (!XInputLibrary) { HMODULE XInputLibrary = LoadLibrary("xinput1_3.dll"); } 

is assigned to a whole new variable which is thrown away when it exits the block. Leaving you with the null in the original variable. This is called variable shadowing.

That makes sense. Thanks.
Mārtiņš Možeiko
2405 posts / 2 projects