unmanaged

Calling a C# function from unmanaged c++ (via a managed wrapper)

左心房为你撑大大i 提交于 2019-12-12 12:32:27
问题 I have C++ source & headers for a set of libraries which I need to call from a C# application. I've created a managed C++ wrapper around the functions I need and am able to call them from C# marshalling the data backwards and forwards. Now the hard part.. My unmanaged C++ library generates status messages as it runs and I'd like to be able to display these from the calling C# application. My current thinking goes like this: I'd like the unmanaged C++ library code to call a function in my C#

the correct technique for releasing a socket/event/ummaged code with the dispose/finalize pattern

依然范特西╮ 提交于 2019-12-12 10:35:21
问题 How to implement the Dispose pattern when my class contains a socket & event? Should it be something like this? class MyClass { Socket m_ListenerSocket = new Socket(); book m_Disposed=false; public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } private void Dispose(bool isDisposing) { if (!m_Disposed) { if (isDisposing) { if (m_ListenerSocket != null) { m_ListenerSocket.Dispose(); innerClass.Notify -= Notify; } } //finalized unmanged code here m_Disposed = true; } } ~MyClass() {

How do I combine an unmanaged dll and a managed assembly into one file?

旧巷老猫 提交于 2019-12-12 09:38:10
问题 SQLite from PHX Software has combined a managed assembly (System.Data.SQLite) with an unmanaged dll (the SQLite 32- or 64-bit dll) into one file, and managed to link them together. How do I do this? Do I need to embed the managed assembly into the unmanaged dll, or vice versa? ie. my questions are: In which order do I need to do this? What tools or knowledge do I need in order to do this? How (if different) do I link to the exported functions from the unmanaged dll in my managed code? The

how do i use the c++ dll in c#

谁说胖子不能爱 提交于 2019-12-12 09:03:05
问题 i like import c++ dll in my c# application how can i Do this?, what is concept i need to use for this? 回答1: suppose this DLL that compile with MinGW. in C-sharp you can follow this code: using System.Runtime.InteropServices; using System; class call_dll { [StructLayout(LayoutKind.Sequential, Pack=1)] private struct STRUCT_DLL { public Int32 count_int; public IntPtr ints; } [DllImport("mingw_dll.dll")] private static extern int func_dll( int an_int, [MarshalAs(UnmanagedType.LPArray)] byte[]

Best method of calling managed code(c#) from unmanaged C++

混江龙づ霸主 提交于 2019-12-12 08:55:00
问题 We have developed a s/w architecture consisting of set of objects developed in C#. They make extensive use of events to notify the client of changes in status, etc. The intention originally was to allow legacy code to use these managed objects through COM interop services. That was easy to write in the design specification but, I'm seeing that actually implementing it is more problematic. I've searched for many hours looking for a good sample of event handling using this method. Before we

Identifying a process or a module as managed/native [duplicate]

五迷三道 提交于 2019-12-12 03:05:01
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How do I determine if a Process is Managed in C#? How can I know if a process or a module is managed (.NET) or native programmatically (in C++)? 回答1: I don't have the PE spec handy - you can download it from msdn.com - but a managed module will typically have a CLR header and imports mscoree.dll. 来源: https://stackoverflow.com/questions/7880606/identifying-a-process-or-a-module-as-managed-native

Unexpected Stackoverflow exception using CLR in a dll

点点圈 提交于 2019-12-12 01:48:35
问题 I have a software that accepts a C dll as plugin. The dll export two functions: init and quit. To test how the plugin works, I wrote three projects after the NativeWrapper concept: a managed library in C++ (dll), a native wrapper in C++ (also dll, that exports the init and quit functions) and a C++ test program. For now I am just testing the init function. All these are built and run inside VS 2013 without any issue. However, When I plug the two dlls in with the said software, it stops

Proper Disposal of Unamanged Struct

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 19:59:59
问题 Hello this question is a continuation of this question. Provided below is a short version of the code that is loading the data into the structure. The HDF5DotNet library is found here using the 32 bit version with vs2015. My question is, will MyStruct leak memory when SomeCallerClass call HDF5GetSubGroups? using HDF5DotNet; namespace CommonClass { public class HDF5FileReader { public static List<string> HDF5GetSubGroups(string filePath) { var returnList = new List<string>(); //... some HDF5

PInvoke and IStream

◇◆丶佛笑我妖孽 提交于 2019-12-11 17:13:39
问题 I have an exported function from a dll written in c++ with the following signiture: Foo( LPSTREAM *pStream, UINT &Size ) that returns an memory stream and obviously its size. What I am having difficulties with is creating a signiture for the exported function and then attempting to read the stream in C#. At one point was able to use "unsafe" byte pointer to get the information, but this does not fit our requirements. Any thoughts, examples, samples etc would be greatly appreciated. 回答1: You

Memory leaks? in passing IEnumerable<byte[]> array to unmanaged function as byte** parameter

不打扰是莪最后的温柔 提交于 2019-12-11 15:08:51
问题 Is that the correct way to allocate and free handles to managed data passed to unmanaged dll? There is unmanaged dll with exported function void Function(byte** ppData, int N); I need to pass it IEnumerable<byte[]> afids var handles = afids.Select(afid => GCHandle.Alloc(afid, GCHandleType.Pinned)); var ptrs = handles.Select(h => h.AddrOfPinnedObject()); IntPtr[] afidPtrs = ptrs.ToArray(); uint N = (uint)afidPtrs.Length; Function(afidPtrs, N); handles.ToList().ForEach(h => h.Free()); I get