unmanaged

How to get unmanaged variable-length C-array within a struct from C to C#?

自作多情 提交于 2019-12-08 07:49:06
问题 How do I return the MIB_IPFORWARDROW array? struct MIB_IPFORWARDTABLE { public uint Size; [MarshalAs(/* what goes here? */)] public IPFORWARDROW[] Table; }; [DllImport("iphlpapi", CharSet = CharSet.Auto)] private static extern int GetIpForwardTable( IntPtr /* MIB_IPFORWARDTABLE* */ pIpForwardTable, ref uint /* ULONG* */ pdwSize, bool bOrder); public static MIB_IPFORWARDROW[] Temp() { var fwdTable = IntPtr.Zero; uint size = 0; var result = GetIpForwardTable(fwdTable, ref size, true); fwdTable

ERROR_MORE_DATA — PVOID and C# — Unmanaged types

微笑、不失礼 提交于 2019-12-08 06:31:08
问题 How can I get the value from the following DLL? offreg.dll. In my below code, I have successfully opened the hive, the key and now I am trying to get the value of the key and I keep running into the ERROR_MORE_DATA (234) error. Here is the C++ .dll: DWORD ORAPI ORGetValue ( __in ORHKEY Handle, __in_opt PCWSTR lpSubKey, __in_opt PCWSTR lpValue, __out_opt PDWORD pdwType, __out_bcount_opt(*pcbData) PVOID pvData, __inout_opt PDWORD pcbData ); Here is my C# code: [DllImport("offreg.dll", CharSet =

Default Printer in Unmanaged C++

…衆ロ難τιáo~ 提交于 2019-12-08 05:04:36
问题 I'm looking for a way to find the name of the Windows default printer using unmanaged C++ (found plenty of .NET examples, but no success unmanaged). Thanks. 回答1: The following works great for printing with the win32api from C++ char szPrinterName[255]; unsigned long lPrinterNameLength; GetDefaultPrinter( szPrinterName, &lPrinterNameLength ); HDC hPrinterDC; hPrinterDC = CreateDC("WINSPOOL\0", szPrinterName, NULL, NULL); In the future instead of googling "unmanaged" try googling "win32

passing a HANDLE variable to an unmanaged .dll in C++/CLI

烈酒焚心 提交于 2019-12-08 04:57:26
问题 I am trying to wrap an unmanaged c++ dll that talks to a video capture card in c++/CLI so i can reference the functions from a c# project that i have. I am having trouble getting the 1st wrapped call to work as I am new to c++/cli syntax. here is what i have. here is the function declataion i am trying to wrap. __declspec(dllimport) BOOL AZ_DeviceCreate(HANDLE& hLiveEvent, DWORD* hEncoderEvent, DWORD* pdwEncoderAddress, HANDLE& hAudioEvent, DWORD& dwAudioAddress); here is my c++/cli .h file

How to debug System.ExecutionEngineException in a framework code of a managed application

╄→尐↘猪︶ㄣ 提交于 2019-12-08 03:52:48
问题 I have an application running as service. The application crashes time to time. The application is written in vb.net and runs its tasks at new thread (one at time). I have collected crash dumps and started analyzing. From analyze of log file created by the application (analysis of dump supports it) it seems that a crash occurs when no task is running and application is waiting for a next System.Timers.Timer event. First I loaded a .dmp file to VS2010: Process Architecture: x86 Exception Code:

Unmanaged Exports with Arrays

為{幸葍}努か 提交于 2019-12-08 00:55:28
问题 I'm using RGiesecke DLLExport library to produce a C# DLL that can be dynamically loaded from Delphi. I have a method like: [DllExport("GetVals", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)] static void GetVals([In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] valueList, int len) { valueList = new int[3]; int[] arrList = new int[] { 1, 2, 3 }; int idx = 0; foreach (int s in arrList) { valueList[idx] = s; idx++; } } I want to be able to

Is it possible to have Code Analysis warnings formatted like normal ones?

淺唱寂寞╮ 提交于 2019-12-07 22:01:09
问题 I like the code analysis included in VS2012. But it's a bit annoying that the warnings are only processable in the Code Analysis window, and not by stepping through the build output with F4 . Is there a way to overcome this limitation? How could I format the output of the static code analysis like normal compiler output (i.e. don't only print the filename but the correct path to the file being inspected)? I'm not using FxCop since I'm working with unmanaged code. 回答1: For unmanaged code

How is a securestring marshalled to unmanaged code?

ぃ、小莉子 提交于 2019-12-07 20:48:36
问题 What prompted this question: I'm trying to change the account under which a windows service runs. I decided to use the win32 api rather than WMI and started looking at ChangeServiceConfig. I thought I could simply use the SecureString type in the unmanaged method signature and it would work fine. Hmmm, not quite. This made me wonder, does anyone know what native (win32) type the SecureString class is marshalled as (by default) to unmanaged code? 回答1: I never got an answer to the question in

Interop with unmanaged code in ASP.net vNext

断了今生、忘了曾经 提交于 2019-12-07 18:44:01
问题 What's the story going to be (if any) around interop with unmanaged code for ASP.net vNext / Core CLR? The key bits (DllImport and friends) appear to be present to allow for unmanaged code interop, but how would things such as packaging and deployment work in this context? The basic build artifact in vNext / CoreFX no longer appears to be an assembly, but a NuGet package. So in that case, how would we make the new project.json system work so that unmanaged dlls that we're P/Invoking into are

Is this .tlh file correct, and if not, then how do I generate the correct one?

蓝咒 提交于 2019-12-07 13:44:25
问题 I am trying to call a .NET 4.0 dll from unmanaged C++ code. I followed the instructions in this Code Project article by Atul Mani. I built the .NET dll, and followed all the steps up to and including registering it with regasm. Next, I created an unmanaged C++ project and added this line at the start of the .cpp file: #import "D:\PathToMyCSharpProject\bin\Debug\com.DeviceServices.tlb" rename ("EOF","adoEOF") no_namespace named_guids raw_interfaces_only When I built the C++ project, a .tlh