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

Declaration expected

P: 13
Hello
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
  3.  
  4. 'Required in this example and any API function which
  5. 'use a string buffer.  Provides the StringBuilder class
  6. Imports System.Text
  7.  
  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
  19.  
  20.     Public Const MAX_PATH As Integer = 256
  21.     'How to call the API function:
  22.  
  23.     Dim s As New StringBuilder(MAX_PATH)
  24.  
  25.         GetSystemDirectory(s, MAX_PATH)
  26.         msgbox(s.ToString(), , "System Directory")
  27.  
  28. End Class
  29.  
..it errors at GetSystemDirectory and msgbox
I thought it may need another imports statement, not sure
I'm using VB.net 2008 express
Aug 4 '10 #1
Share this Question
Share on Google+
1 Reply


PsychoCoder
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.