libmp4v2.dll help

R

roidy

Hi, does anyone have any experience setting up and using libmp4v2.dll from
VB.net 2008. I just carn`t figure out how to declare the correct structures
and varibles in VB.

This page describes the main MP4Tags structure:-
http://mp4v2.googlecode.com/svn/doc/trunk/api/struct_m_p4_tags__s.html

This page describles the api
functions:-http://mp4v2.googlecode.com/svn/doc/trunk/api/group__mp4__meta.html#g71f371b895fe494922900a48383a6a4f

Any help or advice to get me started would be appreciated
 
R

roidy

Ok this is what I`ve come up with so far to try out two of the api calls:-

Public Class Form1
Declare Auto Function MP4GetMetadataName Lib "e:\libmp4v2.dll" (ByVal
filehandle As Integer, ByRef val As IntPtr) As Boolean
Declare Auto Function MP4Read Lib "e:\libmp4v2.dll" (ByVal filename As
String) As Long

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim filehandle As Long
Dim result As Boolean
Dim test As IntPtr

filehandle = MP4Read("e:\test.mp4")
result = MP4GetMetadataName(filehandle, test)
End Sub
End Class

The equivalent c code is as follows:-

char *value;
bool result;
MP4FileHandle mp4file = MP4Read( "e:\test.mp4");
result = MP4GetMetadataName( mp4file, &value );


However I get an "Arithmetic operation resulted in an overflow" exception on
the call to MP4GetMetadataName in the VB version. Anybody know where I`m
going wrong?

Thanks
Rob
 
A

Armin Zingler

roidy said:
Ok this is what I`ve come up with so far to try out two of the api
calls:-
Public Class Form1
Declare Auto Function MP4GetMetadataName Lib "e:\libmp4v2.dll"
(ByVal filehandle As Integer, ByRef val As IntPtr) As Boolean
Declare Auto Function MP4Read Lib "e:\libmp4v2.dll" (ByVal
filename As String) As Long

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim filehandle As Long
Dim result As Boolean
Dim test As IntPtr

filehandle = MP4Read("e:\test.mp4")
result = MP4GetMetadataName(filehandle, test)
End Sub
End Class

The equivalent c code is as follows:-

char *value;
bool result;
MP4FileHandle mp4file = MP4Read( "e:\test.mp4");
result = MP4GetMetadataName( mp4file, &value );


