Using win32 API function in C#

D

Dov P

hello everyone,
i need to use api function named RegSetKeySecurity in my C# program.
This function require ADVAPI32.DLL, but i cannot add this reference.
I tried to use Microsoft.Win32.Registry Namespace but it doesn't give
te ability to modify Security descriptors.

Please help
thanks.
 
J

Jan Tielens

Calling Win32 DLLs in C# with P/Invoke
http://msdn.microsoft.com/msdnmag/issues/03/07/NET/default.aspx
I
have noticed a trend in my programming of late, and that trend has inspired
the topic of this month's column. Recently, I have done a fair amount of
Win32® Interop in my Microsoft® .NET Framework-based apps. I am not saying
that my apps are full of custom interop code, but from time to time I bump
into a minor, but nagging, inadequacy in the .NET Framework Class Library
that can quickly be alleviated by a call into the Windows® API.
As I think about it, any feature limitation in the .NET Framework version
1.0 or 1.1 class library that is not shared by Windows doesn't come as a
huge surprise. After all, 32-bit Windows, in all of its incarnations, is a
mature operating system that has served a wide breadth of customers for over
a decade. The .NET Framework is, in comparison, a newcomer.
As an increasing developer base moves its production applications to
managed code, it seems only natural that there will be even more occasions
for developers to dip down into the underlying operating system for some
critical tidbit of functionality-at least for the time being.
Thankfully, the interop features of the common language run-time (CLR),
called Platform Invoke (P/Invoke), are very complete. In this column I am
going to focus on the practical use of P/Invoke for calling Windows API
functions. P/Invoke is used as a noun when referring to the COM Interop
functionality of the CLR and is used as a verb when referring to the use of
this feature. I am not going to address COM Interop directly because it is
paradoxically both more accessible and more complex than P/Invoke, making it
less straightforward as a column topic.
 
M

Mattias Sjögren

i need to use api function named RegSetKeySecurity in my C# program.
This function require ADVAPI32.DLL, but i cannot add this reference.
I tried to use Microsoft.Win32.Registry Namespace but it doesn't give
te ability to modify Security descriptors.

This should hopefully work

[DllImport("advapi32.dll")]
static extern uint RegSetKeySecurity(HandleRef hKey, uint
SecurityInformation, IntPtr pSecurityDescriptor);



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top