Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

The declaration:

Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As System.Text.StringBuilder, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Along with the following code, will work fine.

'Eject: 
mciSendString("set CDAudio door open", Nothing, 127, 0)
'Inject: 
mciSendString("set CDAudio door closed", Nothing, 127, 0)

Anybody looking for a graduate programmer (Midlands, England)?
Posted

I try that code..and VB spits out this error in the IDE

 

A call to PInvoke function 'WindowsApplication1!WindowsApplication1.Form1::mciSendString' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

  • Leaders
Posted

Thats because half the declaration seems to be in VB6 and half seems to be in VB.Net. I'm also kind of confused as to why a return parameter is being passed as a StringBuilder instead of a string, unless StringBuilders are simply more flexible in their marshalling.

 

Try:

Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (_ 
   ByVal lpstrCommand As String, _
   ByVal lpstrReturnString As String, _
   ByVal uReturnLength As Int32, _
   ByVal hwndCallback As Int32) As Int32

or

Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (_ 
   ByVal lpstrCommand As String, _
   ByVal lpstrReturnString As System.Text.StringBuilder, _
   ByVal uReturnLength As Int32, _
   ByVal hwndCallback As Int32) As Int32

 

The unbalanced stack happens because the declaration you are using has two longs (VB6 Int32 versus VB.NET Int64), resulting in an extra four bytes of data on the stack.

[sIGPIC]e[/sIGPIC]
Posted
Just to clarify, that code was the accepted answer from experts exchange, I simply copied it across.
Anybody looking for a graduate programmer (Midlands, England)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...