pinvoke

What does KEYEVENTF_SILENT equate to

KEYEVENTF_SILENT is a constant used in calls like this one: keybd_event(VK_OFF, 0, KEYEVENTF_SILENT, 0); keybd_event(VK_OFF, 0, KEYEVENTF_SILENT | KEYEVENTF_KEYUP, 0); But since I am using .net I don't know what the actual value of KEYEVENTF_SILENT is. I can't call it with out knowing. Any ideas? ...

error CS0133: Assigning the result of a function to a const in C#.net

Trying to tidy up scope and avoid possible multiple calls to RegisterWindowMessage. Currently have a class used once with the following member [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern int RegisterWindowMessage(string lpString); private int m_message = RegisterWindowMessage("MY_MSG"); As we...

Using .dll methods to load data from file in C# code

I want to use in C# these methods: * int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) * int LibRaw::open_file(const char *rawfile) * int LibRaw::open_buffer(void *buffer, size_t bufsize) * int LibRaw::unpack(void) * int LibRaw::unpack_thumb(void) that are stored in a libraw.dll. These functions...

C#/CopyFile: Cross-platform code with Progress

Hi everyone, Please suggest me a C# cross-platform solution to copy a File with progress. The method should be able to copy the file on Mono as well on .NET. P.S. Most of the solutions here refers to CopyFileEx (which uses PInvoked and I am not sure if this will works on a Mono) P.S.S. Many thanks in advance! -- Murat ...

Advice on whether to use native C++ DLL or not: PINVOKE & Marshaling ?

What's the best way to do this....? I have some Native C++ code that uses a lot of Win32 calls together with byte buffers (allocated using HeapAlloc). I'd like to extend the code and make a C# GUI...and maybe later use a basic Win32 GUI (for use where there is no .Net and limited MFC support). (A) I could just re-write the code in C# a...

Maximize/Minimize is causing Close Button to be re-enabled after disabling it -- Why?

I have used P/Invoke to call GetSystemMenu and EnableMenuItem (win32api) to disable the close functionality. However, after minimizing or maximizing my Windows Forms application the button is re-enabled. Obviously minimizing or maximizing is causing the behavior, but how? I'm not sure where to look to prevent this behavior. Should I be...

C#, .NET, PInvoke For registry functions and PInvoke, how do i get the data from handle pointers?

Say i am using RegQueryValueEx: http://msdn.microsoft.com/en-us/library/ms724911(v=VS.85).aspx I can get the pointer handle to lpType, but its just an integer, how do i actually get the data lpType is pointing to? ...

Writing a managed wrapper for unmanaged (C++) code - custom types/structs

faacEncConfigurationPtr FAACAPI faacEncGetCurrentConfiguration( faacEncHandle hEncoder); I'm trying to come up with a simple wrapper for this C++ library; I've never done more than very simple p/invoke interop before - like one function call with primitive arguments. So, given the above C++ function, for example, what should I ...

A call to PInvoke function '[...]' has unbalanced the stack

Hey I'm getting this weird error on some stuff I've been using for quite a while. It may be a new thing in Visual Studio 2010 but I'm not sure. I'm trying to call a unamanged function written in C++ from C#. From what I've read on the internet and the error message itself it's got something to do with the fact that the signature in my C#...

CSharp -- PInvokeStackImbalance detected on a well documented function?

Here is my code for a ClickMouse() function: [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo); private const long MOUSEEVENTF_LEFTDOWN = 0x02; private const long MOUSEEV...

want to give "logon as a service " rights to the account

i have found a solution using LsaAddAccountRights() win32 api but i was not able to figure out what parameters to give. Here is the code http://www.roelvanlisdonk.nl/?p=1151 Thanks ...

Communicating with all network computers regardless of IP address

I'm interested in finding a way to enumerate all accessible devices on the local network, regardless of their IP address. For example, in a 192.168.1.X network, if there is a computer with a 10.0.0.X IP address plugged into the network, I want to be able to detect that rogue computer and preferrably communicate with it as well. Both co...

How to marshall a LPCWSTR to String in C#?

I'm trying to define a P/Invoke signature for the following method (defined in propsys.h) PSSTDAPI PSRegisterPropertySchema( __in PCWSTR pszPath); I've seen on the WinNT.h that PCWSTR is an alias to LPCWSTR as typedef __nullterminated CONST WCHAR *LPCWSTR, *PCWSTR; And the PSSTDAPI is an alias for HRESULT So how should be the ...

Execute code in another users context

I have an app with a manifest that requires running as administrator, but part of the app is to map a drive using WNetAddConnection2 which I believe requires it to be run in the normal user context due to credentials etc. Is there a way to execute this bit of code in the normal user context without creating a separate process. EDIT Fro...

debugging asp.net & pinvoke

I know you need to turn on the 'Native Code' debugger in order to step into the pinvoke'd dll, however I am not even getting to that point. Instead, when I try to step into the dll I am getting the following exception "Unable to load DLL 'Native.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" If I c...

Performing PInvoke based on a .h file only

Hello, Is it possible to do P/I if I only have the .header interface file with methods exposed? Thanks for your guidance! Cheers! ...

Marshal structure pointer in VS2010

Hi, I have to call a C++ DLL from my C# program. I'm trying to do it using PInvoke - everything works fine in VS2005\ 2008, but after migration to VS 2010, I get this exception: PInvokeStackImbalance was detected Message: A call to PInvoke function 'sampleFunc' has unbalanced the stack. This is likely because the managed PI...

How to call memcmp() on two parts of byte[] (with offset)?

Hi, I want to compare parts of byte[] efficiently - so I understand memcmp() should be used. I know I can using PInvoke to call memcmp() - http://stackoverflow.com/questions/43289/comparing-two-byte-arrays-in-net But, I want to compare only parts of the byte[] - using offset, and there is no memcmp() with offset since it uses pointers...

Reverse P/Invoke tutorial ?

I've a old C/C++ class that i want to refactor and access from .net using PInvoke All P/Invoke tutorials refers to call win32 api but i haven't found anything to code the other side Any tips/ideas ? my c/c++ experience is pretty rusty :( UPDATE - this is for wrapping existing C/C++ code so it can called from .net using P/Invoke How d...

How to find that Mutex in C# is acquired?

How can I find from mutex handle in C# that a mutex is acquired? When mutex.WaitOne(timeout) timeouts, it returns false. However, how can I find that from the mutex handle? (Maybe using p/invoke.) UPDATE: public class InterProcessLock : IDisposable { readonly Mutex mutex; public bool IsAcquired { get; private set; } publ...