calling "user32.dll" so that i can get the process thread

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer

this is the was i declared it in VB 6 and VB.net but in .NET i am getting and index out range error when i try to attach the value in the variable to a string.

"GetWindowThreadProcessId" returns a value to a varaible I have cast it with cstr() and forced it with .tostring still it won't work the same way.

I am not sure how to proceed. thank you for any help




Answer this question

calling "user32.dll" so that i can get the process thread

  • hellomcv

    as i was typing th elast message it dawned on me that the index problem could possibly be coming from the status bar.

    So i checked that and low and behold it worked. I took for granted that the conversion tool from VB6 to VB.net would have made that work right especially when i see the items before it get assigned.

    thank you for the help.



  • farcus

    Not sure what problem your haveing there...however you do have a .NET way of getting the threadId...

    Dim p() As Process = Process.GetProcesses

    Dim T As System.Diagnostics.ProcessThreadCollection = p(0).Threads

    Dim FirstThreadIdOfFirstProcess As Integer = T(0).Id



  • Stuman99

    Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index

    is the error i continue to get when i pass it to the result to this string

    SbCust.Items.Item(6).Text = "Session ID: " & .....

    the function works fine and it gets the result but it wont pass it to the string. I have cstr().tostring, i have added .tostring the variable and nothing seems to work



  • lordali

    the sbcust variable was actaully the status bar. Since i am new to .net i didn't know they changed how they index the panels, so when the rest of the assignments worked i took it for granted that the last one should work.

    I am also just starting to get used to the way error are trapped by visual studio 2005, sometimes it is hard for me to tell which part of the equasion is the problem



  • Simonth

    Try declaring your function as follows and let me know if it still does not work

    Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As IntPtr, ByRef lpdwProcessID As Long) As Long

    Richard


  • MartinAlvarez

    Hi

    What type does the SbCust variable represent

    Richard


  • calling "user32.dll" so that i can get the process thread