Autor Tema: [HELP] Type Declares  (Leído 2433 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Cudder

  • Bytes
  • *
  • Mensajes: 26
  • Reputación: +0/-1
    • Ver Perfil
[HELP] Type Declares
« en: Junio 24, 2012, 01:35:42 pm »
Hey guys, I'm trying to remove type declares on that code but I didn't success.

Here is the code:

Código: [Seleccionar]
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, th32ProcessID As Long) As Long

Public Type PROCESSENTRY32
    dwSize As Long
    cntUseage As Long
    th32ProcessID As Long
    th32DefaultHeapID As Long
    th32ModuleID As Long
    cntThreads As Long
    th32ParentProcessID As Long
    pcPriClassBase As Long
    swFlags As Long
    szExeFile As String * 1024
End Type

Public Function Running(ByVal sFileName As String) As Boolean
    Dim hSnapshot As Long
    Dim pe32 As PROCESSENTRY32
   
    hSnapshot = CreateToolhelp32Snapshot(2, 0)
    pe32.dwSize = Len(pe32)
    Process32First hSnapshot, pe32
   
    Do While Process32Next(hSnapshot, pe32) <> 0
        If InStr(1, LCase(pe32.szExeFile), LCase(sFileName)) > 0 Then
            Running = True
        End If
    Loop
   
    CloseHandle (hSnapshot)
End Function

Would be really appreciated if anyone could remove the type declare and let me know how you did it.

Thanks!

Cudder

  • Bytes
  • *
  • Mensajes: 26
  • Reputación: +0/-1
    • Ver Perfil
Re:[HELP] Type Declares
« Respuesta #1 en: Junio 24, 2012, 04:24:44 pm »
I've tried:

Código: [Seleccionar]
Public Function IsProcessRunning(ByVal sFileName As String) As Boolean
    Dim hSnapshot As Long
    Dim bPE32(1024 + 36 - 1) As Byte
    Dim bExe(1023) As Byte
   
    hSnapshot = CreateToolhelp32Snapshot(2, 0)
    sMoveMem VarPtr(bPE32(0)), VarPtr(CLng(UBound(bPE32))), 4
    Process32First hSnapshot, VarPtr(bPE32(0))
   
    Do While Process32Next(hSnapshot, VarPtr(bPE32(0))) <> 0
        sMoveMem VarPtr(bExe(0)), VarPtr(bPE32(36)), 1024
        If InStr(1, LCase(StrConv(bExe, vbUnicode)), LCase(sFileName)) > 0 Then
            IsProcessRunning = True
        End If
    Loop
   
    CloseHandle (hSnapshot)
End Function

But this is buggy, it doesnt work correctly...

LeandroA

  • Administrador
  • Petabyte
  • *****
  • Mensajes: 1128
  • Reputación: +151/-8
    • Ver Perfil
Re:[HELP] Type Declares
« Respuesta #2 en: Junio 25, 2012, 02:50:32 am »
Hi
Código: (vb) [Seleccionar]
Option Explicit
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, uProcess As Any) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, uProcess As Any) As Long
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, th32ProcessID As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Public Function Running(ByVal sFileName As String) As Boolean
    Dim hSnapshot As Long
    Dim s As String * 1024
    Dim b(1059) As Byte

    CopyMemory b(0), 1060&, 4
    hSnapshot = CreateToolhelp32Snapshot(2, 0)

    Process32First hSnapshot, b(0) 'bpe32
   
    Do While Process32Next(hSnapshot, b(0)) <> 0
        CopyMemory ByVal s, b(36), 1024
   
        'Debug.Print Left$(s, InStr(s, Chr(0)))
       
        If InStr(1, LCase(s), LCase(sFileName)) > 0 Then
            Running = True: Exit Do
        End If
    Loop
   
    CloseHandle (hSnapshot)
End Function

Cudder

  • Bytes
  • *
  • Mensajes: 26
  • Reputación: +0/-1
    • Ver Perfil
Re:[HELP] Type Declares
« Respuesta #3 en: Junio 25, 2012, 11:07:27 am »
Hi
Código: (vb) [Seleccionar]
Option Explicit
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, uProcess As Any) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, uProcess As Any) As Long
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, th32ProcessID As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Public Function Running(ByVal sFileName As String) As Boolean
    Dim hSnapshot As Long
    Dim s As String * 1024
    Dim b(1059) As Byte

    CopyMemory b(0), 1060&, 4
    hSnapshot = CreateToolhelp32Snapshot(2, 0)

    Process32First hSnapshot, b(0) 'bpe32
   
    Do While Process32Next(hSnapshot, b(0)) <> 0
        CopyMemory ByVal s, b(36), 1024
   
        'Debug.Print Left$(s, InStr(s, Chr(0)))
       
        If InStr(1, LCase(s), LCase(sFileName)) > 0 Then
            Running = True: Exit Do
        End If
    Loop
   
    CloseHandle (hSnapshot)
End Function

Thanks a lot BOSSS! I hope to see new projects from you cause honestly you are a really good vb coder. If you are doing custom coding, please get in touch with me :)

Cudder

  • Bytes
  • *
  • Mensajes: 26
  • Reputación: +0/-1
    • Ver Perfil
Re:[HELP] Type Declares
« Respuesta #4 en: Junio 25, 2012, 07:17:52 pm »
Can you help Invoking this line please?

Código: [Seleccionar]
CopyMemory ByVal s, b(36), 1024
I tried:

Código: [Seleccionar]
Call Invoke("kernel32", "RtlMoveMemory", VarPtr(s), VarPtr(b(36)), 1024)
But it doesnt work, I tried StrPtr doesnt work too...

Thanks


Cudder

  • Bytes
  • *
  • Mensajes: 26
  • Reputación: +0/-1
    • Ver Perfil
Re:[HELP] Type Declares
« Respuesta #5 en: Junio 25, 2012, 07:43:11 pm »
Solved!

Código: (vb) [Seleccionar]
Dim bArr(1024) As Byte
Call Invoke("kernel32", "RtlMoveMemory", VarPtr(bArr(0)), VarPtr(b(36)), 1024)
s = StrConv(bArr, vbUnicode)