473,566 Members | 3,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PInvoke and constants

Hello
I use some win 32 API function for example:
HANDLE CreateFile(
LPCTSTR lpFileName,
DWORD dwDesiredAccess ,
DWORD dwShareMode,
LPSECURITY_ATTR IBUTES lpSecurityAttri butes,
DWORD dwCreationDispo sition,
DWORD dwFlagsAndAttri butes,
HANDLE hTemplateFile
);

my code:
[DllImport("kern el32.dll")]
static extern IntPtr CreateFile(stri ng name, int DesiredAccess, int
ShareMode, IntPtr securityAttribu tes, int CreationDisposi tion,
int FlagsAndAttribu tes, IntPtr TemplateFile);
later:
Handle = CreateFile( Name, GENERIC_WRITE, FILE_SHARE_READ , IntPtr.Zero,
OPEN_EXISTING, FILE_ATTRIBUTE_ NORMAL, IntPtr.Zero );

But i compiler does not know these constants: GENERIC_WRITE,
FILE_SHARE_READ , OPEN_EXISTING, FILE_ATTRIBUTE_ NORMAL.
How can i access them ?

Thanx
Michal

Nov 16 '05 #1
5 2818
You have to "handcode" them yourself with the values from the SDK header
files (winnt.h), something like this will do:

const uint GENERIC_READ = 0x80000000;
.....

Willy.

"vertigo" <ax***@wp.pl> wrote in message
news:cn******** **@nemesis.news .tpi.pl...
Hello
I use some win 32 API function for example:
HANDLE CreateFile(
LPCTSTR lpFileName,
DWORD dwDesiredAccess ,
DWORD dwShareMode,
LPSECURITY_ATTR IBUTES lpSecurityAttri butes,
DWORD dwCreationDispo sition,
DWORD dwFlagsAndAttri butes,
HANDLE hTemplateFile
);

my code:
[DllImport("kern el32.dll")]
static extern IntPtr CreateFile(stri ng name, int DesiredAccess, int
ShareMode, IntPtr securityAttribu tes, int CreationDisposi tion,
int FlagsAndAttribu tes, IntPtr TemplateFile);
later:
Handle = CreateFile( Name, GENERIC_WRITE, FILE_SHARE_READ , IntPtr.Zero,
OPEN_EXISTING, FILE_ATTRIBUTE_ NORMAL, IntPtr.Zero );

But i compiler does not know these constants: GENERIC_WRITE,
FILE_SHARE_READ , OPEN_EXISTING, FILE_ATTRIBUTE_ NORMAL.
How can i access them ?

Thanx
Michal

Nov 16 '05 #2
This may help you:

http://www.pinvoke.net/

ShaneB

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:ed******** ******@TK2MSFTN GP14.phx.gbl...
You have to "handcode" them yourself with the values from the SDK header
files (winnt.h), something like this will do:

const uint GENERIC_READ = 0x80000000;
....

Willy.

"vertigo" <ax***@wp.pl> wrote in message
news:cn******** **@nemesis.news .tpi.pl...
Hello
I use some win 32 API function for example:
HANDLE CreateFile(
LPCTSTR lpFileName,
DWORD dwDesiredAccess ,
DWORD dwShareMode,
LPSECURITY_ATTR IBUTES lpSecurityAttri butes,
DWORD dwCreationDispo sition,
DWORD dwFlagsAndAttri butes,
HANDLE hTemplateFile
);

my code:
[DllImport("kern el32.dll")]
static extern IntPtr CreateFile(stri ng name, int DesiredAccess, int
ShareMode, IntPtr securityAttribu tes, int CreationDisposi tion,
int FlagsAndAttribu tes, IntPtr TemplateFile);
later:
Handle = CreateFile( Name, GENERIC_WRITE, FILE_SHARE_READ , IntPtr.Zero,
OPEN_EXISTING, FILE_ATTRIBUTE_ NORMAL, IntPtr.Zero );

But i compiler does not know these constants: GENERIC_WRITE,
FILE_SHARE_READ , OPEN_EXISTING, FILE_ATTRIBUTE_ NORMAL.
How can i access them ?

Thanx
Michal


Nov 16 '05 #3


"ShaneB" <st********@yah oo.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
This may help you:

http://www.pinvoke.net/


Me? I don't think so, but thanks anyway :-).
I prefer to stay away for this PInvoke stuff as much as possible. Most of
what's included in http://www.pinvoke.net/ is covered by managed
alternatives, it's just a matter of searching/learning what's included in
the FCL.

