By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,596 Members | 995 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,596 IT Pros & Developers. It's quick & easy.

Declaration expected

P: 13
I'm getting the error "Declaration expected" twice in this code...
Expand|Select|Wrap|Line Numbers
  1. 'Required in all cases when calling API functions
  2. Imports System.Runtime.InteropServices
  4. 'Required in this example and any API function which
  5. 'use a string buffer.  Provides the StringBuilder class
  6. Imports System.Text
  8. Public Class Form1
  9.     <DllImport("KERNEL32.DLL", EntryPoint:="GetSystemDirectoryW", _
  10.          SetLastError:=True, CharSet:=CharSet.Unicode, _
  11.          ExactSpelling:=True, _
  12.          CallingConvention:=CallingConvention.StdCall)> _
  13.          Public Shared Function GetSystemDirectory(ByVal Buffer _
  14.            As StringBuilder, ByVal Size As Integer) As Long
  15.         ' Leave function empty - DLLImport attribute 
  16.         ' forces calls to GetSystemDirectory to
  17.         ' be forwarded to GetSystemDirectory in KERNEL32.DLL
  18.     End Function
  20.     Public Const MAX_PATH As Integer = 256
  21.     'How to call the API function:
  23.     Dim s As New StringBuilder(MAX_PATH)
  25.         GetSystemDirectory(s, MAX_PATH)
  26.         msgbox(s.ToString(), , "System Directory")
  28. End Class
  29. errors at GetSystemDirectory and msgbox
I thought it may need another imports statement, not sure
I'm using 2008 express
Aug 4 '10 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 100+
P: 465
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
Aug 4 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.