Grupos de Google ya no admite nuevas publicaciones ni suscripciones de Usenet. El contenido anterior sigue siendo visible.

Please Help API/DLL

Visto 75 veces
Saltar al primer mensaje no leído

Fernando

no leída,
7 ene 2006, 8:24:577/1/06
a
Hi,

I need count the frames of a AVI media file - the length.

I made the code bellow and it works well in VB.6 but not in VB.NET

Why does not work in DOT.NET ? I tried to change TYPE to STRUCTURE, and
ByVal to ByRef in API calls, but without sucess.

I then made a VB.6 DLL of this sample code and use it within VB.NET, but
this is slow, it needs to register in anothe computer...

Please tell me why I can't use it within VB.NET

thank you very much

Private Const OF_SHARE_DENY_WRITE As Long = &H20
Private Type AVIFileInfo
dwMaxBytesPerSec As Long
dwFlags As Long
dwCaps As Long
dwStreams As Long
dwSuggestedBufferSize As Long
dwWidth As Long
dwHeight As Long
dwScale As Long
dwRate As Long
dwLength As Long
dwEditCount As Long
szFileType As String * 64
End Type
Private Declare Function AVIFileOpen Lib "avifil32" Alias "AVIFileOpenA" _
(ppfile As Long, ByVal szFile As String, ByVal mode As Long, pclsidHandler _
As Any) As Long

Private Declare Function AVIFileRelease Lib "avifil32" (ByVal pfile As Long)
_
As Long

Private Declare Function AVIFileInfo Lib "avifil32" Alias "AVIFileInfoA" _
(ByVal pfile As Long, pfi As AVIFileInfo, ByVal lSize As Long) As Long

Private Declare Sub AVIFileInit Lib "avifil32" ()
Private Declare Sub AVIFileExit Lib "avifil32" ()

Public Function getFrames(ByVal aviFile As String) As String
Dim hFile As Long, AviInfo As AVIFileInfo
AVIFileInit
'create a handle to the AVI file
If AVIFileOpen(hFile, aviFile, OF_SHARE_DENY_WRITE, ByVal 0&) = 0 Then
'retrieve the AVI information
If AVIFileInfo(hFile, AviInfo, Len(AviInfo)) = 0 Then
getFrames = CStr(AviInfo.dwLength)
Else
getFrames = "#Error#"
End If
'release the file handle
AVIFileRelease hFile
Else
getFrames = "#Error#"
End If
'exit the AVIFile library and decrement the reference count for the
library
AVIFileExit
End Function


Mattias Sjögren

no leída,
7 ene 2006, 9:49:417/1/06
a
>Why does not work in DOT.NET ? I tried to change TYPE to STRUCTURE,

You also have to adjust the data types, such as changing Long to
Integer.


>and ByVal to ByRef in API calls

That you shouldn't do.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Fernando

no leída,
7 ene 2006, 10:16:527/1/06
a
thanks

I did made that changes in order to run within VB.NET, but I allways get
this error :

changed Long to Integer
and ANY to integer

An unhandled exception of type 'System.NullReferenceException' occurred in
WindowsApplication1.exe
Additional information: Object reference not set to an instance of an
object.

can't do it :((

the new code is this :

Module Module1
Private Const OF_SHARE_DENY_WRITE As Integer = &H20
Private Structure AVIInfo
Dim dwMaxBytesPerSec As Integer
Dim dwFlags As Integer
Dim dwCaps As Integer
Dim dwStreams As Integer
Dim dwSuggestedBufferSize As Integer
Dim dwWidth As Integer
Dim dwHeight As Integer
Dim dwScale As Integer
Dim dwRate As Integer
Dim dwLength As Integer
Dim dwEditCount As Integer
Dim szFileType As String
End Structure

Private Declare Function AVIFileOpen Lib "avifil32" Alias "AVIFileOpenA"
_

(ByVal ppfile As Integer, ByVal szFile As String, ByVal mode As Integer,
ByVal pclsidHandler _
As Integer) As Integer

Private Declare Function AVIFileRelease Lib "avifil32" (ByVal pfile As

Integer) _
As Integer