Willy.
Nov 16 '05 #4
No, not you :) That was for the original poster.

Anyhoo, I too avoid PInvoke as much as I can...but there are still many
things missing from the framework. Hopefully 2.0 will address many of them.

ShaneB

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..


"ShaneB" <st********@yah oo.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
This may help you:

http://www.pinvoke.net/


Me? I don't think so, but thanks anyway :-).
I prefer to stay away for this PInvoke stuff as much as possible. Most of
what's included in http://www.pinvoke.net/ is covered by managed
alternatives, it's just a matter of searching/learning what's included in
the FCL.

Willy.

Nov 16 '05 #5
Sure, there are things missing, but as far as I can see, a lot of what's
fount at http://www.pinvoke.net/ is covered by the FCL.
The problem is that people used to VB's 'declare ...' stuff and C/C++ /Win32
programming, are simply looking for direct replacements of Win32 API's when
porting applications to .NET, this without taking some time to learn/see
what's covered by the FCL.
Don't get me wrong, there's nothing basically wrong with PInvoke:
- as long as you know there are no managed alternatives and,
- you know perfectly well what the API is doing, just go for it.
But, a lot of "developers " are blindly using the PInvoke signatures and data
definitions without looking at the API requirements, platform dependencies,
security implications and maintenance issues related to OS versions updates
after deployment, sooner or later they will be faced with a lot of (hard to
trace) issues.
There's a group of PInvoke API's I would call "dangerous" when used in a
managed application because they can disturb the correct functioning of the
CLR.

Willy.
"ShaneB" <st********@yah oo.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
No, not you :) That was for the original poster.

Anyhoo, I too avoid PInvoke as much as I can...but there are still many
things missing from the framework. Hopefully 2.0 will address many of
them.

ShaneB

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..


"ShaneB" <st********@yah oo.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
This may help you:

http://www.pinvoke.net/


Me? I don't think so, but thanks anyway :-).
I prefer to stay away for this PInvoke stuff as much as possible. Most of
what's included in http://www.pinvoke.net/ is covered by managed
alternatives, it's just a matter of searching/learning what's included in
the FCL.

Willy.


Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2234
by: Rookie | last post by:
Hi, Can someone suggest a way to use some of the constants defined in Win32.h eg. FILE_MAP_ALL_ACCESS ? Is there a way to include a .h file in C# code? It would be great if someone could provide links to articles/tutorials on this topic. Thank you.
2
5422
by: ason | last post by:
Does anybody know where to find all these API Constants like for example LVCFMT_BITMAP_ON_RIGHT = 4094; // = 0x1000 Are these Constants in any *.h files???? thanks ..::AsOn
3
3457
by: Brett Robichaud | last post by:
I have created a simple background thread to make one pinvoke call into a DLL I've created. My Winforms app spawns the thread in the form load event then go about it's business. The problem is that my form appears to be blocked while the background thread is running. I am very familir with threads in unmanaged code but am just getting into...
3
1256
by: Mohammad-Reza | last post by:
In MSDN only name of API's Constants are given and if you want the value of them you must search so. I want to know is there any place that I can find them quick and simply.
0
2048
by: Guy Mahieu | last post by:
Hi, I am trying to dynamically add menu items to external win32 applications from c# code. I have found some VB6 examples on the net that do just that, but when I rewrite them into c# they will either do nothing, add a separator or add an empty menu item which does not trigger commands when clicked. The difference between a separator or...
7
4740
by: JohnR | last post by:
Couldn't find it in MSDN. Does anybody have a listing of the message constants that would be received in my application.addmessagefilter routine in VB.net? They are referred to all over MSDN but I can't locate the actual listing of the constants and their values. Thanks, John
12
4928
by: pamelafluente | last post by:
Hi guys, what are the best place on the web where I can find the list of all thh constants like: WM_QUERYENDSESSION As Integer = &H11 (possibly with some explanations) .... etc ... to be used for instance with: Protected Overrides Sub WndProc(ByRef m As
14
3774
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain more why C++/CLI would be better to PInvoke than doing the PInvoke in C#? Because, usually in C# as you already know we use DLLImport and extern
3
2986
by: Siegfried Heintze | last post by:
Can someone kindly help me finish my attempt at pinvoke? HKL is a void* and I don't know how to translate it. //static extern UInt32 MapVirtualKeyExW(UInt32 uCode, UInt32 uMapType, HKL dwhkl); Here is the function: http://msdn.microsoft.com/en-us/library/ms646307(VS.85).aspx Thanks!
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.