Declaration expected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Stevecb
    New Member
    • Jul 2010
    • 13

    Declaration expected

    Hello
    I'm getting the error "Declaratio n expected" twice in this code...
    Code:
    'Required in all cases when calling API functions
    Imports System.Runtime.InteropServices
    
    'Required in this example and any API function which
    'use a string buffer.  Provides the StringBuilder class
    Imports System.Text
    
    Public Class Form1
        <DllImport("KERNEL32.DLL", EntryPoint:="GetSystemDirectoryW", _
             SetLastError:=True, CharSet:=CharSet.Unicode, _
             ExactSpelling:=True, _
             CallingConvention:=CallingConvention.StdCall)> _
             Public Shared Function GetSystemDirectory(ByVal Buffer _
               As StringBuilder, ByVal Size As Integer) As Long
            ' Leave function empty - DLLImport attribute 
            ' forces calls to GetSystemDirectory to
            ' be forwarded to GetSystemDirectory in KERNEL32.DLL
        End Function
    
        Public Const MAX_PATH As Integer = 256
        'How to call the API function:
    
        Dim s As New StringBuilder(MAX_PATH)
    
            GetSystemDirectory(s, MAX_PATH)
            msgbox(s.ToString(), , "System Directory")
    
    End Class
    ..it errors at GetSystemDirect ory and msgbox
    I thought it may need another imports statement, not sure
    I'm using VB.net 2008 express
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    Well change MsgBox to use the MessageBox class (which is native to .Net). MsgBox is a legacy left over function from the VB6 (and older) days.

    As for your other error, I copied your code word for word in an existing VB.NET project and it works fine for me, so I'll have to look further into this one

    Comment

    Working...