unmanaged

Access Violation with unmanaged DLL

扶醉桌前 提交于 2020-01-25 04:48:04
问题 Currently, we use an unmanaged DLL from a vendor that allows us to access a particular instrument. The particular function of interest is specified in a header file as this: extern "C" short CCONV acq_get_board_count (); In my application, I have the pinvoke statement: public class bograms { [DllImport("bograms.dll", EntryPoint = "acq_get_board_count", CallingConvention = CallingConvention.StdCall)] public static extern short acq_get_board_count(); } Now, in my code I am attempting to handle

Marshalling C dll code into C#

一世执手 提交于 2020-01-23 12:13:14
问题 I have the following C-code signature in a dll: extern __declspec(dllexport) unsigned char * funct_name (int *w, int *h, char **enc, int len, unsigned char *text, int *lp, int *mp, int *ep) The C function can modify w, h, enc, lp, mp, and ep (though the latter three can be null and it won't do anything. I'm using the following in C# [DllImport("iec16022ecc200.dll", EntryPoint = "iec16022ecc200", ExactSpelling = false, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention

Calling unmanaged function from C#: should I pass StringBuilder or use unsafe code?

爱⌒轻易说出口 提交于 2020-01-23 06:31:08
问题 I've got a C# program that needs to pass a char buffer to an unmanaged function. I've found two ways that seem to work reliably, but I'm not sure which I should choose. Here's the unmanaged function's signature. extern "C" __declspec(dllexport) int getNextResponse(char *buffer); The first option is to define the buffer as a StringBuilder, as follows. //at class level... [DllImport("mydll.dll")] static extern int getNextResponse(StringBuilder buffer); //in main method body... StringBuilder sb

.NET System::String to UTF8-bytes stored in char*

天涯浪子 提交于 2020-01-20 06:23:03
问题 I am wrapping some unmanaged C++ code inside a .NET project. For this I need to convert System::String to UTF8-bytes stored in char* . I am unsure if this is the best or even a correct way to do this and I'd appreciate if someone could take a look and provide feedback. Thanks, /David // Copy into blank VisualStudio C++/CLR command line solution. #include "stdafx.h" #include <stdio.h> using namespace System; using namespace System::Text; using namespace System::Runtime::InteropServices; //

.NET System::String to UTF8-bytes stored in char*

不问归期 提交于 2020-01-20 06:21:13
问题 I am wrapping some unmanaged C++ code inside a .NET project. For this I need to convert System::String to UTF8-bytes stored in char* . I am unsure if this is the best or even a correct way to do this and I'd appreciate if someone could take a look and provide feedback. Thanks, /David // Copy into blank VisualStudio C++/CLR command line solution. #include "stdafx.h" #include <stdio.h> using namespace System; using namespace System::Text; using namespace System::Runtime::InteropServices; //

.NET System::String to UTF8-bytes stored in char*

为君一笑 提交于 2020-01-20 06:20:15
问题 I am wrapping some unmanaged C++ code inside a .NET project. For this I need to convert System::String to UTF8-bytes stored in char* . I am unsure if this is the best or even a correct way to do this and I'd appreciate if someone could take a look and provide feedback. Thanks, /David // Copy into blank VisualStudio C++/CLR command line solution. #include "stdafx.h" #include <stdio.h> using namespace System; using namespace System::Text; using namespace System::Runtime::InteropServices; //

How do I find out if a .NET assembly contains unmanaged code?

一曲冷凌霜 提交于 2020-01-19 13:37:28
问题 .NET assemblies that contain a mixture of managed and unmanaged code cannot be ILMerged with other assemblies. How can I verify if a given .NET assembly contains purely managed code, or a mix of managed and unmanaged code? 回答1: Run the PEVerify tool against your assembly. PEVerify.exe is installed along with Visual Studio, e.g. this one comes with Visual Studio 2012: C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\PEVerify.exe 回答2: As suggested by nobugz, an easier way

How do I find out if a .NET assembly contains unmanaged code?

会有一股神秘感。 提交于 2020-01-19 13:37:07
问题 .NET assemblies that contain a mixture of managed and unmanaged code cannot be ILMerged with other assemblies. How can I verify if a given .NET assembly contains purely managed code, or a mix of managed and unmanaged code? 回答1: Run the PEVerify tool against your assembly. PEVerify.exe is installed along with Visual Studio, e.g. this one comes with Visual Studio 2012: C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\PEVerify.exe 回答2: As suggested by nobugz, an easier way

Concatenating a string and byte array in to unmanaged memory

老子叫甜甜 提交于 2020-01-16 18:30:27
问题 This is a followup to my last question. I now have a byte[] of values for my bitmap image. Eventually I will be passing a string to the print spooler of the format String.Format("GW{0},{1},{2},{3},", X, Y, stride, _Bitmap.Height) + my binary data; I am using the SendBytesToPrinter command from here. Here is my code so far to send it to the printer public static bool SendStringPlusByteBlockToPrinter(string szPrinterName, string szString, byte[] bytes) { IntPtr pBytes; Int32 dwCount; // How

Concatenating a string and byte array in to unmanaged memory

*爱你&永不变心* 提交于 2020-01-16 18:30:07
问题 This is a followup to my last question. I now have a byte[] of values for my bitmap image. Eventually I will be passing a string to the print spooler of the format String.Format("GW{0},{1},{2},{3},", X, Y, stride, _Bitmap.Height) + my binary data; I am using the SendBytesToPrinter command from here. Here is my code so far to send it to the printer public static bool SendStringPlusByteBlockToPrinter(string szPrinterName, string szString, byte[] bytes) { IntPtr pBytes; Int32 dwCount; // How