Really stumped with mci API (mciGetErrorString)

N

Nick

Ok if anyone can help me out on this I would be extremely thankful, I'm
completely stumped....

I'm playing around with the MCI API (the stuff you can use for playing
audio/video).

All this code below does is try playing a file which doesn't exist, getting
an error message, and then showing a message box. This is code that I've
copied over from VB6 which works just fine;

Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA"
(ByVal lpszCommand As String, ByVal lpszReturnString As String, ByVal
cchReturnLength As Long, ByVal hwndCallback As Long) As Long
Public Declare Function mciGetErrorString Lib "winmm.dll" Alias
"mciGetErrorStringA" (ByVal fdwError As Long, ByVal lpszErrorText As String,
ByVal cchErrorText As Long) As Long

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim errcode As Long
errcode = mciSendString("open C:\this_doesnot_exist.mpg", "", 0, 0)
If errcode <> 0 Then
Dim errstr As String, retval As Long
errstr = Space(128)
retval = mciGetErrorString(errcode, errstr, Len(errstr))
MsgBox(errstr, vbOKOnly Or vbCritical)
End If
End Sub

But I get an error NullReferenceException when it tries to run
mciGetErrorString.
 
M

Mattias Sjögren

Nick,

Currect Delcare statements for VB.NET should look more like this

Declare Auto Function mciSendString Lib "winmm.dll" (ByVal lpszCommand
As String, ByVal lpszReturnString As String, ByVal
cchReturnLength As Integer, ByVal hwndCallback As IntPtr) As Integer

Declare Auto Function mciGetErrorString Lib "winmm.dll" (ByVal
fdwError As Integer, ByVal lpszErrorText As String, ByVal cchErrorText
As Integer) As Boolean



Mattias
 

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