DroopyLib
Re: DroopyLib
Excellent Droopy.
Thanks for your great work.
Thanks for your great work.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Re: DroopyLib
Hi Droopy,
I've found a problem in the Week (date.l) routine.
If I input the date 2013,1,1,0,0,0 then the result is week 0.
So I started looking for a solution and found it in a newly created page on the Dutch wikipedia (weeknummer).
This example, I converted to PureBasic. Note that this only applies to European calendar weeks, the Japanese and American calendars work differently.
I think this is useful for your library.
Greetings,
Roel.
I've found a problem in the Week (date.l) routine.
If I input the date 2013,1,1,0,0,0 then the result is week 0.
So I started looking for a solution and found it in a newly created page on the Dutch wikipedia (weeknummer).
This example, I converted to PureBasic. Note that this only applies to European calendar weeks, the Japanese and American calendars work differently.
Code: Select all
Procedure My_Week(date.l)
var_year = Year(date)
var_month = Month(date)
var_day = Day(date)
UK01 = DayOfYear(Date(var_year, var_month, var_day, 0, 0, 0)) - 4
UK02.i = UK01/7
UK03 = DayOfWeek(Date(var_year, var_month, var_day, 0, 0, 0))
If UK03 = 0
UK03 = 7
EndIf
UK04 = DayOfWeek(Date(var_year-1, 1, 4, 0, 0, 0))
If UK04 = 0
UK04 = 7
EndIf
UK05 = DayOfYear(Date(var_year-1, 12, 31, 0, 0, 0)) - 4
UK06.i = UK05/7
UK07 = DayOfWeek(Date(var_year-1, 12, 31, 0, 0, 0))
If UK07 = 0
UK07 = 7
EndIf
UK08 = DayOfWeek(Date(var_year, 1, 4, 0, 0, 0))
If UK08 = 0
UK08 = 7
EndIf
UK09 = DayOfWeek(Date(var_year+1, 1, 4, 0, 0, 0))
If UK09 = 0
UK09 = 7
EndIf
If UK07 < UK08
UK10 = 1
ElseIf UK07 < UK04
UK10 = UK06 + 2
Else
UK10 = UK06 + 1
EndIf
If var_day < 4 And var_month = 1
If UK03 < UK08
UK11=1
Else
UK11=UK10
EndIf
ElseIf var_day > 28 And UK03 < UK09
UK11 = 1
ElseIf UK03 < UK08
UK11 = UK02 + 2
Else
UK11=UK02+1
EndIf
ProcedureReturn UK11
EndProcedure
Greetings,
Roel.
Re: DroopyLib
Calendarweek ? I use some "old" code from german forum and it works perfect...
http://purebasic.fr/german/viewtopic.php?p=71675#p71675
http://purebasic.fr/german/viewtopic.php?p=71675#p71675
Re: DroopyLib
Is there any problems with the process commands and PB 5.11.
Can't get them to work
Regards
Sveinung
Can't get them to work

Regards
Sveinung
Re: DroopyLib
Why not just update PB, Sveinung?
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Re: DroopyLib
Pretty sure 5.11 is the lates release ??GeoTrail wrote:Why not just update PB, Sveinung?
GetPidProcess
KillProcess
SearchProcess
RunOnlyOneInstance
HandleToFileName
PidToFileName
WaitProgramInitialisation
These are the cpmmands I can't get to work.
Sveinung
Re: DroopyLib
I have tested GetPidProcessSveinung wrote:Pretty sure 5.11 is the lates release ??GeoTrail wrote:Why not just update PB, Sveinung?
GetPidProcess
KillProcess
SearchProcess
RunOnlyOneInstance
HandleToFileName
PidToFileName
WaitProgramInitialisation
These are the cpmmands I can't get to work.
Sveinung
KillProcess
SearchProcess
RunOnlyOneInstance
with pb 5.11 and working ok

Re: DroopyLib
@le_magn
I have tested on win8 x64 and win 7sp1 x64....same result, getpidprocess always returns 0.
Sveinung
I have tested on win8 x64 and win 7sp1 x64....same result, getpidprocess always returns 0.
Sveinung
Re: DroopyLib
Maybe you try to get a PID of a x64 program within the PBx86 ?
Re: DroopyLib
Stupid me! Forgot to mention that it was compiling to X64. SORRY!!Bisonte wrote:Maybe you try to get a PID of a x64 program within the PBx86 ?



*Bow head in shame*
I can get the pid from any process compiling to x86 but not x64. In x86 mode I can get the pid of both 32 and 64 bits Applications.
So it seems to be the x64 mode that is the problem.
Sveinung
Re: DroopyLib
With this, you don't need OpenLibrary()... x86 and x64, proved in an tailbite-userlibrary and its case insensitive if you want 

