AVIFileInfo throws NullPointerException

  • Thread starter Thread starter Lars Stenberg
  • Start date Start date
L

Lars Stenberg

Hello!

Im sitting here and trying to retreive som avi information, but the
invoke of the AVIFileInfo throws a nullpointer exception.

snipp
-------
public struct AVIFILEINFO {
public long dwMaxBytesPerSec;
public long dwFlags;
public long dwCaps;
public long dwStreams;
public long dwSuggestedBufferSize;
public long dwWidth;
public long dwHeight;
public long dwScale;
public long dwRate;
public long dwLength;
public long dwEditCount;
public string szFileType;
}

class Class1 {
....
[DllImport("avifil32.dll")]
private static extern void AVIFileInit();

[DllImport("avifil32.dll")]
private static extern void AVIFileExit();

[DllImport("avifil32.dll")]
private static extern long AVIFileOpen(ref long ppfile, string
szFile, long mode, object pclsidHandler);

[DllImport("avifil32.dll")]
private static extern long AVIFileRelease(long pfile);

[DllImport("avifil32.dll")]
private static extern long AVIFileInfo (long pfile, ref AVIFILEINFO
pfi, long lSize);
....

public Class1() {
AVIFileInit();
long hFile = 0;
AVIFILEINFO aviInfo = new AVIFILEINFO();
AVIFileOpen(ref hFile, @"C:\klowner.avi", 0, null);
AVIFileInfo(hFile, ref aviInfo,
System.Runtime.InteropServices.Marshal.SizeOf(aviInfo));
AVIFileRelease(hFile);

AVIFileExit();
}
}

AVIFileOpen returns long, 68116944363978752
When the exception is thrown hFile == 3761212

Anyone have any clue?

Regards,
Lars
 
Lars,
public struct AVIFILEINFO {
public long dwMaxBytesPerSec;
public long dwFlags;
public long dwCaps;
public long dwStreams;
public long dwSuggestedBufferSize;
public long dwWidth;
public long dwHeight;
public long dwScale;
public long dwRate;
public long dwLength;
public long dwEditCount;
public string szFileType;
}

All longs should be changed to (u)ints. The szFileType member should
have the attribute

[MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)]

and the struct itself should have

[StructLayout(LayoutKing.Sequential, CharSet=CharSet.Auto)]

[DllImport("avifil32.dll")]
private static extern long AVIFileOpen(ref long ppfile, string
szFile, long mode, object pclsidHandler);

[DllImport("avifil32.dll")]
private static extern long AVIFileRelease(long pfile);

[DllImport("avifil32.dll")]
private static extern long AVIFileInfo (long pfile, ref AVIFILEINFO
pfi, long lSize);

This should be

[DllImport("avifil32.dll", CharSet=CharSet.Auto)]
private static extern uint AVIFileOpen(out IntPtr ppfile, string
szFile, uint mode, IntPtr pclsidHandler);

[DllImport("avifil32.dll")]
private static extern uint AVIFileRelease(IntPtr pfile);

[DllImport("avifil32.dll", CharSet=CharSet.Auto)]
private static extern uint AVIFileInfo(IntPtr pfile, out AVIFILEINFO
pfi, int lSize);




Mattias
 
Back
Top