Jump to content

Array Error


Caiol
 Share

Recommended Posts

Hello everyone...

I'm getting an error with my script:

"Subscript used with non-Array variable"

Script:

While ProcessExists("msskn.exe")
    $iPID = ProcessExists("msskn.exe")
    $get = _ProcessGetLoadedModules($iPID)

    $max = UBound($get)

    if $max-1 > $i Then
        $i = $i + 1
    Elseif $i = $max-1 Then
        $i = 0
    ElseIf $i > $max-1 Then
        $i = 0
    Else
        $i = 0
    EndIf
    
    $TestPath = _PathSplit($get[$i], $szDrive, $szDir, $szFName, $szExt)
WEnd

I don't know what is the problem... i'd tryed everything that I known...

Function _ProcessGetLoadedModules:

#Include <WinAPI.au3>

; #FUNCTION#;===============================================================================
;
; Name...........: _ProcessGetLoadedModules
; Description ...: Returns an array containing the full path of the loaded modules
; Syntax.........: _ProcessGetLoadedModules($iPID)
; Parameters ....:
; Return values .: Success - An array with all the paths
;               : Failure - -1 and @error=1 if the specified process couldn't be opened.
; Author ........: Andreas Karlsson (monoceres) & ProgAndy
; Modified.......:
; Remarks .......:
; Related .......: 
; Link ..........;
; Example .......; No
;
;;==========================================================================================
Func _ProcessGetLoadedModules($iPID)
    Local Const $PROCESS_QUERY_INFORMATION=0x0400
    Local Const $PROCESS_VM_READ=0x0010
    Local $aCall, $hPsapi=DllOpen("Psapi.dll")
    Local $hProcess, $tModulesStruct
    $tModulesStruct=DllStructCreate("hwnd [200]")
    Local $SIZEOFHWND = DllStructGetSize($tModulesStruct)/200
    $hProcess=_WinAPI_OpenProcess(BitOR($PROCESS_QUERY_INFORMATION,$PROCESS_VM_READ),False,$iPID)
    If Not $hProcess Then Return SetError(1,0,-1)
    $aCall=DllCall($hPsapi,"int","EnumProcessModules","ptr",$hProcess,"ptr",DllStructGetPtr($tModulesStruct),"dword",DllStructGetSize($tModulesStruct),"dword*","")
    
    If $aCall[4]>DllStructGetSize($tModulesStruct) Then
        $Dimensions = $aCall[4] / $SIZEOFHWND
        If $Dimensions <= 0 Then $Dimensions = 1    ;just an example
        $tModulesStruct=DllStructCreate("hwnd ["&$dimensions&"]")
        $aCall=DllCall($hPsapi,"int","EnumProcessModules","ptr",$hProcess,"ptr",DllStructGetPtr($tModulesStruct),"dword",$aCall[4],"dword*","")
    EndIf
    $Dimensions = $aCall[4] / $SIZEOFHWND
    If $Dimensions <= 0 Then $Dimensions = 1    ;just an example
    Local $aReturn[$Dimensions] ;This way, you will not get an error
    For $i=0 To Ubound($aReturn)-1
        
$aCall=DllCall($hPsapi,"dword","GetModuleFileNameExW","ptr",$hProcess,"ptr",DllStructGetData($tModulesStruct,1,$i+1),"wstr","","dword",65536)
$aReturn[$i]=$aCall[3]
    
Next
    _WinAPI_CloseHandle($hProcess)
    DllClose($hPsapi)
    Return $aReturn
EndFunc

Someone helps? :)

Link to comment
Share on other sites

  • Moderators

Caiol,

Looking at the header for _ProcessGetLoadedModules you see the following:

; Return values .: Success - An array with all the paths
;                : Failure - -1 and @error=1 if the specified process couldn't be opened.

So I would suggest that the function is failing to return an array and then you get the error when you try to read the array elements. :)

What you need to do is to add an errorchecking line to check for @error after the function return and only run the rest of your code if it is not set. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...