pinvoke

COM dll is not being flushed out

Guys, I am interacting with a custom COM component called CSCCOM in my c# project. I am wrapping it with IDisposable as below: Form1.cs try { using (CSCCOMWRAP CSC = new CSCCOMWRAP()) { CSCCodeList CSCL = new CSCCodeList(CSC); comboBox1.DataSource = CSCL.List; Marshal.ReleaseComObject(CSCL); } } catc...

Putting window inside the desktop

Hi, I am trying to make a kind of desktop widgets using C#. So far, I've managed to create a window that gets added to the WorkerW window containing SHELLDLL_DefView. This way, my main form is inserted inside the desktop window over the wallpaper. This is exactly what I want except that I have a little problem. It seems like there is an...

C# P/Invoke on CUDA DLL eventually causes AccessViolationException

This is driving me crazy. I've looked all over, but I'm not sure I understand exactly what's causing this error. I'm making a call to a DLL (that I've coded as a separate project) which runs a CUDA kernel on some data I'm using. Although, I suspect the issue isn't being caused by CUDA, since the code has been tested and works at least ...

C# P/Invoke: Pointer to string as error message

I am attempting to use llvmc as a C# library using P/Invokes(because I can't find any .NET bindings). However, I've a problem. llvmc uses char** for error passing. An example would be this: char* error = NULL; LLVMVerifyModule(PointerToSomeModule, LLVMAbortProcessAction, &error); What should I do to allow this function to be used in...

DllImport incomplete names

I am using several P/Invokes under .NET. However, I want my library to work both in Windows and Linux, preferably with the same binaries. Since the native library I depend on is available on multiple platforms, I was hoping to just have them along with my managed library's binaries. Right now I'm using something like this: [DllImport(...

PInvoke DLL That Uses Other DLLs - ClickOnce Question

I'm creating a .NET DLL that acts as a wrapper using PInvoke on an unmanaged DLL. My question is, if I'm PInvoking an unmanaged DLL that references other DLLs when using click once, which DLLs do I need to include with the deployment of a project that uses that .NET Wrapper DLL? Files involved: Project that uses click once deployment...

C# wrapper design for DLL with P/Invoke

I need an opinion on writing a managed (C#) wrapper for an unmanaged C++ DLL. Let's say I have an object like this: public class ManagedObject { public void DoSomethingWithTheObject() { } } and suppose that the DoSomethingWithTheObject() method has to make a call to the unmanaged DLL method. Now there are two acceptable poss...

P/Invoke C# struct with strings to C void*

I'm having a problem creating a C# P/invoke wrapper around a third party C library. In particular, the library has a method with the signature int command(SomeHandle *handle, int commandNum, void *data, int datasize); It is a wildcard method that does different things depending on commandNum. data can be a pointer to anything, like a s...

Need C Sharp win32, PInvoke API

Hi All, Long time listener, first time caller. Does anyone know of a good interop library for the Win32API? I found pinvok.net which is OK. (FWIW I got the addin to work with MSVS 2010 by following the instructions here: http://www.red-gate.com/supportcenter/GeneralContent.aspx?c=knowledgebase\PInvoke\KB200711000198.htm and using 10.0...

Need to activate a window

I have a situation like this. I have the window handle of an application. I need to activate it. I tried all these functions but is not working always.(most of the time , it doesn't work the first time and I'll have to manually click on it to activate it. Second attempt onwards it works fine) The reason why I am doing this is because I ...

P/Invoke AccessViolationException that makes no sense

First of all, sorry to post a question like this when so many other have been asked on this topic, but I've been reading all the questions I could find (+google), and none has really given me any hints as to what is happening in my case. I have a 3rd party .dll (libFLAC) with two exported functions with similar name: FLAC__StreamEncode...

C# 4.0 PInvoke Issue (ATI AGS Library)

Hey guys, I downloaded the ATI AGS (ATI GPU Services) Libary, and am attempting to retrieve some basic driver information using this API, from C#. The ATI AGS library is available for download from here: http://developer.amd.com/gpu/ags/Pages/default.aspx I wrote a little bit of C# code to pull driver information from the GPU using th...

Cleaner way to code instead of Marshall.QueryInterface?

I am wondering if there is a cleaner way to write the (working) code below: uint uEnum = 0; PStore.EnumTypes(0, 0, ref uEnum); System.Reflection.MemberInfo inf = typeof(PSTORECLib.CEnumTypes); GuidAttribute CEnumGuid = (GuidAttribute)inf.GetCustomAttributes(typeof(GuidAttribute), false)[0]; Guid tmp = new Guid(CEnumGuid.Value); Int...

Pinvoke - Location of the Win32 DLL

I use PInvoke on a win32 DLL and i've currently placed it in my System32 folder. Is there an alternative to this? What if my app needs to be deployed somewhere where i dont have access to system folders? ...

Can't find PInvoke DLL on Windows Mobile

I am working on Windows Mobile application. Whenever I download some sample which is using wrapper around native code (using DllImport), it always gives "Can't find PInvoke DLL" error. I am using VS 2005 with C# on 64-bit Windows 7 OS. I have checked many of solution on stackoverflow as well as othersites, but with no solution to my p...

How to use proper unmanged .dll depending on CPU Architecture?

I am using an unmanaged library in a .net application which is used on x86 and 64bit systems alike and therefore is compiled as 'Any CPU'. The unmanaged, native .dll however comes in two different .dlls for that (one for win32 and one for x64). Is there any way to still keep the 'Any CPU' / one binary way with different native .dlls reg...

LowLevelMouseProc in background thread

I'm trying to setup mouse hook on background thread. delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam); LowLevelMouseProc _proc = HookCallback; SetWindowsHookEx(PInvoke.WH_MOUSE_LL, _proc, IntPtr.Zero, 0); and IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam){/**/} If I put this on the main windo...

Paste Rich Text into another application using pinvoke.

I basically have a situation where I need to get rich text out of a C# program, copy it into the Clip Board, and Paste it into another Application using pinvoke. I know how to get the Handle of the Text Box it has to be pasted into, but WM_PASTE doesn't seem to do what I want. I have spent some time searching around the internet, and am ...

P/Invoke declaration does not seem correct

I was handed down a library that was developed in house as a wrapper for BITS. I was told that if you wanted to change between the 64bit and 32bit build you would need to swap out these two commented lines. [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] //32 bit address internal struct BG_BASIC_CREDENTIALS { [FieldOffset(0...

C# dll that can be pinvoked?

Question: Is it possible to write a C# dll that can be pinvoked ? I want to write a replacement library for the WinAPI calls WritePrivateProfileString etc. for reading and writing ini files. Is it possible to export a function, e.g. 'WritePrivateProfileString', implemented in C# so one can pinvoke the dll with DllImport ? I want to re...