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