PDA

Click to See Complete Forum and Search --> : [RESOLVED] C# to VB.NET conversion


Windblossom
Mar 3rd, 2007, 02:42 PM
Hi, I'm currently converting some code from C#.NET to VB.NET

I'm having a problem with converting this code:

private const string mmdll = "winmm.dll";

[DllImport(mmdll)]
public static extern int waveOutGetNumDevs();

[DllImport(mmdll)]
public static extern int waveOutPrepareHeader(IntPtr hWaveOut, ref WaveHdr lpWaveOutHdr, int uSize);

This got converted to VB.NET:

Private Const mmdll As String = "winmm.dll"

<DllImport(mmdll)>
Public Shared Function waveOutGetNumDevs() As Integer
End Function

<DllImport(mmdll)>
Public Shared Function waveOutPrepareHeader(ByVal hWaveOut As IntPtr, ByRef lpWaveOutHdr As WaveHdr, ByVal uSize As Integer) As Integer
End Function

But I get an error on <DllImport(mmdll)>:

"Attribute Specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement"

Please advice

RobDog888
Mar 3rd, 2007, 02:45 PM
An invaluable converter utility that is free but converts up to 100 lines of code at a time.

http://www.tangiblesoftwaresolutions.com/Product_Details/Instant_VB/Instant_VB.htm

sunburnt
Mar 3rd, 2007, 03:09 PM
You need to place an underscore (line continuation) after the attribute, just as the error message states. C# lines end with a semicolon; VB.NET lines end with a newline. So you either need to do this:


<DllImport(mmdll)> _
Public Shared Function waveOutGetNumDevs() As Integer


or this:


<DllImport(mmdll)> Public Shared Function waveOutGetNumDevs() As Integer


Also, I think the "End Function" is not required, but I don't know much about the VB.NET syntax.

RobDog888
Mar 3rd, 2007, 03:13 PM
End Function is requiredbut also the EntryPoint:= argument too.

<DllImport("mmdll.dll", EntryPoint:="waveOutGetNumDevs")> _
Public Shared Function waveOutGetNumDevs() As Integer
End Function

Also, in addition to the converter utilities you can dopwnload the API Viewer Utility (link in my signature). It has the various formats for API definitions. ;)

Windblossom
Mar 3rd, 2007, 04:57 PM
okay thanks, that solves it