Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
#define DEBUG
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;



      static void Main(string[] args)
        {
            [DllImport("User32.dll")]
            // All errors from this ^|^
            //                       |
Error	1	} expected           C:\Program.cs	13	38	Project-229
Error	2	Invalid expression term '['	C:\Program.cs	13 13	Project-229
Error	3	; expected                    C:\Program.cs	13 14	Project-229
Error	4	; expected	                  C:\Program.cs	13 37	Project-229
Error	5	Invalid expression term ']'	C:\Program.cs	13 37	Project-229
Error	6	; expected	                  C:\Program.cs	13 38	Project-229
Posted
Updated 6-Aug-10 17:14pm
v2
Comments
Toli Cuturicu 8-Aug-10 6:47am    
Reason for my vote of 2
No imported function!

What function are you trying to import?

Check out http://www.pinvoke.net/ for examples and such.
 
Share this answer
 
Comments
DaveyM69 7-Aug-10 10:26am    
pinvoke.net is a good guide - be careful though as there are many incorrect submissions on there. The most common mistake I've found is using int instead of IntPtr. This will be OK normally on 32 systems, but has a reasonably high probability of failing if ever run on a 64bit OS.
Moral: Check the signatures against those declared in the relavent C/C++ header file or MSDN page and correct if needed.
Your function declarations (like any other methods) need to be declared at the class level. You cannot declare them within another method.

In other words, do it outside of your Main method. As you are calling native functions, the standard is to declare a class called NativeMethods and put them in there.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900