[Help]Unable to Suspend a Thread.

Posts 1–10 of 10 · Page 1 of 1
[Help]Unable to Suspend a Thread.
Trouble Suspending Thread.

Edit: This is Visual Basic 6.

The only solution is I am missing something or my request is denied.
I'm able to open the thread without errors but SuspendThread just doesn't want to work. (Tried on a few applications and all failed).

Declarations:
Code:
Private Declare Function ResumeThread Lib "kernel32.dll" (ByVal hThread As Long) As Long
Private Declare Function SuspendThread Lib "kernel32.dll" (ByVal hThread As Long) As Long
Private Declare Function OpenThread Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwThreadId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Const SUSPEND_RESUME = &H2 'This could be my problem.

'Same as GetWindowThreadProcessId (DUR)
Public Declare Function GetThreadID Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Function:
Code:
hwnd = FindWindow("GFC_StdWindowClass", vbNullString)
If hwnd > 0 Then
PID = GetWindowThreadProcessId(hwnd, lngPID)
hProcess = OpenThread(SUSPEND_RESUME, False, PID)
If hProcess <> 0 Then
Call SuspendThread(PID)


[php]
Imports System.Threading

Public This_Thread as thread = New Thread(AddressOf Whocares)

Sub WhoCares()
Try
'Some code here, i don't care what
This_Thread.suspend
Catch e as ThreadStateException
Msgbox( e.ToString())
End try
End Sub

[/php]

In form load.

[php]
This_Thread.Start
[/php]

See if you get a error.
Thanks for your reply but I don't use VB.Net.
If that works, Great addition to this thread!

I want to do this in VB6. Do you have any idea as why it isn't working?
I don't receive any errors with my code. I get return -1.
Quote Originally Posted by fuked View Post
Thanks for your reply but I don't use VB.Net.
If that works, Great addition to this thread!

I want to do this in VB6. Do you have any idea as why it isn't working?
I don't receive any errors with my code. I get return -1.

move on from vb6 to vb.net. > forget the past!
Quote Originally Posted by XGelite View Post
move on from vb6 to vb.net. > forget the passed!
So true. I'm going to try it in C++ later on. I dislike .Net tho. Just not comfortable with it I guess. VB6 I am.
Quote Originally Posted by fuked View Post
So true. I'm going to try it in C++ later on. I dislike .Net tho. Just not comfortable with it I guess. VB6 I am.
It'd help if you read the documentation on SuspendThread.
Quote Originally Posted by msdn
hThread [in]

A handle to the thread that is to be suspended.
You're passing a ProcessID to SuspendThread, when you should be passing a Handle.
Quote Originally Posted by Iamazn1 View Post
It'd help if you read the documentation on SuspendThread.

You're passing a ProcessID to SuspendThread, when you should be passing a Handle.
The function I use is the same of that as GetThreadID and I'm Not using ProcessID.
I confirm that I get the ThreadID using Spy++. They are a match.

If ThreadID is incorrect, please Define: "Handle".


Quote Originally Posted by Calebb View Post
It's been forever since Ive used VB6 lol. I still name my buttons with cmd in the front.
It is best practice to do this in any language.
Quote Originally Posted by fuked View Post
The function I use is the same of that as GetThreadID and I'm Not using ProcessID.
I confirm that I get the ThreadID using Spy++. They are a match.

If ThreadID is incorrect, please Define: "Handle".




It is best practice to do this in any language.
Thread Handles and Identifiers (Windows)
It's been forever since Ive used VB6 lol. I still name my buttons with cmd in the front.
Okay, I love vb6 (solely because it is unmanaged and allows for some great functionality) However, seriously , You should move on as a VB developer. Your not familiar enough with VB6 , so while your still young in development, move on before the technology passes you up (IE, if you can't figure out how to suspend a thread yet {basic} then you are not proficient at developing in vb6 anyway{IMO}).

.net framework is the way of the future, and has been for a long time. Unless your developing for 98Se, 95 etc, then there is no real use for it, and no legitimate excuse for not learning .net
Posts 1–10 of 10 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

Talk with us