Page 9 of 13

Re: DroopyLib

Posted: Sat Dec 01, 2012 9:45 pm
by GeoTrail
Excellent Droopy.
Thanks for your great work.

Re: DroopyLib

Posted: Sat Jan 12, 2013 1:34 am
by rule
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.

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
I think this is useful for your library.

Greetings,
Roel.

Re: DroopyLib

Posted: Sat Jan 12, 2013 11:12 am
by Bisonte
Calendarweek ? I use some "old" code from german forum and it works perfect...

http://purebasic.fr/german/viewtopic.php?p=71675#p71675

Re: DroopyLib

Posted: Sun May 19, 2013 9:45 pm
by Sveinung
Is there any problems with the process commands and PB 5.11.
Can't get them to work :(

Regards
Sveinung

Re: DroopyLib

Posted: Mon May 20, 2013 1:22 am
by GeoTrail
Why not just update PB, Sveinung?

Re: DroopyLib

Posted: Mon May 20, 2013 12:05 pm
by Sveinung
GeoTrail wrote:Why not just update PB, Sveinung?
Pretty sure 5.11 is the lates release ??

GetPidProcess
KillProcess
SearchProcess
RunOnlyOneInstance
HandleToFileName
PidToFileName
WaitProgramInitialisation

These are the cpmmands I can't get to work.

Sveinung

Re: DroopyLib

Posted: Mon May 20, 2013 7:46 pm
by le_magn
Sveinung wrote:
GeoTrail wrote:Why not just update PB, Sveinung?
Pretty sure 5.11 is the lates release ??

GetPidProcess
KillProcess
SearchProcess
RunOnlyOneInstance
HandleToFileName
PidToFileName
WaitProgramInitialisation

These are the cpmmands I can't get to work.

Sveinung
I have tested GetPidProcess
KillProcess
SearchProcess
RunOnlyOneInstance

with pb 5.11 and working ok

Re: DroopyLib

Posted: Tue May 21, 2013 10:42 am
by Sveinung
@le_magn

I have tested on win8 x64 and win 7sp1 x64....same result, getpidprocess always returns 0.

Sveinung

Re: DroopyLib

Posted: Tue May 21, 2013 11:08 am
by Bisonte
Maybe you try to get a PID of a x64 program within the PBx86 ?

Re: DroopyLib

Posted: Tue May 21, 2013 12:21 pm
by Sveinung
Bisonte wrote:Maybe you try to get a PID of a x64 program within the PBx86 ?
Stupid me! Forgot to mention that it was compiling to X64. SORRY!! :oops: :oops: :oops:
*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

Posted: Wed May 22, 2013 8:06 pm
by Droopy
i'm looking for these bugs

Re: DroopyLib

Posted: Wed May 22, 2013 10:38 pm
by Bisonte
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

Posted: Thu May 23, 2013 7:27 am
by jpd
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

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



Re: DroopyLib

Posted: Thu May 23, 2013 10:08 pm
by Droopy
Hello,

New version avalaible :
23/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
@Sveinung : RunOnlyOneInstance/KillProcess : no bug found
@Bisonte and jpd : Thanks a lot wink:

Week() bug will be fixed in the next release.

Regards

Re: DroopyLib

Posted: Fri May 24, 2013 8:04 am
by Sveinung
Thank you Droppy! :D

Sveinung