Jump to content
Sign in to follow this  
mikkokh

How to get rest of chars from memory?

Recommended Posts

mikkokh

Hi.

Script should return full title of current song from Winamp player, but it seems return only first char of it... How I should change it to get all work?

#include <SendMessage.au3>
#include "NomadMemory.au3"

Opt("WinTitleMatchMode", 4)

Const $WinAmpClass = "classname=Winamp v1.x"
Const $WM_USER = 1024
Const $IPC_GET_PLAYING_TITLE = 3034

$hwnd_winamp = WinGetHandle ($WinAmpClass)
If @error Then
    ConsoleWrite("Fail to get Winamp Handle!" & @CRLF)
    Exit
EndIf

Local $memAddress = _SendMessage($hwnd_winamp, $WM_USER, 0, $IPC_GET_PLAYING_TITLE)
If Not @error Then
    $memHandle = _MemoryOpen(ProcessExists("winamp.exe"))
    If @Error Then _
        Exit
    
    Local $title = _MemoryRead($memAddress, $memHandle, "char[16]")
    
    ConsoleWrite($title & @CRLF)
    
    _MemoryClose($memHandle)
EndIf

Notice: This script needs NomadMemory.au3 UDF file, and it should be in same folder with script.


- miXza-81 -

Share this post


Link to post
Share on other sites
mikkokh

Thanks. It works.

Edit:

Winamp UDF uses quite long SendMessage method (2 SendMessage commands for get correct title position from application memory) to get same string that $IPC_GET_PLAYING_TITLE gives only with one SendMessage command. I think it is problem with my time critical script when my system CPU has more load. My script is synced to sleep max 250ms with TimerInit, TimerDiff and sleep functions - It smoth progress when execute time of part of code changes.

If someone could help me to get this version work, I would be realy thankful and I would also learn new and intresting tricks about programming. Also, I think that if I would use $IPC_GET_PLAYING_TITLE to get memory address of title, that same memory address would work as long as WinAmp is running continuous... Or, are I'm wrong about it?

Edit 2:

This code seems to work like it should, but it need some more testing. It's maked by me with "mistake, error and success" method...

#include <SendMessage.au3>
#include <WinAPI.au3>
#include "NomadMemory.au3"

Opt("WinTitleMatchMode", 4)
Opt("MustDeclareVars", 1)

Const $WinAmpClass = "classname=Winamp v1.x"
Const $WM_USER = 1024
Const $IPC_GET_PLAYING_TITLE = 3034

_main()


Func _main()

   Local $hwnd_winamp, $pid_winamp, $memHandle, $memAddress, $chrCode, $error
   Local $title = ""
   
   $hwnd_winamp = WinGetHandle($WinAmpClass)
   If @error Then
      ConsoleWrite("Fail to get Handle of Winamp!" & @CRLF)
      Exit
   EndIf
   
   If (_WinAPI_GetWindowThreadProcessId($hwnd_winamp, $pid_winamp) = 0) Then
      ConsoleWrite("Fail to get PID of Winamp!" & @CRLF)
      Exit
   EndIf
   
   $memAddress = _SendMessage($hwnd_winamp, $WM_USER, 0, $IPC_GET_PLAYING_TITLE)
   If @error Then
      ConsoleWrite("Fail to SendMessage!" & @CRLF)
      Exit
   EndIf
   
   $memHandle = _MemoryOpen($pid_winamp)
   $error = @error
   If $error Then
      ConsoleWrite("Fail to Open Memory!  [Code:" & $error & "]" & @CRLF)
      Exit
   EndIf
   
   While True
      $chrCode = _MemoryRead($memAddress, $memHandle, "word")
      $error = @error
      If $error Then
         ConsoleWrite("Fail to Read Memory!  [Code" & $error & "]" & @CRLF)
         ExitLoop
      EndIf
      
      If ($chrCode = 0) Then _
         ExitLoop
      
      $title &= Chr($chrCode)
      $memAddress += 1
   WEnd
   
   ConsoleWrite($title & @CRLF)
   
   If Not _MemoryClose($memHandle) Then _
      ConsoleWrite("Fail to Close Memory!  [Code" & @error & "]" & @CRLF)

EndFunc
Edited by mikkokh

- miXza-81 -

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×