Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi haw could i include 2 DllImport like this
[DllImport("user32.dll")]
[DllImport("windowsx.dll")]
in c#
compiler reply "Duplicate DllImport' attribute"
Posted

unfortunately, I don't know of anyway to globally include all of the methods within a dll like user32.dll.

What you have to do is import the individual functions such as

C#
[DllImport("User32.dll")]
public static extern int MessageBox(int h, string m, string c, int type);


So, you would need to know all of the functions that you would use from user32.dll or windowsx.dll and include them all individually.
 
Share this answer
 
v2
Comments
khalidSabtan 21-May-10 17:38pm    
it seems you have gave me the wright answer the line [DllImport("... should be followed by another line that uses the reqired function
then
another [DllImport("... followed by 1 or several function that uses that dll lib. i did not try it yet but it seems correct many thanks Winner
DllImport attribute is added to function, it shows from which DLL the runtime will call this function. What do you want to tell by specifying multiple DllImports?

This is not valid.

What is your goal?
 
Share this answer
 
Comments
khalidSabtan 21-May-10 16:12pm    
hi Dmitry Vitkovsky ,I was c++ programer i want to convert 1 of my c++ program 2 c# it has many included library such as
#include user32.h
#include windowsx.h
how could i include that in c# i hope this clearfy ur request
Dimitri Witkowski 21-May-10 16:17pm    
Ohhhh
DllImport is NOT an include - it's like
extern "C" __declspec(dllimport)

http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx
khalidSabtan 21-May-10 16:29pm    
the msdn you provided did not help ,no matter what is my question just tell me how to tell the compiler that
the program need user32.dll and windows.dll ?
Dimitri Witkowski 21-May-10 16:36pm    
The .NET app will require to describe each function you import from these libraries, and to each function you will have to add DllImport attribute.
You can start here: http://msdn.microsoft.com/en-us/library/sd10k43k(VS.71).aspx

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