The original concept Application Execution Error (R0015)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
The Application terminated.
Error: Error calling external function CreateToolhelp32Snapshot; ANSI at line 12 in the function of_getexe of object uf_get_exename.
Using unified method of pb treatment process online, it is an error, forget each great god,
Attached to the main code:
///////////////////////////of_getexe (String as_exename)////////////////////////
//function: the enumeration process and returns the specified process PID
no.//incoming: String as_exename filename
//return: Long
/////////////////////////////////////////////////////////////
S_Process lst_Process
String ls_filename [100], ls_curexename
Ulong ln_ProcessID ln_SameCount, ln_Snapshot ln_Circle, ln_Count, ul_PID
Ul_PID=0
ln_Snapshot=CreateToolhelp32Snapshot (2, 0)
If (ln_Snapshot & lt; 1) then return 0//failed to create the snapshot
Lst_Process. StructSize=296//failed to create the snapshot is decided by the Windows 296
If Process32First (ln_Snapshot, lst_Process)=0 then return 0
//the enumeration process under the current permissions
Debugbreak ()
The do while true
If Process32Next (ln_Snapshot, lst_Process)=0 then the exit
Ln_Count=ln_Count + 1
Ls_FileName [ln_Count]=lst_Process. FileName
If the Lower (ls_FileName [ln_Count])=as_exename Then
No.//process
Ul_PID=lst_Process. ProcessID
//messagebox (string (ul_PID), ls_FileName [ln_Count])
End the If
Loop
Return ul_PID
CodePudding user response:
Give you the code, you consultAPI declaration
The Function Long GetCurrentProcessId () Library "kernel32. DLL
"The Function Long CreateToolhelp32Snapshot (Long Flags, Long ProcessId) Library "kernel32. DLL
"The Function Integer Process32First (uLong Snapshot, ref s_Process Process) Library "kernel32. DLL" alias for "Process32First; Ansi
"The Function Integer Process32Next (uLong Snapshot, ref s_Process Process) Library "kernel32. DLL" alias for "Process32Next; Ansi
"The FUNCTION ulong GetWindowThreadProcessId (ulong HWND, ref ulong lpdwProcessId) LIBRARY "user32. DLL
"The FUNCTION ulong GetWindowText (ulong HWND, ref string lpString, ulong CCH) LIBRARY "user32. DLL" ALIAS FOR "GetWindowTextA; Ansi
"
The code
S_Process lst_Process/structure/process
String ls_FileName [], ls_CurExeName//up to 100 process, can improve
String ls_win_txt
Ulong ln_ProcessID ln_SameCount, ln_Snapshot
Ulong ln_Circle, ln_Count
Ulong ll_new, ll_handle
Ln_ProcessID=GetCurrentProcessId ()//in the current process ID
If IsNull (ln_ProcessID) or ln_ProcessID & lt; 1 then
//return - 1 error is returned
End the if
Ln_Snapshot=CreateToolhelp32Snapshot (2, 0)//on the heap snapshot creation process
If (ln_Snapshot & lt; 1) then
//return - 1 error is returned
End the if
Lst_Process. StructSize=296//Win32api Process structure size
Ln_SameCount=0//the copy number of 0
If Process32First (ln_Snapshot, lst_Process)=0 then
Return 1//to take the first process failure returns
End the if
Ln_Count=1
Ls_FileName [ln_Count]=lst_Process. The process name listed in the FileName//into the array
//such as the list to process ID is equal to the current process ID, know the name of the current process, save
If lst_Process. ProcessID=ln_ProcessID then
Ls_CurExeName=lst_Process. FileName
End the if
Ls_win_txt=space (200)
The do while true//cycle process name list, into the array
If Process32Next (ln_Snapshot, lst_Process)=0 then
The exit//finished list
End the if
Ln_Count=ln_Count + 1
Ls_FileName [ln_Count]=lst_Process. FileName
If lst_Process. ProcessID=ln_ProcessID then
Ls_CurExeName=lst_Process. FileName
End the if
Ll_new=dw_main. Insertrow (0)
Dw_main. Setitem (ll_new, "process_no", lst_Process processid)
Dw_main. Setitem (ll_new, "process_file", ls_filename [ln_count])
If GetWindowThreadProcessId (lst_Process processid, ll_handle) & gt; 0 then
GetWindowText ll_handle ls_win_txt, (255)
Dw_main. Setitem (ll_new, "process_handle", ll_handle)
Dw_main. Setitem (ll_new, "process_nam", ls_win_txt)
End the if
Loop
Comes out on the data window, you consult
The above code in the pb10 debugging through
CodePudding user response:
The landlord to get the PB is version 9, see code found uf_get_exename should be used PB10 above, and because the API statement using the ANSI.PB9 the API declaration is not to need to ANSI, remove try again,