AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

AHK_L - Mediainfo.dll extract data from pointer

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
twhyman



Joined: 07 Dec 2005
Posts: 339

PostPosted: Thu Mar 11, 2010 2:43 pm    Post subject: AHK_L - Mediainfo.dll extract data from pointer Reply with quote

Hi,

I am trying to convert the mediainfo.dll script to work with the latest AHK_L
Unicode build.

Code:

;use your own paths here
PathToMediaInfoDLL := A_ScriptDir . "\MediaInfo.dll"
PathToAVIFile :=  A_ScriptDir . "\hd_dts_sfx_short_lossless.m2ts"

hModule := DllCall("LoadLibrary", "str", PathToMediaInfoDLL)  ; Avoids the need for subsequent DllCalls to load the library
VarSetCapacity(Info_Parameters, 30000) ;prepare to hold large data


handle := dllcall("mediainfo\MediaInfo_New") ;initialize mediainfo

resultopenfile := dllcall("mediainfo\MediaInfo_Open", "UInt", handle, "str", PathToAVIFile) ;open the file
msgbox errorlevel %errorlevel%, resultopenfile %resultopenfile% ;if resultopenfile=1 -> success

;some examples


;Inform with Complete=false
DllCall("mediainfo\MediaInfo_Option", "UInt", 0, "str", "Complete", "str", "") ;set the last "" to "1" for complete=true
capac:=VarSetCapacity(inform, 30000)
inform := dllcall("mediainfo\MediaInfo_Inform", "UInt", handle, "int", 0) ;we use unicode version of the function
informANSI := ExtractData(inform) ;translate unicode to ansi
msgbox errorlevel %errorlevel%, inform:`n`n%informANSI%



VideoContainer_ptr:=DllCall("mediainfo\MediaInfo_Get", "UInt", handle, "int", 0, "int", 0, "str", "Format", "int", 1, "int", 0)
VideoContainer := extractdata(VideoContainer_ptr)
msgbox, Container: %VideoContainer%`n%VideoContainer2%
Exitapp

/*
VideoCodec_ptr:=DllCall("mediainfo\MediaInfoA_Get", "UInt", handle, "int", 1, "int", 0, "str", "Format", "int", 1, "int", 0)
VideoCodec := extractdata(VideoCodec_ptr)
msgbox, Video Codec: %VideoCodec%

VideoAspectRatio_ptr:=DllCall("mediainfo\MediaInfoA_Get", "UInt", handle, "int", 1, "int", 0, "str", "DisplayAspectRatio/String", "int", 1, "int", 0)
VideoAspectRatio := extractdata(VideoAspectRatio_ptr)
msgbox, Video Aspect Ratio: %VideoAspectRatio%

AudioFormat_ptr:=DllCall("mediainfo\MediaInfoA_Get", "UInt", handle, "int", 2, "int", 0, "str", "Format", "int", 1, "int", 0)
AudioFormat := extractdata(AudioFormat_ptr)
msgbox, Audio Format: %AudioFormat%

AudioCodec_ptr:=DllCall("mediainfo\MediaInfoA_Get", "UInt", handle, "int", 2, "int", 0, "str", "Codec", "int", 1, "int", 0)
AudioCodec := extractdata(AudioCodec_ptr)
msgbox, Audio Codec: %AudioCodec%

Subtitles_LNG_ptr:=DllCall("mediainfo\MediaInfoA_Get", "UInt", handle, "int", 3, "int", 0, "str", "Language/String", "int", 1, "int", 0)
Subtitles_LNG := extractdata(Subtitles_LNG_ptr)
msgbox, Subtitles Language: %Subtitles_LNG%
*/



handle := DllCall("mediainfo\MediaInfo_Delete", "UInt", handle) ;Delete MediaInfo handle

DllCall("FreeLibrary", "UInt", hModule)  ; To conserve memory, the DLL may be unloaded after using it.


;credits for this function go to PhiLho (http://www.autohotkey.com/forum/topic12460.html)
; Some API functions require a WCHAR string.
GetUnicodeString(ByRef @unicodeString, _ansiString)
{
   local len

   len := StrLen(_ansiString)
   VarSetCapacity(@unicodeString, len * 2 + 1, 0)

   ; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/unicode_17si.asp
   DllCall("MultiByteToWideChar"
         , "UInt", 0             ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
         , "UInt", 0             ; dwFlags
         , "Str", _ansiString    ; LPSTR lpMultiByteStr
         , "Int", len            ; cbMultiByte: -1=null terminated
         , "UInt", &@unicodeString ; LPCWSTR lpWideCharStr
         , "Int", len)           ; cchWideChar: 0 to get required size
}

;credits for this function go to PhiLho (http://www.autohotkey.com/forum/topic12460.html)
; Some API functions return a WCHAR string.
GetAnsiStringFromUnicodePointer(_unicodeStringPt)
{
   local len, ansiString

   len := DllCall("lstrlenW", "UInt", _unicodeStringPt)
   VarSetCapacity(ansiString, len, 0)

   DllCall("WideCharToMultiByte"
         , "UInt", 0           ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
         , "UInt", 0           ; dwFlags
         , "UInt", _unicodeStringPt ; LPCWSTR lpWideCharStr
         , "Int", len          ; cchWideChar: size in WCHAR values, -1=null terminated
         , "Str", ansiString   ; LPSTR lpMultiByteStr
         , "Int", len          ; cbMultiByte: 0 to get required size
         , "UInt", 0           ; LPCSTR lpDefaultChar
         , "UInt", 0)          ; LPBOOL lpUsedDefaultChar

   Return ansiString
}

;credits for this function go to Goyyah (http://www.autohotkey.com/forum/viewtopic.php?p=91578#91578)
ExtractData(pointer) {
Loop {
       errorLevel := ( pointer+(A_Index-1) )
       Asc := *( errorLevel )
       IfEqual, Asc, 0, Break ; Break if NULL Character
       String := String . Chr(Asc)
     }
Return String
}


The first inform function does not work i get an error, and the second one that uses dataextract function I get what seems to be only the first letter of the returned info

Can someone help on this?

Thanks,
Twhyman
_________________
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Thu Mar 11, 2010 3:58 pm    Post subject: Reply with quote

It is probably the "str" bit, look at the AHK_L thread for some pointers on using A_IsUnicode with "str" and DLLCalls. (That's all I know as I don't know anything about DLLCalls but that is what I've seen a few times)
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
twhyman



Joined: 07 Dec 2005
Posts: 339

PostPosted: Fri Mar 12, 2010 6:46 am    Post subject: Reply with quote

Hi,

I know because its unicode you need to double the place for a string,
But I don't know how to do that with pointers... Embarassed

Maybe lexikos can help.
_________________
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group