Private Declare Function AVIFileInfo Lib "avifil32" Alias "AVIFileInfoA"
_

(ByVal pfile As Integer, ByVal pfi As AVIInfo, ByVal lSize As Integer)
As Integer

Private Declare Sub AVIFileInit Lib "avifil32" ()
Private Declare Sub AVIFileExit Lib "avifil32" ()

Public Function getFrames(ByVal aviFile As String) As String

Dim hFile As Integer, AviInfo As AVIInfo
AVIFileInit()


'create a handle to the AVI file

If AVIFileOpen(hFile, aviFile, OF_SHARE_DENY_WRITE, 0) = 0 Then


'retrieve the AVI information
If AVIFileInfo(hFile, AviInfo, Len(AviInfo)) = 0 Then
getFrames = CStr(AviInfo.dwLength)
Else
getFrames = "#Error#"
End If
'release the file handle

AVIFileRelease(hFile)


Else
getFrames = "#Error#"
End If
'exit the AVIFile library and decrement the reference count for the
library

AVIFileExit()
End Function

End Module


Mattias Sjögren

no leída,
7 ene 2006, 11:52:067/1/06
a
> Private Structure AVIInfo
...
> Dim szFileType As String

Add the attribute <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)>
to this field.


> Private Declare Function AVIFileOpen Lib "avifil32" Alias "AVIFileOpenA"
>_
> (ByVal ppfile As Integer, ByVal szFile As String, ByVal mode As Integer,
>ByVal pclsidHandler _
> As Integer) As Integer

ppfile should be ByRef here or you wont get a valid file pointer back.


> Private Declare Function AVIFileInfo Lib "avifil32" Alias "AVIFileInfoA"
>_
> (ByVal pfile As Integer, ByVal pfi As AVIInfo, ByVal lSize As Integer)
>As Integer

pfi should be ByRef.

Fernando

no leída,
7 ene 2006, 14:21:107/1/06
a
thank you Mattias, thank you very much

it works now and I don't need a VB.6 DL anymore

the code is this :

========

Imports System.Runtime.InteropServices

Module Module1
Private Const OF_SHARE_DENY_WRITE As Integer = &H20
Private Structure AVIInfo
Dim dwMaxBytesPerSec As Integer
Dim dwFlags As Integer
Dim dwCaps As Integer
Dim dwStreams As Integer
Dim dwSuggestedBufferSize As Integer
Dim dwWidth As Integer
Dim dwHeight As Integer
Dim dwScale As Integer
Dim dwRate As Integer
Dim dwLength As Integer
Dim dwEditCount As Integer

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> Dim szFileType
As String
End Structure

Private Declare Function AVIFileOpen Lib "avifil32" Alias "AVIFileOpenA"
(ByRef ppfile As Integer, ByVal szFile As String, ByVal mode As Integer,
ByVal pclsidHandler As Integer) As Integer

Private Declare Function AVIFileRelease Lib "avifil32" (ByVal pfile As

Integer) As Integer

Private Declare Function AVIFileInfo Lib "avifil32" Alias "AVIFileInfoA"

(ByVal pfile As Integer, ByRef pfi As AVIInfo, ByRef lSize As Integer) As
Integer

Private Declare Sub AVIFileInit Lib "avifil32" ()


Private Declare Sub AVIFileExit Lib "avifil32" ()

Public Function getFrames(ByVal aviFile As String) As String
Dim hFile As Integer, AviInfo As AVIInfo

Dim tmp As String

AVIFileInit()
'create a handle to the AVI file

If AVIFileOpen(hFile, aviFile, OF_SHARE_DENY_WRITE, tmp) = 0 Then


'retrieve the AVI information
If AVIFileInfo(hFile, AviInfo, Len(AviInfo)) = 0 Then
getFrames = CStr(AviInfo.dwLength)
Else
getFrames = "#Error#"
End If
'release the file handle
AVIFileRelease(hFile)
Else
getFrames = "#Error#"
End If
'exit the AVIFile library and decrement the reference count for the

AVIFileExit()
End Function

End Module


0 mensajes nuevos