Archive: Weird System.dll problem...


Weird System.dll problem...
If I call an API by itself it works, but if I call the same API followed by a second API the first API fails. :weird:

What's even stranger is if I call the first API and then DetailPrint a random variable the first API fails. :weird:

------------------------------------------------
Ex. 1: Uncomment Second API to make fail.
------------------------------------------------
!define APPNAME "Detect New Devices"
!define APPNAMEANDVERSION "Detect New Devices 1.0"

Name "${APPNAMEANDVERSION}"
InstallDir "$PROGRAMFILES\Detect New Devices"
OutFile "DetectNewDevices.exe"

!include "MUI.nsh"

!define MUI_ABORTWARNING

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_RESERVEFILE_LANGDLL

Section "Detect New Devices" Section1
SetOverwrite on
SetOutPath $INSTDIR
Call GetDevNode
SectionEnd

!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${Section1} ""
!insertmacro MUI_FUNCTION_DESCRIPTION_END

Function GetDevNode
SetPluginUnload alwaysoff
StrCpy $1 ""
System::Call 'setupapi::CM_Locate_DevNodeA(*i .r0, *t r1r1, i r2r2) i .r3'
;System::Call 'setupapi::CM_Reenumerate_DevNode(*i r0r0, i r4r4) i .r5'
DetailPrint "Var0: $0"
DetailPrint "Var1: $1"
DetailPrint "Var2: $2"
DetailPrint "Ret Val: $3"

SetPluginUnload manual
System::Free 0
FunctionEnd
------------------------------------------------
Ex. 2: Uncomment DetailPrint "Weird: $5" to make fail
------------------------------------------------
!define APPNAME "Detect New Devices"
!define APPNAMEANDVERSION "Detect New Devices 1.0"

Name "${APPNAMEANDVERSION}"
InstallDir "$PROGRAMFILES\Detect New Devices"
OutFile "DetectNewDevices.exe"

!include "MUI.nsh"

!define MUI_ABORTWARNING

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_RESERVEFILE_LANGDLL

Section "Detect New Devices" Section1
SetOverwrite on
SetOutPath $INSTDIR
Call GetDevNode
SectionEnd

!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${Section1} ""
!insertmacro MUI_FUNCTION_DESCRIPTION_END

Function GetDevNode
SetPluginUnload alwaysoff
StrCpy $1 ""
System::Call 'setupapi::CM_Locate_DevNodeA(*i .r0, *t r1r1, i r2r2) i .r3'
DetailPrint "Var0: $0"
DetailPrint "Var1: $1"
DetailPrint "Var2: $2"
DetailPrint "Ret Val: $3"

;DetailPrint "Weird: $5"
SetPluginUnload manual
System::Free 0
FunctionEnd
------------------------------------------------

An help on this would be greatly appreciated.

Thanks.

jc3


CM_Locate_DevNode takes a string as the second parameter, not a pointer to a string. CM_Reenumerate_DevNode takes an integer (handle, DEVINST) as the first parameter, not a pointer to an integer.

You should check the return values, it's the first call that fails, not the second.


Thank you for your reply.

EDITED
I'm still having problems with this, but it looks like it something machine specific where It's working when it shouldn't but isn't when it should.

I had the change to try this on another PC today and it works properly, but works in the reverse on my laptop.

Go figure.

Thanks again.

jc3