unmanaged

get pointer on byte array from unmanaged c++ dll in c#

半腔热情 提交于 2019-12-04 04:46:32
问题 in c++ I have such function extern "C" _declspec(dllexport) uint8* bufferOperations(uint8* incoming, int size) I am trying to call it from c# like this [DllImport("MagicLib.DLL", CallingConvention = CallingConvention.Cdecl)] //[return: MarshalAs(UnmanagedType.ByValArray)]//, ArraySubType=UnmanagedType.SysUInt)] public static extern byte[] bufferOperations(byte[] incoming, int size); But I get the Cannot marshal 'return value': Invalid managed/unmanaged type combination ((( The question is -

Free unmanaged memory allocation from managed code

孤街浪徒 提交于 2019-12-04 04:15:00
A .NET application calls C dll. The C code allocates memory for a char array and returns this array as result. The .NET applications gets this result as a string. The C code: extern "C" __declspec(dllexport) char* __cdecl Run() { char* result = (char*)malloc(100 * sizeof(char)); // fill the array with data return result; } The C# code: [DllImport("Unmanaged.dll")] private static extern string Run(); ... string result = Run(); // do something useful with the result and than leave it out of scope Some tests of it show that the garbage collector does not free the memory allocated by the C code.

Getting exceptions on x86 system when using unmanaged code to get file icon using extension

*爱你&永不变心* 提交于 2019-12-04 04:03:44
问题 I'm developing disk catalog application that requires me to get file icons using file extensions retrieved from the database. Code to get file icon using their extension works absolutely fine on my Windows 7 x64 machine with Any CPU debug configuration but when i switch to x86 in debug configuration i get following error. Fatal Execution Engine error When i tried to run the application in Windows XP x86 in Any CPU configuration i get following error. Attempted to read or write protected

How to call managed C++ methods from Un-managed C++

倖福魔咒の 提交于 2019-12-04 03:30:38
问题 PLEASE SEE UPDATE BELOW (RESOLVED) Also I have extended this into a second question here Implement a C# DLL COM File In Unmanaged C++ Program I have researched this to the end of the internet without finding a real, understandable, human example of how to do this. I have a C# DLL that encrypts and decrypts text. I don't want to / don't have the intellectual capability to rewrite this in C++ un-managed code. So instead I created a C++/CLR class that interfaces with the C# dll. NOW I need to

Managed to unmanaged overhead

女生的网名这么多〃 提交于 2019-12-04 03:26:11
In .NET there are several places when you must leave managed code and enter the realm of unmanaged a.k.a. native code. To name a few: extern dll functions COM invocation There are always comments about overhead that jump from one side to another causes, and my question here is if anybody MEASURED exact overhead that is happening, and can explain how it can be calculated. For example, maybe byte[] can be converted to IntPtr or even to byte* in .NET and help marshaller save some CPU cycles. shelleybutterfly [I see I didn't really answer the question about how you would measure; the best way to

Stack overflow in unmanaged: IP: 0x26eb76, fault addr: 0xbf808ffc

萝らか妹 提交于 2019-12-04 02:40:41
My Mono application crashes on Mac with this message ( Full log ): $ mono --debug bin/Debug/SparkleShare.app/Contents/MonoBundle/SparkleShare.exe [...] Stack overflow in unmanaged: IP: 0x26eb76, fault addr: 0xbf808ffc [...] "in unmanaged" implies that the stack overflow is not in my code (I only have managed code) but rather in a library I embed ( SQLite, DotCmis, NewtonSoft.Json ) or in Mono's code. Even though I compile and run in Debug mode, all I get is these two hexadecimals. QUESTION: How can I investigate this stack overflow? Any trick? Note: The same libraries (with pretty much the

How is it that a struct containing ValueTuple can satisfy unmanaged constraints, but ValueTuple itself cannot?

浪子不回头ぞ 提交于 2019-12-04 01:49:57
Consider the following types: (int, int) → managed. struct MyStruct { public (int,int) Value; } → unmanaged! Problem: A non-generic structure MyStruct , which has a managed member (int,int) has been evaluated as managed type. Expected Behavior: A structure which contains a managed member, should be considered as managed, the same way the struct MyStruct { int? Value; } are considered as managed. It seems both types are behaving against the documentations [1] and [2] . Example 1 - unmanaged Constraint class Program { static void DoSomething<T>() where T : unmanaged { } struct MyStruct { public

How to find caller assembly name in unmanaged c++ dll

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 21:11:27
I have an unmanaged c++ dll . I am calling external methods of this unmanaged dll from c# (.net 3.5) I am looking for a way to find witch c# assembly is calling my unmanaged c++ dll (into my c++ dll) (at least, name of assembly) And sure, I don't want to pass any additional parameter to methods . Thanks in advance This requires a stack walk. Works well in managed code, that's how code access security is implemented. Does not work so well when there are native stack frames to walk. You can try StackWalk64() in your native code. Expensive and not that likely to work out well, especially in .NET

Marshal.StructureToPtr fails in module ntdll.dll

*爱你&永不变心* 提交于 2019-12-03 20:29:49
I'll start with a bit of history : The issue I'm facing currently appeared suddenly without any changes to the code. Then disappeared in the same way after 3 days. Now it came back in a week and doesn't want to go away =). I have code that works with printer - settings it's printer preferences to print documents in the specified way. I use local printer which points to TCP address of the network printer (it is common approach for such tasks as I know). Here follows the code I use to load printer configuration from binary file (previously saved in the similar way). I give all source code with

Best way to call Managed .NET code from Unmanaged code

删除回忆录丶 提交于 2019-12-03 19:34:27
问题 I'm trying to find the best performing method of calling into Managed .NET code from Unmanaged C++ code. I have found information on Hosting .NET within my C++ application and I'm able to create a pRuntimeHost and start it without a problem. The ExecuteInDefaultAppDomain seems very limited since I really want to send it a few parameters and have it return a structure of information. The most obvious alternative is to use COM methods but the current C# code isn't really setup as interfaces