unmanaged

How can I send a managed object to native function to use it?

早过忘川 提交于 2019-11-29 04:52:00
How can I send a managed object to native function to use it? void managed_function() { Object^ obj = gcnew Object(); void* ptr = obj ??? // How to convert Managed object to void*? unmanaged_function(ptr); } // The parameter type should be void* and I can not change the type. // This function is native but it uses managed object. Because type of ptr could not be // Object^ I called it "Unmanaged Function". void unmanaged_function(void* ptr) { Object^ obj = ptr ??? // How to convert void* to Managed object? obj->SomeManagedMethods(); } The cleaner and the better approach is to use gcroot

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

不羁岁月 提交于 2019-11-29 03:48:05
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 callback declarations using __cdecl. Prior to this, __stdcall was the only show in town, unless you

CallbackOnCollectedDelegate was detected

↘锁芯ラ 提交于 2019-11-29 03:26:58
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 = false; [DllImport("user32.dll")] private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex,

Unmanaged Exports: Cannot compile assembly

南笙酒味 提交于 2019-11-29 02:37:07
I want to create a .NET assembly that can be accessed from unmanaged code (Delphi 5). I have found Unmanaged Exports and followed the steps there but I am unable to successfuly compile even the basic example: using RGiesecke.DllExport; namespace DelphiNET { public class Class1 { [DllExport("add")] public static int Add(int left, int right) { return left + right; } } } DelphiNET.csproj project file: ... <ItemGroup> <Compile Include="Class1.cs" /> <Compile Include="DllExport\DllExportAttribute.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <Import Project="$

Unload a .NET DLL from an unmanaged process

丶灬走出姿态 提交于 2019-11-29 01:11:17
I'm extending my Inno-Setup script with code that I can best implement in C# in a managed DLL. I already know how to export methods from a managed DLL as functions for use in an unmanaged process. It can be done by IL weaving, and there are tools to automate this: NetDllExport (written by me) UnmanagedExports So after exporting, I can call my functions from Pascal script in an Inno-Setup installer. But then there's one issue: The DLL can't seem to be unloaded anymore. Using Inno-Setup's UnloadDLL(...) has no effect and the file remains locked until the installer exits. Because of this, the

How to run unmanaged executable from memory rather than disc

本秂侑毒 提交于 2019-11-28 23:55:01
I want to embed a command-line utility in my C# application, so that I can grab its bytes as an array and run the executable without ever saving it to disk as a separate file (avoids storing executable as separate file and avoids needing ability to write temporary files anywhere). I cannot find a method to run an executable from just its byte stream. Does windows require it to be on a disk, or is there a way to run it from memory? If windows requires it to be on disk, is there an easy way in the .NET framework to create a virtual drive/file of some kind and map the file to the executable's

C++/CLI Support in .Net Core

倖福魔咒の 提交于 2019-11-28 21:15:09
Our project structure is like, native.dll :- This contains pure native code written in c\c++. This native.dll exposes some functions using *def file. Wrapper Library(wrapper.dll compiled with .Net framework v4.0) :- In order to use functionality of native.dll , a Wrapper lib(wrapper.dll) is written in C++\CLI using :clr\oldsyntax . This wrapper has all code of Interoperability and Marshalling . Application(Console App v4.0) directly uses wrapper.dll to use functionality provided by native.dll . Now this project needs to run in .Net Core . This means we will have an .Net Core application that

Marshal.AllocHGlobal VS Marshal.AllocCoTaskMem, Marshal.SizeOf VS sizeof()

穿精又带淫゛_ 提交于 2019-11-28 20:24:24
I have the following struct: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct WAVEHDR { internal IntPtr lpData; // pointer to locked data buffer internal uint dwBufferLength; // length of data buffer internal uint dwBytesRecorded; // used for input only internal IntPtr dwUser; // for client's use internal uint dwFlags; // assorted flags (see defines) internal uint dwLoops; // loop control counter internal IntPtr lpNext; // reserved for driver internal IntPtr reserved; // reserved for driver } I need to allocate unmanaged memory to store an instance of above struct. A

Create unmanaged c++ object in c#

守給你的承諾、 提交于 2019-11-28 18:55:08
I have an unmanaged dll with a class "MyClass" in it. Now is there a way to create an instance of this class in C# code? To call its constructor? I tried but the visual studio reports an error with a message that this memory area is corrupted or something. Thanks in advance Alex F C# cannot create class instance exported from native Dll. You have two options: Create C++/CLI wrapper. This is .NET Class Library which can be added as Reference to any other .NET project. Internally, C++/CLI class works with unmanaged class, linking to native Dll by standard C++ rules. For .NET client, this C++/CLI

Managed C++ to form a bridge between c# and C++

回眸只為那壹抹淺笑 提交于 2019-11-28 18:02:10
I'm a bit rusty, actually really rusty with my C++. Haven't touched it since Freshman year of college so it's been a while. Anyway, I'm doing the reverse of what most people do. Calling C# code from C++. I've done some research online and it seems like I need to create some managed C++ to form a bridge. Use __declspec(dllexport) and then create a dll from that and use the whole thing as a wrapper. But my problem is - I'm really having a hard time finding examples. I found some basic stuff where someone wanted to use the C# version to String.ToUpper() but that was VERY basic and was only a