unmanaged

pass unmanaged C++ method to C# dll for callback

一世执手 提交于 2019-12-10 10:43:49
问题 I have a .Net dll which I have registered and am able to call methods on from my C# code. I essentially followed this tutorial: http://support.microsoft.com/kb/828736 now I need to do something in c# asynchronously, so I need some way of telling the c++ code that I am done. I have created a method like so: public void Init(string server, IntPtr callback); which I can see in the c++ as: Init(BSTR server, long callback); I also need to pass a variable back to the c++ code when I make invoke it.

Why does my multithreaded C++ .NET application only crash when executed outside of visual studios?

旧巷老猫 提交于 2019-12-10 10:26:05
问题 I have created a very simple C++ .NET application using both managed and unmanaged code to replicate my problem. When the user clicks a button a new thread should spawn and do some time-consuming tasks while calling back to my main thread with status updates. This code compiles and successfully executes from within side of Visual Studios Express 2010. That is, when I click the "play" button, my project builds and executes without crashing. However, if I go to the Release folder where the

Create DLL from unmanaged C++

China☆狼群 提交于 2019-12-10 05:07:36
问题 I currently have a console application written in unmanaged C++, the source code consists of an entry-point main and some other functions. I need to create a DLL from this code so that I can use it from other projects, specifically from managed C++. (Another question: would I have to write a wrapper class for this purpose?) As I know next to nothing of managed/unmanaged C++ and creating DLLs, I followed this tutorial and managed to get a simple Hello World DLL up and running by using only

Passing struct from unmanaged C++ to C#

為{幸葍}努か 提交于 2019-12-10 02:33:48
问题 Note: The final working solution is after the edit! I hope someone can help me with a problem I've been trying to solve for the last few days. I am trying to pass a struct from a unmanaged C++ DLL to a C# script. This is what I have so far: C++ EXPORT_API uchar *detectMarkers(...) { struct markerStruct { int id; } MarkerInfo; uchar *bytePtr = (uchar*) &MarkerInfo; ... MarkerInfo.id = 3; return bytePtr; } C# [DllImport ("UnmanagedDll")] public static extern byte[] detectMarkers(...); ...

Calling unmanaged code from .NET

自作多情 提交于 2019-12-09 21:43:40
问题 I am trying to use a dll in my c# program but I just cant seem to get it to work. I have made a test app shown below. The return value is 0, however it does not actually do what it is supposed to do. Whereas the following command does work: rundll32 cmproxy.dll,SetProxy /source_filename proxy-1.txt /backup_filename roxy.bak /DialRasEntry NULL /TunnelRasEntry DSLVPN /Profile "C:\Documents and ettings\Administrator\Application Data\Microsoft\Network\Connections\Cm\dslvpn.cmp" Code: using System

How can I embed an unmanaged C++ form into a .NET application?

折月煮酒 提交于 2019-12-09 06:27:26
问题 I have been able to successfully wrap my unmanaged Borland C++ dll, and launch it's forms from a C# .NET 4.0 application. Is it possible to embed a form from the dll directly into a .NET application? To clarify, the original form is being used as an embedded control in a Borland C++ project already. It essentially looks like a custom control, sitting on a panel within the application. When I say 'embed' I mean place INTO a form in the same way you drop buttons, panels, etc on to a form. I'm

Passing objects between C# and C

拜拜、爱过 提交于 2019-12-09 01:26:28
问题 My application consist of C# code with unmanaged C dll calls. In my C# code I have an object/class where its properties are both system types such as string and int and other objects I have defined. I would like to pass this complex (Graph.cs) object to my C (dll) code, what implementation would you suggest here? I have tried moving structs but I fail to do so with anything other then string and int. Thanks. Code: public Class Grpah { TupleCollection m_TupleCollection; int m_nGeneralIndex;

How do I properly return a char * from an Unmanaged DLL to C#?

随声附和 提交于 2019-12-09 01:02:09
问题 Function signature: char * errMessage(int err); My code: [DllImport("api.dll")] internal static extern char[] errMessage(int err); ... char[] message = errMessage(err); This returns an error: Cannot marshal 'return value': Invalid managed/unmanaged type combination. What am I doing wrong? Thanks for any help. 回答1: try this: [DllImport("api.dll")] [return : MarshalAs(UnmanagedType.LPStr)] internal static extern string errMessage(int err); ... string message = errMessage(err); I believe C# is

How to use managed code from unmanaged code?

蹲街弑〆低调 提交于 2019-12-09 00:04:43
问题 How do I call a .NET code from native C++ (unmanaged code)? I want to expose .NET code to my unmanaged (C++) application and then use them. More specifically, I want to call C# from native C++ :). I know there are many ways but can you tell me the pros and cons of each? By the way, I don't want to use COM so what are the options now? Is it possible that I wrap the C# code in C++/CLI and then call it from C++? If so, how do I do that? How do I wrap the C# in C++/CLI and then call it from C++?

How to use extern “C” dll function taking char** as an argument in C# application?

杀马特。学长 韩版系。学妹 提交于 2019-12-08 11:21:55
问题 I have dll with function: extern "C" int doJob(char** buffer); Its usage with C++ looks like this: char* buf; int status = doJob(&buf); What definition should I have for this function in C#? How can I use this function in C#? 回答1: One of the possible patterns is: [DllImport("containsdojob.dll", CallingConvention = CallingConvention.Cdecl)] public static extern Int32 doJob(out IntPtr buffer); [DllImport("containsdojob.dll", CallingConvention = CallingConvention.Cdecl)] public static extern