pinvoke

EntryPointNotFoundException when using TaskDialog in C#.

I'm using the following code to call a TaskDialog. [DllImport("ComCtl32", CharSet = CharSet.Unicode, PreserveSig = false)] internal static extern void TaskDialogIndirect( [In] ref TASKDIALOGCONFIG pTaskConfig, [Out] out int pnButton, [Out] out int pnRadioButton, [Out] out bool pfVerificationFlagCh...

Clarification on how to properly declare interop interfaces

This is just a question on how to write my code for a COM import. My understanding of the correct implementation of interop interfaces is that the main criteria is that: All method signatures must match in a compatible way Methods must appear in exactly the same order in the .Net interface as they do in the unmanaged interface When th...

P/Invoke Interop Assistant: Is this actually correct?

I've got the following structs in C++: (Using pragma pack 1) typedef struct _wfs_cdm_physicalcu { LPSTR lpPhysicalPositionName; CHAR cUnitID[5]; ULONG ulInitialCount; ULONG ulCount; ULONG ulRejectCount; ULONG ulMaximum; USHORT usPStatus; BOOL bHardw...

Can anyone find equivalent c# code

This is c++ code CreateImageSnapshot, (int, eImageFormat, BYTE**) in VC++ we implementing BYTE** PlayerLib::CreateImageSnapshot (iPlayerRef,static_cast<eImageFormat>(lFormat), &pBuffer); here i need to import the dll and do the same process in c#.. Can anyone find equivalent C# code like [DllImport("PlayerLib", SetLastError ...

Call unmanged Code from C# - returning a struct with arrays

[EDIT] I changed the source as suggested by Stephen Martin (highlighted in bold). And added the C++ source code as well. Hi, I'd like to call an unmanaged function in a self-written C++ dll. This library reads the machine's shared memory for status information of a third party software. Since there are a couple of values, I'd like to ...

Getting the Windows System Error Code title/description from it's hex number

I'm messing around with some windows functions using p/invoke. Occasionally, I get an error code that is not ERROR_SUCCESS (such an odd name). Is there a way to look these up within the program? Forexample, if I get error 1017. Can I tell the user The system has attempted to load or restore a file into the registry, but the spec...

SendMessage to Windows Explorer address bar

How to SendMessage to Windows Explorer address bar in C#? Thank you ...

PInvoke on the Windows Mobile platform

So I'm trying to invoke a function I have in my unmanaged C++ dll. void foo(char* in_file, char * out_file) In my C# application I declare the same function as [DllImport("dll.dll")] public static extern void foo(byte[] in_file, byte[] out_file); The actual parameters I pass through an ASCII encoder like so byte[] param1 = Encodi...

Marshalling struct with embedded pointer from C# to unmanaged driver

Hi, I'm trying to interface C# (.NET Compact Framework 3.5) with a Windows CE 6 R2 stream driver using P/Invoked DeviceIoControl() calls . For one of the IOCTL codes, the driver requires a DeviceIoControl input buffer that is the following unmanaged struct that contains an embedded pointer: typedef struct { DWORD address; cons...

What is the difference between a delegate instance and a method pointer?

I thought that a delegate instance was interchangeable with a function instance. Take the following code: delegate int AddDelegate(int a, int b); AddDelegate DelegateInstance; public void DoStuff() { //I can call this without a delegate "instance": MethodThatTakesAdd(Add); //I can also call it WITH a delegate "instance" ...

Is there a managed API for kernel32.searchpath?

Is there a managed API for kernel32.searchpath? i.e not using a pinvoke. http://www.pinvoke.net/default.aspx/kernel32.searchpath ...

Catch DllNotFoundException from P/Invoke

Found post with a solution: http://stackoverflow.com/questions/970017/how-do-i-handle-a-failed-dllimport I'm writing an app that checks the OS version to do different things depending on whether the host is using a Vista-series or NT-series version of Windows. If Vista-series, it loads some DLLs (using DllImport), but doesn't use these ...

F# syntax for P/Invoke signature using MarshalAs

I'm unsure of the syntax for this. I'm trying to translate this C# code into F#. struct LASTINPUTINFO { public uint cbSize; public uint dwTime; } public class IdleTimer { [DllImport("User32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); } This i...

Cannot use pinvoke to send WM_CLOSE to a Windows Explorer window

I have a C# application that uses the SendMessage pinvoke method to send a "close window" message (WM_CLOSE / 16) to various windows outside the application. This works great, except when the window in question is a Windows Explorer window. I do not get an exception, but the window does not close. Here's the signature: [DllImport...

How should I declare this C struct for interop?

I have to use a legacy C routine in the application I am developing. The code in here works, but I have to convert almost all the fields to char arrays in order to use it. There is a better way to do it? I have tried some version using strings, all to no avail. This is the code found in the original header file... typedef struct PXUCAM...

Boolean Marshalling with LayoutKind.Explicit, Is this broken or failing as designed?

First of all the Boolean type is said to have a default marshal type of a four-byte value. So the following code works: struct A { public bool bValue1; public int iValue2; } struct B { public int iValue1; public bool bValue2; } public static void Main() { in...

How can I ignore a field when marshalling a structure with P/Invoke

Hi, I want to marshal a structure for use with P/Invoke, but this struct contains a field that is only relevant to my managed code, so I don't want it to be marshaled since it doesn't belong in the native structure. Is it even possible ? I was looking for an attribute similar to NonSerialized for serialization, but it doesn't seem to ex...

How should I call this native dll function from C#?

Here's the native (Delphi 7) function: function Foo(const PAnsiChar input) : PAnsiChar; stdcall; export; var s : string; begin s := SomeInternalMethod(input); Result := PAnsiChar(s); end; I need to call this from C#, but the name of the dll is not known at compile time - so I must use LoadLibrary to get to it. This is what ...

C# - get event from SetWindowText

We are writing a plugin for an existing VB6 application (via COM interop), and we are requiring some functionality that they do not support. We could easily get the required functionality if we could somehow receive an event for when a particular control's text on their window changes. We can already grab their existing window handle o...

C#: problem loading C++ DLL

In my code, I can load "MessageBoxA" from user32.dll and use it, but if I try to load and use a function from my DLL, I get a crash. My C# code: [DllImport("SimpleDLL.dll")] static extern int mymean(int a, int b, int c); [DllImport("user32.dll")] static extern int MessageBoxA(int hWnd, string msg, ...