Code: Select all
Procedure GetPID(Name$, Mode = 0) ; Returns the ProcessID the tasks Name$ or 0 ( Mode = #True : Case Insensitiv)
Protected Process.PROCESSENTRY32
Protected ProcSnap
ProcSnap = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS, 0)
If ProcSnap <> 0
Process\dwsize=SizeOf(Process)
Process32First_(ProcSnap, Process)
While Process32Next_(ProcSnap, Process) > 0
If Mode <> 0
If UCase(PeekS(@Process\szExeFile)) = UCase(Name$)
ProcedureReturn Process\th32ProcessID
Break
EndIf
Else
If PeekS(@Process\szExeFile) = Name$
ProcedureReturn Process\th32ProcessID
Break
EndIf
EndIf
Wend
EndIf
EndProcedure
Re: DroopyLib
Hi,
oops Bisonte was faster...
but this example here works a little bit different.
Droopy can change this as necessary on the DroopyLib.
Here some Process Procedure that works on Win2k and Higher x86/x64 Ascii and Unicode
the only different is on the GetPIDProcess Procedure
the orig droopy this found only the first entry, this one is more similar as the Searchprocess but return the pid (list) of all found matches
oops Bisonte was faster...

but this example here works a little bit different.
Droopy can change this as necessary on the DroopyLib.
Here some Process Procedure that works on Win2k and Higher x86/x64 Ascii and Unicode
the only different is on the GetPIDProcess Procedure
the orig droopy this found only the first entry, this one is more similar as the Searchprocess but return the pid (list) of all found matches
Code: Select all
Prototype ProcessFirst(Snapshot, Process)
Prototype ProcessNext(Snapshot, Process)
Global ProcessFirst.ProcessFirst
Global ProcessNext.ProcessNext
Global NewList PID()
Prototype GetModuleFileNameEx(hProcess,dwFlags, lpExeName, lpdwSize)
Global GetModuleFileNameEx.GetModuleFileNameEx
Prototype GetProcessImageFileName(hProcess, lpImageFileName, nSize)
Global GetProcessImageFileName.GetProcessImageFileName
Prototype QueryFullProcessImageName(hProcess, dwFlags, lpExeName, lpdwSize)
Global QueryFullProcessImageName.QueryFullProcessImageName
Declare.s PidToFileName(PID)
ProcedureDLL.s HandleToFileName(hWnd.l) ; Returns the file Path and Name of the exe that owns the specified Window Handle
Protected Name.s=""
;// Handle can be found with WindowsEnum()
Pid.l=0
GetWindowThreadProcessId_( hWnd, @Pid )
Name.s=PidToFileName(Pid)
ProcedureReturn Name
EndProcedure
Procedure.s JunctiontoPathname(junction.s)
Protected *Buffer,i,C,nr
Protected Drives.s,Drive.s,DosDeviceName.s,LogicalName.s
If FindString(junction,"Device\LanmanRedirector",1)
LogicalName=RemoveString(junction,"Device\LanmanRedirector")
ProcedureReturn LogicalName
EndIf
*Buffer = AllocateMemory(#MAX_PATH*SizeOf(character))
For i = 0 To GetLogicalDriveStrings_(#MAX_PATH*SizeOf(character), *Buffer)
C = PeekB(*Buffer +i)
If C <> 0
drives.s = UCase(drives) + Chr(C)
EndIf
Next
DosDeviceName = Space(#MAX_PATH*SizeOf(character))
nr=CountString(drives,"\")
For x=1 To nr
drive.s=StringField(drives,x,"\")
QueryDosDevice_(drive, @DosDeviceName, #MAX_PATH*SizeOf(character))
If FindString(junction,DosDeviceName,1)
LogicalName=ReplaceString(junction, DosDeviceName, Drive)
Break
EndIf
Next
ProcedureReturn LogicalName
EndProcedure
Procedure.s PidToFileName(PID)
Protected hProcess
Protected libID
Protected lpdwSize
Protected PathFileName.s = ""
Protected DosDeviceName.s
If OSVersion() => #PB_OS_Windows_Vista
libID = OpenLibrary(#PB_Any, "kernel32.dll")
ElseIf OSVersion() => #PB_OS_Windows_2000 Or OSVersion() < #PB_OS_Windows_Vista
libID = OpenLibrary(#PB_Any, "psapi.dll")
EndIf
CompilerIf #PB_Compiler_Unicode
If OSVersion() = #PB_OS_Windows_2000
GetModuleFileNameEx=GetFunction(libID,"GetModuleFileNameExW")
ElseIf OSVersion() = #PB_OS_Windows_XP Or OSVersion() = #PB_OS_Windows_Server_2003
GetProcessImageFileName = GetFunction(libID, "GetProcessImageFileNameW")
ElseIf OSVersion() => #PB_OS_Windows_Vista
QueryFullProcessImageName = GetFunction(libID, "QueryFullProcessImageNameW")
EndIf
CompilerElse
If OSVersion() = #PB_OS_Windows_2000
GetModuleFileNameEx=GetFunction(libID,"GetModuleFileNameExA")
ElseIf OSVersion() = #PB_OS_Windows_XP Or OSVersion() = #PB_OS_Windows_Server_2003
GetProcessImageFileName = GetFunction(libID, "GetProcessImageFileNameA")
ElseIf OSVersion() => #PB_OS_Windows_Vista
QueryFullProcessImageName = GetFunction(libID, "QueryFullProcessImageNameA")
EndIf
CompilerEndIf
If GetModuleFileNameEx <> 0 Or GetProcessImageFileName <> 0 Or QueryFullProcessImageName <>0
If OSVersion() = #PB_OS_Windows_2000
hProcess = OpenProcess_( #PROCESS_QUERY_INFORMATION | #PROCESS_VM_READ, 0, PID );
ElseIf OSVersion() = > #PB_OS_Windows_XP
hProcess = OpenProcess_(#PROCESS_QUERY_INFORMATION, 0, PID)
EndIf
If hProcess
PathFileName = Space(#MAX_PATH*4)
lpdwSize=#MAX_PATH*4
If OSVersion() = #PB_OS_Windows_2000
GetModuleFileNameEx(hProcess,0,@PathFileName,@lpdwSize )
ElseIf OSVersion() = #PB_OS_Windows_XP Or OSVersion() = #PB_OS_Windows_Server_2003
GetProcessImageFileName(hProcess, @PathFileName, #MAX_PATH)
PathFileName=JunctiontoPathname(PathFileName)
ElseIf OSVersion() => #PB_OS_Windows_Vista
QueryFullProcessImageName(hProcess, DosDevice, @PathFileName, @lpdwSize)
EndIf
CloseHandle_(hProcess)
EndIf
CloseLibrary(libID)
EndIf
ProcedureReturn PathFileName
EndProcedure
;{/*
; MessageRequester("PID Process to Filename","Explorer.exe"+" --> "+PidToFileName(GetPidProcess("Explorer.exe")))
;}
ProcedureDLL GetHandle(WindowsName.s)
retour= FindWindow_(0, WindowsName)
ProcedureReturn retour
EndProcedure
Procedure.b GetPIDProcess(Name.s)
Protected ProcLib
Protected ProcName.s
Protected Process.PROCESSENTRY32
Protected x
Protected RetVal=#False
Name=UCase(Name.s)
ProcLib= OpenLibrary(#PB_Any, "Kernel32.dll")
If ProcLib
CompilerIf #PB_Compiler_Unicode
ProcessFirst = GetFunction(ProcLib, "Process32FirstW")
ProcessNext = GetFunction(ProcLib, "Process32NextW")
CompilerElse
ProcessFirst = GetFunction(ProcLib, "Process32First")
ProcessNext = GetFunction(ProcLib, "Process32Next")
CompilerEndIf
If ProcessFirst And ProcessNext
Process\dwSize = SizeOf(PROCESSENTRY32)
Snapshot =CreateToolhelp32Snapshot_(#TH32CS_SNAPALL,0)
If Snapshot
ProcessFound = ProcessFirst(Snapshot, Process)
x=1
While ProcessFound
ProcName=PeekS(@Process\szExeFile)
ProcName=GetFilePart(ProcName)
If UCase(ProcName)=UCase(Name)
AddElement(PID())
PID()=Process\th32ProcessID
RetVal=#True
EndIf
ProcessFound = ProcessNext(Snapshot, Process)
x=x+1
Wend
EndIf
CloseHandle_(Snapshot)
EndIf
CloseLibrary(ProcLib)
EndIf
ProcedureReturn RetVal
EndProcedure
ret=GetPidProcess("purebasic.exe")
If ret
ForEach PID()
Debug PID()
Next
EndIf
hWin=GetHandle("Unbenannt - Editor")
If hWin
Debug HandleToFileName(hWin)
EndIf
PB 5.10 Windows 7 x64 SP1
Re: DroopyLib
Hello,
New version avalaible :
@Bisonte and jpd : Thanks a lot wink:
Week() bug will be fixed in the next release.
Regards
New version avalaible :
@Sveinung : RunOnlyOneInstance/KillProcess : no bug found23/05/13 : Library 5.11.001
Compiled with PB 5.11 / TB 1.4.9
WaitProgramInitialisation() Bug fixed
SearchProcess() Function rewritten
PidToFileName() Function rewritten
HandleToFileName() Function rewritten
GetPidProcess() Function rewritten
GetPidProcessEx() Function added
@Bisonte and jpd : Thanks a lot wink:
Week() bug will be fixed in the next release.
Regards
Re: DroopyLib
Thank you Droppy!
Sveinung

Sveinung