pinvoke

Getting exception when calling CryptGetKeyParam

I'm trying to use the CryptoAPI (CAPI) to perform a Diffie Hellman Key Exchange. I'm using the MSDN documentation. // Step 0) Acquire context if (!CAPI.CryptAcquireContext(ref this._cryptographicProvider, null, null, CAPI.PROV_DSS_DH, CAPI.CRYPT_VERIFYCONTEXT)) HandleWin32Error("Unable to acquire cryptographi...

How to change the timezone setting of Windows2k8 with .net

I have tried to change the timezone of my system with c# code for a few days now and nothing I'm trying is making much sense or working at all. I started out trying to use the PInvoke syntax for SetTimeZoneInformation that I've seen on other questions here. [DllImport("kernel32.dll", CharSet = CharSet.Auto)] private static extern bool ...

GUI-Test automation: Finding WinForms buttons via pinvoke with c#

I'm building a small GUI-Test automation tool in C# for a application. One of the functions in the test tool is to close dialogs pops up from the tested application. The trouble that I have is to find the button to click on without giving the full class name. I have used the FindWindowEx method to get the dialog box and the button that ...

Compact Framework call Input Method Options with p/invoke

Hi, I have implemented a p/invoke command in my compact framework based application which invokes the windows calibrate screen. [DllImport("coredll.dll")] private extern static bool TouchCalibrate(); btnAlignScreen.Click += delegate { TouchCalibrate(); }; Does anyone know the p/invoke command to invok...

Passing NON null-terminated strings to unmanaged code

Consider the following struct to be sent over TCP to an unmanaged dll [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] public struct FooMessage { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 42)] public string foo; //More fields... } Using the following function (credit to Cheeso): public byte[]...

What is a way to provide logging from a c++ dll to a c# application via interop/pinvoke

I have a C++ DLL that I have source to. It is currently logging to stdout. I am calling methods in this dll via pinvoke from c#. I want the c# code to be able to get the log messages, and then forward them to the c# application's own logging mechanism. I have seen some questions/answers dealing with capturing stdout, but I cannot get ...

PInvokeStackImbalance - invoking unmanaged code from HookCallback

my goal i want to translate a left click to a right click my approach i register a low-level hook via SetWindowsHookEx (user32.dll) filter left-mouse-clicks check if i want to translate THAT specific click in case that i really want to do not pass on the message create a new mouseclick via mouse_event (user32.dll too) the problem...

Call native code specified at runtime

I'm developing an application that will allow users to call external code from both managed and native .dlls. The users will be able to specify what library/method/function to call at runtime (it will be stored in a configuration file). I know how to do this using pinvoke for native libraries if I know what dll/function I want to call ...

How do I check if an NTAccount object represents a Group or a User?

When working with the access rules returned by GetAccessRules(True, True, GetType(System.Security.Principal.NTAccount)) how can I tell if the NTAccount object referenced in each rule is a user account or a group? Update: I was able to solve this as follows. Note, the intent of this code is to return True if the NTAccount is a grou...

BadImageFormatException: PInvoke ImportDll with hdf5dll.dll

Ok, I have the HDF5 library downloaded from the official site, and I have a few DLLs, including hdf5dll.dll, and hdf5_hldll.dll. I have what I think to be some wrappers around the native calls, in my classes H5, H5LT, H5F, and H5T. Example from H5.cs: namespace HDF5 { using hid_t = System.Int32; using herr_t = System.Int32; ...

Is there a table of the matching types for marshaling in P/Invoke & InterOP?

I am almost buried by how the different dialects of types are matched between .NET world and native world. Such as MFC CList and other stuffs. I am desperately hoping for this: Some kind of table or cheetsheet that lists all the mappings between types of .NET world and native world. A table that lists all the types that can be marshal...

pinvoke, sendmessagebystring, retrieving from rich text

I have a situation where I must use Windows API to retrieve text from a Rich Text Box in another program; I am wondering if there is any way to get the ...'rich text' from it, and not just the plain text. In this example, ptrHandle is the RichText Control Handle. if (ptrHandle == null) return null; if (ptrHandle == IntPtr.Zero) ...

Windows Explorer settings: What's the point of SSF_SHOWSYSFILES?

I'm trying to detect the show system and hidden files settings from Windows Explorer in an application I'm writing. I'm using SHGetSetSettings and in calling it I have to specify one or more of the SSF Constants to specify what settings to retrieve. Finding out the hidden files settings was easy enough, I just had to specify SSF_SHOWAL...

pinvokestackimbalance -- how can I fix this or turn it off?

I just switched to vs2010 from vs2008. Exact same solution, except now every single call to a C++ dll yields a 'pinvokestackimbalance' exception. This exception does not get fired in 2008. I have complete access to the C++ dll and to the calling application. There does not appear to be any problem with the pinvoke, but this problem i...

.NET Interop and TR1 shared_ptr

How is it possible to marshal a shared_ptr from unmanaged C++ code into C#? I have a function in C++ (exposed through C bindings) that will allocate a new MyObject and return a pointer to it via a shared_ptr. In C++ I can call the function: MyObjHandle* ref = NULL: GetMyObject(&ref); // double ptr... where MyObjHandle is defined: ...

RFID tags writing

Can any one tell me how to write information on RFIID tags library name is MifareAPI.dll if any one has used this library to write tag i m using AIR ID Writer RFIDeas Inc Prototypes of function currently i'm working [DllImport("MifareAPI.dll")] public static extern short MF_StoreKey(uint readerKey, ref Byte[] keyBuffer); [DllImpor...

Entry Point Not Found Exception

I'm trying to use a C++ unmanaged dll in a C# project and I'm getting an error when trying to call a function that says that entry point cannot be found. public class Program { static void Main(string[] args) { IntPtr testIntPtr = aaeonAPIOpen(0); Console.WriteLine(testIntPtr.ToString()); } ...

Junk characters coming in from pinvoke WM_GETTEXT

I have a method set that uses pinvoke to call WM_GETTEXT on another program's textbox - and it works fairly well, but frequently I just get back total junk text appended to the end of it. (The ORIGINAL text is always intact.) This is random, I cannot reproduce it on demand, but it is frequent enough to be stopship. Here is the text to ...

C#: Maxing out console applications (fringe development stuff)

Part of an idea of mine are the following things: Mouse access in a C# console application Setting a special font for a console application (to provide the correct codepage 437 with all the RIGHT graphical stuff, not that é and à - stuff) Providing a DirectX - graphical - window on top of a console application that moves with the conso...

Get file type in Mono

How do i get the file type in Mono? i.e. "*.txt" => "Text Document", "*.jpg" => "JPEG Image". Similar to what SHFILEINFO.szTypeName returns with P/Invoke on Windows. ...