AutoHotkey Community

It is currently May 27th, 2012, 5:30 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: March 11th, 2010, 3:43 pm 
Offline

Joined: December 7th, 2005, 8:29 am
Posts: 345
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2010, 4:58 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
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 FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 7:46 am 
Offline

Joined: December 7th, 2005, 8:29 am
Posts: 345
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... :oops:

Maybe lexikos can help.

_________________
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: dra, HotkeyStick, rbrtryn, Yahoo [Bot] and 68 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group