unmanaged

C# Export function dll

自古美人都是妖i 提交于 2019-12-11 12:18:46
问题 I use the Unmanaged-Exports package from Robert Giesecke, which can be found at (https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports). I'd like to export a function but somehow it doesn't work. The functions won't be exported. My approach: Code: [DllExport("test", CallingConvention = CallingConvention.StdCall)] public static string test() { return "Hello World, this is the DLL"; } Screenshot of my IDA results: As you can see they're empty because no function was

Wrapping unmanaged c++ in a managed wrapper

橙三吉。 提交于 2019-12-11 10:32:04
问题 I have an unmanaged C++ library. I would like to expose the functionality for .NET applications. There's one partucular function I am not sure how to handle: typedef void (free_fn*) (void*); void put (void *data, free_fn deallocation_function); The idea is that you pass dynamically allocated buffer to the function and supply a deallocation function. The library will process the data asynchronously and will release the buffer later on when data is no longer needed: void *p = malloc (100); ...

Conversion between managed and unmanaged types in C++?

我怕爱的太早我们不能终老 提交于 2019-12-11 09:07:16
问题 When I use a GUI in C++ the text fields are stored as managed strings, i think. I need a way to convert them to standard ints, floats and strings. Any help? 回答1: You can convert a System.String into an unmanaged char * using Marshal.StringToHGlobalAnsi. Make sure you free it when you're done by calling Marshal.FreeHGlobal. To convert the strings to numeric values, you can use the regular .NET parsing functions such as Int32.Parse . 回答2: To use managed memory in native code, you must copy the

Marshall char** to string problem calling unmanaged code from managed code

淺唱寂寞╮ 提交于 2019-12-11 06:54:16
问题 I've this C++ function, bool MyClass::my_function(int num, TCHAR** filepath) I've expose the function as extern "C" { __declspec(dllexport) bool MyFunction(int num, char* filepath[]) { OutputDebugStringA("--MyFunction--"); TCHAR **w_filepath = (TCHAR **)calloc(num, 2* sizeof(TCHAR **)); for(int i = 0; i < num; i++) { OutputDebugStringA(filepath[i]); int len = strlen(filepath[i]) + 1; w_filepath[i] = (TCHAR *)calloc (1, len); ctow(w_filepath[i], filepath[i]); // converts char to WCHAR } bool

How to consume COM object in ASP.NET class file

心不动则不痛 提交于 2019-12-11 06:46:21
问题 I have a COM object that I am trying to wrap in a C# class in order to make it more readily available for other applications that wish to consume it. I have the following code that creates an instance of the COM object, and then using reflection makes a call to a method to retrieve user data. This code works fine when it is located in an aspx page. object jdObj = Server.CreateObject("jd_api.UserCookie"); string username = jdObj.GetType().InvokeMember("GetUserName", System.Reflection

Passing Handle to a console app OR Managed/Unmanaged Help

巧了我就是萌 提交于 2019-12-11 06:36:16
问题 I'm having sleeping issues because of this! I have a VS2005 C# DLL that should communicate to a USB device under Labview. The C# DLL is mounted over a C++ Wrapper who's over a C++ (unmanaged) Project (not coded by me, but I own the code. btw. C++ and me, we're not best friends). Using this wrapper I can (under Windows/Visual Studio) do everything (connect, disconnect, send and receive data). The problem occurs under Labview. It connects, disconnects, send files but it doesn't receives(not

How to unload the default .NET AppDomain from an unmanaged application

烂漫一生 提交于 2019-12-11 06:00:08
问题 Is there a way to unload the default .NET AppDomain from an unmanaged application? I'm using a third party tool called .NET Extender for using .NET assemblies from within Visual FoxPro which allows me to host .NET controls and also make use of .NET classes and methods from within a FoxPro environment. The problem I'm having is that when debugging an application from within Visual FoxPro it runs the everything under the main vfp9.exe application file for the IDE and it appears that handles to

Automaticaly copy native dll to the bin folder of referencing project in Visual Studio

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 05:34:50
问题 I have some native dll which must be copied in the bin folder with platform conditions. And I want them to be copied to the bin folder of projects referencing this project. If I set the build action to Content , they will be copied to the bin folder but with the folder structure kept so they will not be in the bin folder but in sub folders. So when running the program, it will not be able to resolve the dll because they are in a subfolder. For example if I have this code in the project file

getting a byte array from a pinned object

心已入冬 提交于 2019-12-11 04:54:21
问题 It is possible to get a pointer from a managed array byte [] buffer = new byte[length + byteAlignment]; GCHandle bufferHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned); IntPtr ptr = bufferHandle.AddrOfPinnedObject(); is there any way to do the opposite. getting a byte array from a pinned object without copying? 回答1: Sure, that's what Marshal.Copy is for - there is no way (well, no way without copying of some variety) to otherwise get memory between the managed and unmanaged states...well,

Rewrite LockBits code without unsafe

倾然丶 夕夏残阳落幕 提交于 2019-12-11 04:19:58
问题 How to rewrite this code without unsafe modifier? var bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat); var size = Math.Abs(bmpData.Stride) * bitmap.Height; var stream = new UnmanagedMemoryStream((byte*)bmpData.Scan0, size)); 回答1: To get transparent highly efficient access to the bitmap data (faster than any copy technique with LockBits), you can use the following technique which does not require to mark the code as unsafe