1 2 3 4 5 | HMODULE XInputLibrary = LoadLibrary("xinput1_4.dll"); if (!XInputLibrary) { HMODULE XInputLibrary = LoadLibrary("xinput1_3.dll"); } |
1 2 3 4 5 | HMODULE XInputLibrary = LoadLibrary("xinput1_4.dll"); if (!XInputLibrary) { XInputLibrary = LoadLibrary("xinput1_3.dll"); } |
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.
1 2 3 4 5 | HMODULE XInputLibrary = LoadLibrary("xinput1_4.dll"); if (!XInputLibrary) { HMODULE XInputLibrary = LoadLibrary("xinput1_3.dll"); } |
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.