unmanaged

How to find a child of a parent unmanaged win32 app

a 夏天 提交于 2019-11-28 06:17:08
问题 Basically I am looking for a win32 method to invoke in C# to set the focus to a children of an unmanaged application. But first I need to find the child control's handle which is the problem. Any useful win32 functions to solve this? 回答1: There is a library which supports enumerating and searching window handles, which is available at http://mwinapi.sourceforge.net/ Just so that you do not have to reinvent the wheel every time ;) Start with SystemWindow.AllToplevelWindows and then just dig

Pass Managed Function Pointer As Unmanaged Callback

微笑、不失礼 提交于 2019-11-28 04:55:08
问题 I am attempting to pass a managed function pointer void (*)(void *) to my unmanaged library. My unmanaged library calls this callback with a pointer to a frame of data protected by a CriticalSection. While the managed callback is running, nothing else can modify the frame of data due to the Critical Section. However, I am getting Access Violations and Heap Corruptions just by entering the callback. EDIT : I forgot to mention. The StartStreaming() steals the thread it manages. Furthermore, it

SafeHandle and HandleRef

偶尔善良 提交于 2019-11-28 04:14:14
问题 After reading about both, including a high voted answer on this site, I still find this a bit unclear. Since my understanding of the matter might be wrong, I'll first post a synopsis of what I know so I can be corrected if I'm wrong, and then post my specific questions: Sometimes when coding managed code, we have to pass an address to unmanaged code. That's what an IntPtr is for. However, we try to make sure of two opposite things: a) Keep that pointer (to an address) alive from the GC. b)

WinApi - GetLastError vs. Marshal.GetLastWin32Error

吃可爱长大的小学妹 提交于 2019-11-28 03:55:00
I tested a lot. But I found no disadvantages of those 2! But see the accepted answer. I read here that calling GetLastError in managed code is unsafe because the Framework might internally "overwrite" the last error. I have never had any noticeable problems with GetLastError and it seems for me that the .NET Framework is smart enough not to overwrite it. Therefore I have a few questions on that topic: in [DllImport("kernel32.dll", SetLastError = true)] does the SetLastError attribute make the Framework store the error code for the use of Marshal.GetLastWin32Error() ? is there an example where

What is the difference in managed and unmanaged code, memory and size?

二次信任 提交于 2019-11-28 02:56:58
After seeing and listening a lot regarding managed and unmanaged code, and knowing the only difference is that managed is about CLR and un-managed is outside of the CLR, it makes me really curious to know it in detail. What is it all about, managed and unmanaged code, memory and size? How can code I write in C# be unmanaged while this is C# code and how does a memory of size becomes unmanaged. An example and a little insight would be helpful. Short answer: Managed code is .NET code (VB.NET, C# etc.) that you write and compile to .NET CIL . Unmanaged code is code that is not under .NET that

Wrapping unmanaged C++ with C++/CLI - a proper approach

女生的网名这么多〃 提交于 2019-11-28 00:03:40
as stated in the title, I want to have my old C++ library working in managed .NET. I think of two possibilities: 1) I might try to compile the library with /clr and try "It Just Works" approach. 2) I might write a managed wrapper to the unmanaged library. First of all, I want to have my library working FAST, as it was in unmanaged environment. Thus, I am not sure if the first approach will not cause a large decrease in performance. However, it seems to be faster to implement (not a right word :-)) (assuming it will work for me). On the other hand, I think of some problems that might appear

allocating “unmanaged” memory in c#

不打扰是莪最后的温柔 提交于 2019-11-27 20:32:47
I'm writting a program in c# that uses a C++ library, and for some reason I need to allocate an unmanaged buffer to pass it to the lib. Is there a way to do this in c# ? Basically I would just need to do a malloc in C#... Thanks Try something like this: using System; using System.Runtime.InteropServices; class Example { static void Main() { IntPtr pointer = Marshal.AllocHGlobal(1024); } } This uses the Marshal.AllocHGlobal method: Allocates memory from the unmanaged memory of the process by using the specified number of bytes. You can also use a byte array for this. You do this by using an

Abort call to unmanaged DLL

半世苍凉 提交于 2019-11-27 20:14:39
I have an unmanaged DLL with a function that can run for a long time if the input parameter is a large value, sometimes that is desirable but not always. How can I in c# call this function so that I can abort it when needed? So far I have tried to put the call in a separate thread, but neither interrupt nor abort seem to stop the process, which runs at 100% CPU until the dll is done. Is it possible to terminate the running dll code? Unmanaged code is only abortable if it is an "alertable wait state". It won't be when it is burning 100% cpu cycles. P/Invoking TerminateThread would work,

Minimum C# code to extract from .CAB archives or InfoPath XSN files, in memory

随声附和 提交于 2019-11-27 17:51:35
问题 Lately I've been trying to implement some functionality which extracts files from an InfoPath XSN file (a .CAB archive). After extensive searching around the internet, it seems that there is no native .NET API for this. All current solutions are centered around large libraries i.e. managed C++ which wrap up Cabinet.dll. All of this, sadly, falls foul of my companies "No third party libraries" policy. As of 2.0, .NET gained an attribute called UnmanagedFunctionPointer which allows source level

CallbackOnCollectedDelegate was detected

情到浓时终转凉″ 提交于 2019-11-27 17:33:47
问题 I am subclassing an application. My subclassed Window procedure is within a DLL. My subclassing code inside the DLL looks somewhat like this (stripped down, removed other non-related parts). class FooBar { private delegate int WndProcDelegateType(IntPtr hWnd, int uMsg, int wParam, int lParam); private const int GWL_WNDPROC = (-4); private static IntPtr oldWndProc = IntPtr.Zero; private static WndProcDelegateType newWndProc = new WndProcDelegateType(MyWndProc); internal static bool bHooked =