Straterra Posted January 15, 2006 Posted January 15, 2006 I know how to eject the CD-ROM drive in VB6..but..how would I go about ejecting and closing the CD-ROM drive in VB .Net? Quote
Cags Posted January 15, 2006 Posted January 15, 2006 This may help... http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20922233.html Quote Anybody looking for a graduate programmer (Midlands, England)?
Straterra Posted January 15, 2006 Author Posted January 15, 2006 This may help... http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20922233.html Gah..I don't have an account with them.. Quote
Cags Posted January 16, 2006 Posted January 16, 2006 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) Quote Anybody looking for a graduate programmer (Midlands, England)?
Straterra Posted January 17, 2006 Author Posted January 17, 2006 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. Quote
Leaders snarfblam Posted January 17, 2006 Leaders Posted January 17, 2006 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. Quote [sIGPIC]e[/sIGPIC]
Cags Posted January 17, 2006 Posted January 17, 2006 Just to clarify, that code was the accepted answer from experts exchange, I simply copied it across. Quote Anybody looking for a graduate programmer (Midlands, England)?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.