pinvoke

SetCurrentConsoleFontEx isn't working for long font names

做~自己de王妃 提交于 2021-02-07 06:41:45
问题 I can't get this to work for font names that are 16 characters or longer, but the console itself obviously doesn't have this limitation. Does anyone know a programmatic way to set the font that will work with the built-in "Lucida Sans Typewriter" or the open source "Fira Code Retina"? This following code works: I have copied PInvoke code from various places, particularly the PowerShell console host, and the Microsoft Docs Note that the relevant docs for CONSOLE_FONT_INFOEX and

P/Invoke or C++/CLI for wrapping a C library

风格不统一 提交于 2021-02-05 13:37:48
问题 Have a moderate size (40-odd function) C API that needs to be called from a C# project. The functions logically break up to form a few classes that will be API presented to the rest of the project. Are there any objective reasons to prefer P/Invoke or C++/CLI for the interoperability underneath that API, in terms of robustness, maintainability, deployment, ...? The issues I could think of that might be, but aren't problematic are: C++/CLI will require an separate assembly, the P/Invoke

How to pin memory allocated by Marshal.AllocHGlobal() in C#?

 ̄綄美尐妖づ 提交于 2021-02-05 11:22:10
问题 How do you pin memory allocated by Marshal.AllocHGlobal()? My first attempt was the following: int bytes = 10; IntPtr ip = Marshal.AllocHGlobal(bytes); GCHandle iph = GCHandle.Alloc(ip, GCHandleType.Pinned); Although I think this only pins the IntPtr and not the block of memory referred to by the IntPtr . 回答1: The memory allocated by AllocHGlobal is already pinned. the IntPtr that is returned is the address of the pinned location. UPDATE: To be pedantic you can't actually "pin" the memory

C# : Pass int array to c++ dll

梦想的初衷 提交于 2021-02-05 08:00:07
问题 I have a C++ dll which is used to card printing( ID cards ). My implementation done using C#.Net. I used following code to call c++ dll. [DllImport(@"J230i.dll",CallingConvention = CallingConvention.Cdecl,SetLastError=true)] public static extern int N_PrintJobStatus(ref int[] nPrtintjobStatus); int[] pJob = {0,0,0,0,0,0,0,0} ; ret = N_PrintJobStatus( ref pJob); N_PrintJobStatus method signature given as bellow N_PrintJobStatus(int *pJobStatus ) After calling the method it gives following

Invalid Managed/Unmanaged Type Combination With Embedded, Dynamically-Allocated Array

随声附和 提交于 2021-02-05 07:09:48
问题 I have a common construct in an unmanaged Win32 C++ DLL: // FirstElemPtrContainer.h #include "stdafx.h" typedef unsigned char elem_type; // a byte typedef struct FirstElemPtrContainer { unsigned char num_elems; void *allocd_ary; } FirstElemPtrContainer; The void* in the struct is meant to contain a pointer to the first element of an allocated byte array. The DLL that uses this definition then exports functions to allocate, populate, and deallocate the struct: // The exported allocator

Invalid Managed/Unmanaged Type Combination With Embedded, Dynamically-Allocated Array

回眸只為那壹抹淺笑 提交于 2021-02-05 07:09:32
问题 I have a common construct in an unmanaged Win32 C++ DLL: // FirstElemPtrContainer.h #include "stdafx.h" typedef unsigned char elem_type; // a byte typedef struct FirstElemPtrContainer { unsigned char num_elems; void *allocd_ary; } FirstElemPtrContainer; The void* in the struct is meant to contain a pointer to the first element of an allocated byte array. The DLL that uses this definition then exports functions to allocate, populate, and deallocate the struct: // The exported allocator

Invalid Managed/Unmanaged Type Combination With Embedded, Dynamically-Allocated Array

冷暖自知 提交于 2021-02-05 07:06:29
问题 I have a common construct in an unmanaged Win32 C++ DLL: // FirstElemPtrContainer.h #include "stdafx.h" typedef unsigned char elem_type; // a byte typedef struct FirstElemPtrContainer { unsigned char num_elems; void *allocd_ary; } FirstElemPtrContainer; The void* in the struct is meant to contain a pointer to the first element of an allocated byte array. The DLL that uses this definition then exports functions to allocate, populate, and deallocate the struct: // The exported allocator

How to get content of array from C++ dll in C#

喜夏-厌秋 提交于 2021-02-05 05:54:05
问题 I want to use functions from DLL in C++ with C#. I store string data in a vector. My C++ file contains: #include "stdafx.h" #include <stdlib.h> #include <stdio.h> #include <string.h> extern "C" __declspec(dllexport) std::vector<std::string> GetProduct(); std::vector<std::string> GetProduct() { std::vector<std::string> vectProduct; vectProduct.push_back("Citroen"); vectProduct.push_back("C5"); vectProduct.push_back("MOP-C5"); return vectProduct; } In C# using System; using System.Collections

Call Java Method from API in .NET

老子叫甜甜 提交于 2021-02-04 15:09:18
问题 I have a Java API in jar file with some dependencies from other jar files. Is there any way to call a specific method from this API, like using PInvoke from .NET? 回答1: Here you go :) I've used it myself and was very please with the implementation. IKVM: Using Java API's in .NET Applications (1) If you just want some libraries from Java. (2.1) If you have access to the code. (2.2) Last resort, dynamically load the Java into .Net (interpreter) 回答2: I don't think it will be an easy task to

Call Java Method from API in .NET

夙愿已清 提交于 2021-02-04 15:07:57
问题 I have a Java API in jar file with some dependencies from other jar files. Is there any way to call a specific method from this API, like using PInvoke from .NET? 回答1: Here you go :) I've used it myself and was very please with the implementation. IKVM: Using Java API's in .NET Applications (1) If you just want some libraries from Java. (2.1) If you have access to the code. (2.2) Last resort, dynamically load the Java into .Net (interpreter) 回答2: I don't think it will be an easy task to