pinvoke

P/Invoke for shell32.dll's SHMultiFileProperties

I'm not very good with P/Invoke. Can anyone tell me how to declare and use the following shell32.dll function in .NET? From http://msdn.microsoft.com/en-us/library/bb762230%28VS.85%29.aspx: HRESULT SHMultiFileProperties( IDataObject *pdtobj, DWORD dwFlags ); It is for displaying the Windows Shell Properties dialog for ...

Unable to extract processID from GetProcessId(.. hWnd) (pInvoke)

Hi, im using the following method [DllImport("kernel32.dll", SetLastError=true)] static extern int GetProcessId(IntPtr hWnd); to try and get the processId for a running process and the only information I have is the HWND. My problem is that it is always returning error code 6 which is ERROR_INVALID_HANDLE. I thought i might...

"ignoring" P/Invoke when running on Mono

I have a WinForms Application that I want to run at Mono at some point. However, it is using some P/Invoke against user32.dll, which will cause an obvious problems. However, this is not a critical functionality, just some flavor stuff. So I would like to ignore it when running Mono. I know I could just use an #if directive, but then I ...

.NET Marshaler: Good documentation?

I'm currently working on some C# code that calls into a custom, native dll. When marshaling data back to C#, I have need to explicitly align the fields of the classes/structs used for marshaling. I've had a number of issues with this stemming from an incomplete understanding of the marshaler and its rules. For example, I recently foun...

How to Install OpenType( file type : otf) Font on Application Start using C#

I have to install a Myriad pro web.otf font on the client machine using C# . Please Suggest. i tried installing as per the code mentioned in the post [DllImport("gdi32", EntryPoint = "AddFontResource")] public static extern int AddFontResourceA(string lpFileName); [System.Runtime.InteropServices.DllImport("shfolder.dll", Ch...

Correct way to marshal SIZE_T* ?

I have the following C++ function definition, which I am trying to call through PInvoke from managed code: bool FooBar(SIZE_T* arg1); My managed declaration looked as follows: [DllImport("mydll", SetLastError=true, CharSet=CharSet.Unicode)] private static extern bool FooBar(ref uint arg1); Some of you may notice the same bug I even...

How do I expose erl_interface (Erlang's C library) through a DLL?

I've been working non-stop for the last three days on a completely managed interface to Erlang. At this point, I've decided that there simply must be an easier way. I've got a little over 3000 lines and it's not even in a compilable state yet. To be honest, I'm getting lost in my own code. So, I then remembered that Erlang has a C libra...

Converting this C signature to C# for P/Invoke

I have the following C function: int w_ei_connect_init(ei_cnode* ec, const char* this_node_name, const char *cookie, short creation); ei_cnode looks like this: typedef struct ei_cnode_s { char thishostname[EI_MAXHOSTNAMELEN+1]; char thisnodename[MAXNODELEN+1]; char thisalivename[EI_MAXALIVELEN+1]; ...

Marshaling pointer to an array of strings

I am having some trouble marshaling a pointer to an array of strings. It looks harmless like this: typedef struct { char* listOfStrings[100]; } UnmanagedStruct; This is actually embedded inside another structure like this: typedef struct { UnmanagedStruct umgdStruct; } Outerstruct; Unmanaged code calls back into managed co...

Using in_addr in C#

I'm trying to interact with a native DLL using P/Invoke, but it requires an in_addr struct parameter. I keep seeing many different kinds of definitions for it, but which is the best to use? Also, how can I convert a C# IPAddress object to an in_addr struct? ...

Passing struct by reference causing AccessViolationException

Yet another one of my P/Invoke questions! I have this C function: int _ei_x_new(ei_x_buff* x); Essentially, it initializes a new buffer struct. In C#, I have this: [DllImport(EIDLL, EntryPoint = "_ei_x_new")] public static extern int ei_x_new(out ei_x_buff x); ei_x_buff is pretty simple: typedef struct ei_x_buff_TAG { char* bu...

P/Invoke Marshalling Help - Nested Structures - VB.NET

Ok, what the heck am I doing wrong here.. "System.TypeLoadException: Cannot marshal field 's2' of type 'MY_Struct1': The type definition of this field has layout information but has an invalid managed/unmanaged type combination or is unmarshalable." 'VENDORAPI short FunctionEx(Struct1* pstruct1); Declare Auto Function FunctionEx Lib "...

Windows Mobile - Stop Main Phone App

Is there a way to make Windows Mobile not use the main phone app? I have my own phone app that I want to handle phone transactions for a business device. My app works fine (detects the call and can hang up), but the main phone app still wants to allow the user to answer a call normally. I can try to hide the incoming call window or ...

Can you use .net 3.5 Action or Func as Marshalled unmanaged delegates?

After reading Dynamically calling unmanaged dlls in .net I've been trying to modify the code to my liking. I made a class that implements idisposable to wrap load calls in and free them when needed. However I can't seem to figure out the syntax if it is possible to use anonymous delegates with it. var loaded=DynamicLibraryLoader.TryLo...

Modifying opacity of any window from C#

Hi, Is it possible to modify the opacity of all opened windows from C#. I googled for minimizing the windows and i came to know that its possible with pInvoke calls. It even worked. Similarly is it possible to change the opacity of all the opened windows from C#? Also, i am not in to MFC stuffs. Still is there any tools to know the ...

In .NET, how do I Create a Junction in NTFS, as opposed to a Symlink?

I'm trying to create an NTFS Junction. From the cmd line I can do this using the junction.exe tool from sysinternals. The output of a DIR cmd for a junction looks like this: Volume in drive C has no label. Volume Serial Number is C8BC-2EBD Directory of c:\users\cheeso\Documents 03/22/2009 09:45 PM <JUNCTION> My Music [\?...

Access Violation in Marshal.PtrToStructure

I am trying to deserialize a structure, and I'm getting an AV exception in PtrToStructure. The only wrinkle is that this is a variable length structure, so I need to adjust the length before deserializing. Here's my code, is there anything obviously wrong? The structure contains only integer/short/byte arrays, nothing fancy. the incomin...

Managing C++ Garmin API in C#

I want to call Garmin API (http://developer.garmin.com/mobile/mobile-sdk/) in VB.Net Compact Framework project. The API is in C++, so i´m making a C# dll project as intermediate way between API dll and VB.Net. I have some problems while executing my code because it throw a NotSupportedException (bad arguments type, i think) in QueCreateP...

Is there a way to invoke the "Identify Monitors" function from C#?

I'm working on a little WPF app that will run fullscreen and I'd like to give the user the ability to choose which monitor it will display on. To make it easier to identify each monitor in the list, I would like to do something like the Windows Display Settings dialog's "Identify Monitors" button. Is there a way to invoke that function ...

Implementing IDisposable on a sealed class

I don't think this question has been asked before but I'm a bit confused on the best way to implement IDisposable on a sealed class - more particularly a sealed class that does not inherit from a base class ( i.e a 'pure sealed class' which is my made up term ). Dunno about you but I find the guidelines on implementing IDisposable very c...