Results 1 to 5 of 5

Thread: [RESOLVED] C# to VB.NET conversion

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    8

    Resolved [RESOLVED] C# to VB.NET conversion

    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

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: C# to VB.NET conversion

    An invaluable converter utility that is free but converts up to 100 lines of code at a time.

    http://www.tangiblesoftwaresolutions...Instant_VB.htm
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: C# to VB.NET conversion

    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:

    Code:
    <DllImport(mmdll)> _
    Public Shared Function waveOutGetNumDevs() As Integer
    or this:

    Code:
    <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.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: C# to VB.NET conversion

    End Function is requiredbut also the EntryPoint:= argument too.

    vb Code:
    1. <DllImport("mmdll.dll", EntryPoint:="waveOutGetNumDevs")> _
    2. Public Shared Function waveOutGetNumDevs() As Integer
    3. 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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    8

    Re: C# to VB.NET conversion

    okay thanks, that solves it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width