unmanaged

Unload a .NET DLL from an unmanaged process

情到浓时终转凉″ 提交于 2019-11-27 15:43:15
问题 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

Is it possible to catch an access violation exception in .NET?

风格不统一 提交于 2019-11-27 13:29:59
Is there anything I can do to catch an AccessViolationException ? It is being thrown by a unmanaged DLL that I don't control. You shouldn't. An access violation is a serious problem: it is an unexpected attempt to write to (or read from) an invalid memory address. As John already clarified, the unmanaged DLL might already have corrupted the process memory before the access violation has been raised. This can have unpredicted effects on any part of the current process. The safest thing to do is to possibly inform the user and then immediately exit. Some more details: An access violation is an

C++/CLI Support in .Net Core

泪湿孤枕 提交于 2019-11-27 13:04:46
问题 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

Create unmanaged c++ object in c#

浪尽此生 提交于 2019-11-27 11:47:26
问题 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 回答1: 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

How do I add a reference to an unmanaged C++ project called by a C# project?

痞子三分冷 提交于 2019-11-27 11:47:18
One solution (the.sln) One C++ project (mycppproject.vcxproj in 2010or mycppproject.vcproj in 2008) which compiles a native DLL exporting some function(s). In debug this builds c:\output\Debug\mycppproject_d.dll and in release this builds c:\output\Release\mycppproject.dll. One C# console application (mycsharpconsole.csproj) containing PInvoke calls into the DLL. All compiles fine. When I build, I would like to be able to add a reference from the csharp project to the cpp DLL project so that it can copy the appropriate file from the appropriate directory into the \bin\Debug directory the

Is there a tool that generates P/Invoke signatures for arbitrary unmanaged DLL?

99封情书 提交于 2019-11-27 09:59:59
问题 I stumbled upon a tool that generates P/Invoke signatures for Microsoft's own unmanaged DLLs: PInvoke Interop Assistant Is there a similar tool that will generate P/Invoke signatures for third-party unmanaged DLLs? Alternately, any way to feed a third-party DLL to PInvoke Interop Assistant EDIT: Actual issue I am trying to resolve 回答1: Google quickly found http://www.pinvoker.com/ (Compatiblity listed as VS2005, 2008, and 2010; it doesn't seem to have been updated to work with newer versions)

How to separate managed and unmanaged DLLs in another directory

你离开我真会死。 提交于 2019-11-27 09:37:09
My Release folder is: MyApp.exe MyManagedDLL.dll NativeDLL.dll MyApp uses the managed dll which calls with pinvoke the native dll. I tried to move them to another subfolder folder and I referenced the managed dll again, when I run my app it says it can't find the NativeDLL.dll. How to fix that? Windows has no idea that it needs to look in a subdirectory for the DLL. It will only look in a select few places for the DLL, starting from the folder that contains the EXE. Giving it a hard time like that it not very productive. But you can help it by pinvoking SetDllDirectory(). Keep in mind that

Marshaling – what is it and why do we need it?

巧了我就是萌 提交于 2019-11-27 09:12:05
问题 What is marshalling and why do we need it? I find it hard to believe that I cannot send an int over the wire from C# to C and have to marshall it. Why can't C# just send the 32 bits over with a starting and terminating signal, telling C code that it has received an int ? If there are any good tutorials or sites about why we need marshalling and how to use it, that would be great. 回答1: Because different languages and environments have different calling conventions, different layout conventions

Using C# extension methods from managed C++/CLI

跟風遠走 提交于 2019-11-27 07:38:58
问题 Forgive me if my terminology is a little off. My knowledge of managed C++/CLI is very limited. I have an MFC application that uses a dll with the /clr option enabled. This dll uses a couple of C# dlls to communicate with a server using WCF. For the most part this works fine. In one of the C# dlls, I've added an extension method to the System.Net.IPAddress class that will retrieve the subnet mask for the IPAddress object (using the UnicastIPAddressInformation class and its IPv4Mask). The

How can I convert an unmanaged IntPtr type to a c# string?

只谈情不闲聊 提交于 2019-11-27 06:36:42
问题 I'm new to C# (from a native C++ background) and I'm trying to write a little UI to print windows broadcast messages among other things. I've overridden the default WndProc message loop in my C# program like so: [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] protected override void WndProc(ref Message m) { // Listen for operating system broadcasts. switch (m.Msg) { case WM_SETTINGCHANGE: this.richTextLog.Text += "WM