I can't see why the last parameter to CreateToolhelp32Snapshot is 0, as that means current process Id, in this case Perl - I would have thought this should be PID of the process whose thread I want to change. ??HANDLE hProcessSnap = NULL; BOOL bRet = FALSE; THREADENTRY32 te32 = {0}; // Take a snapshot of all processes in the system. hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); if (hProcessSnap == INVALID_HANDLE_VALUE) return (FALSE); // Fill in the size of the structure before using it. te32.dwSize = sizeof(THREADENTRY32); // Get first process information Thread32First(hProcessSnap, &te32) // get the thread priority HANDLE hThread; hThread = OpenThread(THREAD_SET_INFORMATION|THREAD_QUERY_INFORMATI +ON, FALSE, te32.th32ThreadID); // set new priority class if (SetThreadPriority(hThread, threadPriority) != TRUE) { cerr << "SetThreadPriority() "; printError(); } CloseHandle(hThread);
580 output, presumably an open handle to the snapshot$pid = 952; # 952 is a running job pid use threads; use threads::shared; use Win32::API; Win32::API->Import( 'Kernel32', q[ DWORD GetLastError( ) ] ); Win32::API->Import( 'Kernel32', q[ HANDLE CreateToolhelp32Snapshot( DWORD dwFlags, DWORD th32Pr +ocessID ) ] ); $hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, $pid); + print "hProcessSnap = $hProcessSnap \n";
WARNING Unknown parameter type THREADENTRY32 ??Win32::API->Import( 'Kernel32', q[ BOOL Thread32First( HANDLE hSnapshot, THREADENTRY32 lpte)] ); $retcode = GetLastError(); print "import threadfirst error was $retcode \n";
error code 24 is output, indicating incorrect command length.# typedef for THREADENTRY32 typedef Win32::API::Struct AA => qw{ DWORD dwSize; DWORD cntUsage; DWORD th32ThreadID; DWORD th32OwnerProcessID; LONG tpBasePri; LONG tpDeltaPri; DWORD dwFlags; }; my $Point = Win32::API::Struct->new( AA ); $Point->{dwSize} = 24; ##$size=Win32::API::Struct->sizeof(AA); ##always returns 0. ?? Thread32First($hProcessSnap, LPAA); $retcode = GetLastError(); print "threadfirst error was $retcode \n";
But I'm stuck at Thread32FirstWin32::API->Import( 'Kernel32', q[HANDLE OpenThread( DWORD dwDesiredAc +cess, BOOL bInheritHandle, DWORD dwThreadId) ] ); $hThread = OpenThread(THREAD_SET_INFORMATION|THREAD_QUERY_INFORMATION, FALSE, $point->{th32ThreadID}); Win32::API->Import( 'Kernel32', q[ BOOL SetThreadPriority( HANDLE hThr +ead, int nPriority ) ] ); SetThreadPriority( hThread, $threadpriority );
In reply to Re^10: how to change process & thread priority on Win32 ?
by rbutcher
in thread how to change process & thread priority on Win32 ?
by rbutcher
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |