pinvoke

NullReferenceException, no stack trace… where to start?

混江龙づ霸主 提交于 2019-12-29 08:29:33
问题 I have a WPF audio application. Occasionally (and even in the debugger) I'm seeing a NullReferenceException which carries no stack trace information with it. How can one start debugging such an issue? Some background: I'm P/Invoking functions in WinMM.dll which involves registering a callback when calling waveOutOpen [DllImport("winmm.dll")] public static extern MmResult waveOutOpen(out IntPtr phwo, IntPtr uDeviceID, WaveFmt pwfx, WaveCallbk dwCallback, IntPtr dwInstance, int fdwOpen); This

Why won't my solution work to P/Invoke NotifyServiceStatusChange in C#?

落花浮王杯 提交于 2019-12-29 07:20:50
问题 I am trying to P/Invoke the NotifyServiceStatusChange event in C# to check when a service has stopped. I managed to get it to compile and run without any errors, but now, when I stop the service, it doesn't seem to want to notify that its dead . Any ideas why that could be? You can test it out by copying this code into a blank console application; just be sure to replace "My Service Name" with your service name (there are two instances of this string below). using System; using System

Is this PInvoke code correct and reliable?

旧城冷巷雨未停 提交于 2019-12-29 05:43:06
问题 In this question I have searched for a simple solution to unblock files. Thanks to all the comments and answer, I have found a simple solution by PInvoking DeleteFile . It works, but because I've never used file-operations through PInvoke (Win32), I don't know if there are some pitfalls or if there is another method of calling DeleteFile to delete the alternate stream of a file. What I also don't know is if I have to wrap the call in a try/catch or if it is enough just to look the at the

A call to PInvoke function has unbalanced the stack. This is likely because the managed PInvoke .. (.NET 4)

大兔子大兔子 提交于 2019-12-29 04:13:42
问题 My project run successful without errors in .NET Frame work 3.5. But, When I target it to .NET Frame work 4. I got the error: " A call to PInvoke function has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. " I used unmanaged library as below: [StructLayout(LayoutKind.Sequential )] public class DGNElemCore { public int offset; public int size; public int element_id; public int stype; public int level; public int type;

Marshal an array of strings from C# to C code using p/invoke

左心房为你撑大大i 提交于 2019-12-29 01:23:57
问题 I need to pass an array of C# strings into C code Example C code void print_string_array(const char** str_array, int length){ for (int i = 0; i < length; ++i) { printf("Sting[%l] = %s\n", i, str_array[i]); } } C# that I have tried (This did not work) string foo[] = {"testing", "one", "two", "three"}; print_string_array(foo, foo.Length); [DllImport(my_C_dll, CharSet = CharSet.Ansi)] private static extern void print_string_array([In][MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType

Unbalanced Stack!

亡梦爱人 提交于 2019-12-28 23:04:46
问题 I have written a VC++ dll. The declaration for one of the methods in the dll is as follows: extern "C" _declspec(dllexport) void startIt(int number) { capture = cvCaptureFromCAM(number); } I use this dll in a C# code using P/Invoke. I make the declaration as: [DllImport("Tracking.dll", EntryPoint = "startIt")] public extern static void startIt(int number); and I call the function in the code as: startIt(0); Now, when this line is encountered, the compiler is throwing me this error: A call to

How can I resize the desktop work area using the SPI_SETWORKAREA flag?

浪尽此生 提交于 2019-12-28 12:44:22
问题 I have been trying for quite a while now to resize the desktop work area (the area where windows get maximized). I have found the required API, but I can't seem to resize the work area. It does just nothing. I use Windows 7 Ultimate x64 so I also tried compiling it in x64 'mode', and still no luck. Could someone give me a push in the right direction? Here is what I got so far: [DllImport("user32.dll", EntryPoint = "SystemParametersInfoA")] private static extern Int32 SystemParametersInfo

What is the difference between [In, Out] and ref when using pinvoke in C#?

若如初见. 提交于 2019-12-28 05:23:07
问题 Is there a difference between using [In, Out] and just using ref when passing parameters from C# to C++? I've found a couple different SO posts, and some stuff from MSDN as well that comes close to my question but doesn't quite answer it. My guess is that I can safely use ref just like I would use [In, Out], and that the marshaller won't act any differently. My concern is that it will act differently, and that C++ won't be happy with my C# struct being passed. I've seen both things done in

Pinvoke SetFocus to a particular control

两盒软妹~` 提交于 2019-12-28 04:27:06
问题 Simple question: is it possible to set focus on another application's textbox (using it's ClassName). I have the window as an "intptr" etc etc but just need some guidance as to what functions/APIs are available for this! Issue is, I use the SetForegroundWindow API to get window focus, but it wouldn't let me send the Ctrl+L keys to focus on the textbox! Any help would be great! 回答1: ...as far as I recall, this is the code I had to use to make that work - and that worked well on my apps, and

SendInput and 64bits

非 Y 不嫁゛ 提交于 2019-12-27 15:42:59
问题 Below is an extract of some code I am using to simulate key presses via the SendInput API. This works correctly if I set my application to compile for an x86 CPU, but doesn't work for x64 CPU compilation. I'm guessing it has something todo with the fact that x64 uses double size pointers, but I tried to change this [FieldOffset(4)] to this [FieldOffset(8)] but it didn't work. Could it be something to do with the fact it is importing the 32bit version of user32.dll? #region SendInput API