Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use "SuspendThread()".The error code is "5".

Status
Not open for further replies.

gxlzlu

Programmer
Oct 8, 2001
8
CN
Global array: HANDLE ThreadArray[5];

In main thread: ThreadArray=::CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) ChildThread,&iArray,0,NULL)//just want to save the Handle of ChildThread.

In other thread:£º::SuspendThread(ThreadArray);//error

I use "::GetLasterror()" to get what the error is.It show me "5".So it is "access deny".But all of the threads is in the same process.I don't konw why??Who can help me??
 
I am useing ATL.And all of this was declared in a componemt.(COM)
 
Can't say I quite understand your code.

ThreadArray=::CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) ChildThread,&iArray,0,NULL)

won't compile since ThreadArray is a void*[] and CreateThread returns a void*. I.e, you need to say ThreadArray[0] or whatever. The same applies to SuspendThread() where you are passing the array itself and not the handle value from some element. This compiles though since you can convert any pointer to a void pointer.

I.e.,

::SuspendThread(ThreadArray[0]);

or so would be correct. Maybe this is a typo though. I'd expect an error code 6 invalid handle from SuspendThread().

:) Hope that this helped! :)
 
Sorry!!I used "SuspendThread(ThreadArray)" in my program.Just write wrong.I am so sorry!!

I have check it in MSDN. Maybe I should set some security to those thread.But I don't know how to do.Could you help me?

After all Thanks for you help!!
 
I can't think of any reason why threads in the same process started under the same user should cause this problem, unless you've actually set a SD in the SECURITY_ATTRIBUTES which prevents access, which is not likely, I think. Maybe you're picking up some value which happens to be a valid thread handle, although kernel object handles are process-relative in NT or W2K (what are you using BTW?) :) Hope that this helped! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top