However I get an "Arithmetic operation resulted in an overflow"
exception on the call to MP4GetMetadataName in the VB version.
Anybody know where I`m going wrong?


Yes, you use wrong declarations and you don't use them not correctly. Where
did you get them from?

These are the original declarations:

typedef void* MP4FileHandle;

bool MP4GetMetadataName(MP4FileHandle hFile, char** value);

MP4FileHandle MP4Read(const char* fileName, uint32_t verbosity
DEFAULT(0));


This is just an attempt to find the closest possible declarations:

Declare Auto Function MP4GetMetadataName Lib "e:\libmp4v2.dll"
(ByVal filehandle As IntPtr, ByRef val As IntPtr) As Boolean

Declare Auto Function MP4Read Lib "e:\libmp4v2.dll" (ByVal
filename As String, byval verbosity as UInteger) As IntPtr


Call:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim filehandle As IntPtr
Dim result As Boolean
Dim test As IntPtr
Dim bytes(1023) As Byte

filehandle = MP4Read("e:\test.mp4", ???) '<-- don't know what to pass

Dim gch = Runtime.InteropServices.GCHandle.Alloc(bytes(0))
result = MP4GetMetadataName(filehandle, gch.AddrOfPinnedObject())
gch.Free()

End Sub

Maybe (hopefully) there is another way to translate a char**. You have to
convert the byte array to a String using one of the System.Text.Encoding
objects.


Armin
 
R

roidy

Thanks for the help Armin.

I`ve tried the code you posted but I`m now getting a "Handle is not pinned."
exception on the call to MP4GetMetadataName and the value of filehandle is
always 0. I don`t know the first thing about pinned objects or using dll`s
in VB.

Thanks
Rob
 
A

Armin Zingler

roidy said:
Thanks for the help Armin.

I`ve tried the code you posted but I`m now getting a "Handle is not
pinned." exception on the call to MP4GetMetadataName and the value of
filehandle is always 0. I don`t know the first thing about pinned
objects or using dll`s in VB.

Sry, my fault. Add one parameter to the Alloc function:

Dim gch = Runtime.InteropServices.GCHandle.Alloc( _
bytes(0), _
Runtime.InteropServices.GCHandleType.Pinned _
)

But, I can't test it here so I have not clue if it works.

Armin
 
R

roidy

Thanks that cleared up the "Handle is not pinned exception.". However the
filehandle value from MP4Read still returns 0. This is the VB code I have so
far:-

Public Class Form1
Declare Auto Function MP4GetMetadataName Lib "e:\libmp4v2.dll" _
(ByVal filehandle As IntPtr, ByRef val As IntPtr) As Boolean
Declare Auto Function MP4Read Lib "e:\libmp4v2.dll" _
(ByVal filename As String, ByVal verbosity As UInteger) As
IntPtr

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles MyBase.Load
Dim filehandle As IntPtr
Dim result As Boolean
Dim bytes(1023) As Byte
filehandle = MP4Read("e:/test.mp4", 0)
Dim gch = Runtime.InteropServices.GCHandle.Alloc(bytes(0),
Runtime.InteropServices.GCHandleType.Pinned)
result = MP4GetMetadataName(filehandle, gch.AddrOfPinnedObject())
gch.Free()
End Sub
End Class


This is the same version written in c :-

extern "C" int main(int argc, char** argv)
{
char *value;
MP4FileHandle filehandle= MP4Read( "e:/test.mp4",0 );
MP4GetMetadataName( mp4file, &value );
fprintf( stdout, " Name: %s\n", value );
_getch();
return 0;
}

The c version works perfectly and returns a filehandle value of 0x0035e250
however the VB version always returns a filehandle value of 0 meaning that
the call to MP4Read has failed in some way. Could it be the way I`m passing
the filename string to the MP4Read function in VB?

Rob
 
R

roidy

Managed to get it working Thanks....

Rob



roidy said:
Thanks that cleared up the "Handle is not pinned exception.". However the
filehandle value from MP4Read still returns 0. This is the VB code I have
so far:-

Public Class Form1
Declare Auto Function MP4GetMetadataName Lib "e:\libmp4v2.dll" _
(ByVal filehandle As IntPtr, ByRef val As IntPtr) As
Boolean
Declare Auto Function MP4Read Lib "e:\libmp4v2.dll" _
(ByVal filename As String, ByVal verbosity As UInteger) As
IntPtr

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles MyBase.Load
Dim filehandle As IntPtr
Dim result As Boolean
Dim bytes(1023) As Byte
filehandle = MP4Read("e:/test.mp4", 0)
Dim gch = Runtime.InteropServices.GCHandle.Alloc(bytes(0),
Runtime.InteropServices.GCHandleType.Pinned)
result = MP4GetMetadataName(filehandle, gch.AddrOfPinnedObject())
gch.Free()
End Sub
End Class


This is the same version written in c :-

extern "C" int main(int argc, char** argv)
{
char *value;
MP4FileHandle filehandle= MP4Read( "e:/test.mp4",0 );
MP4GetMetadataName( mp4file, &value );
fprintf( stdout, " Name: %s\n", value );
_getch();
return 0;
}

The c version works perfectly and returns a filehandle value of 0x0035e250
however the VB version always returns a filehandle value of 0 meaning that
the call to MP4Read has failed in some way. Could it be the way I`m
passing the filename string to the MP4Read function in VB?

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top