473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PInvoke and constants

Hello
I use some win 32 API function for example:
HANDLE CreateFile(
LPCTSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile
);

my code:
[DllImport("kernel32.dll")]
static extern IntPtr CreateFile(string name, int DesiredAccess, int
ShareMode, IntPtr securityAttributes, int CreationDisposition,
int FlagsAndAttributes, 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 2808
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_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile
);

my code:
[DllImport("kernel32.dll")]
static extern IntPtr CreateFile(string name, int DesiredAccess, int
ShareMode, IntPtr securityAttributes, int CreationDisposition,
int FlagsAndAttributes, 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**************@TK2MSFTNGP14.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_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile
);

my code:
[DllImport("kernel32.dll")]
static extern IntPtr CreateFile(string name, int DesiredAccess, int
ShareMode, IntPtr securityAttributes, int CreationDisposition,
int FlagsAndAttributes, 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********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP11.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****************@TK2MSFTNGP15.phx.gbl...


"ShaneB" <st********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP11.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********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP14.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****************@TK2MSFTNGP15.phx.gbl...


"ShaneB" <st********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP11.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
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...
2
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
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...
3
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
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...
7
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...
12
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...
14
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...
3
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); ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.