pinvoke

Difficulties with p/invoke and EnumDisplaySettingsEx

断了今生、忘了曾经 提交于 2021-01-29 04:25:32
问题 I am attempting to retrieve information on all the various monitors (and their adapters) present on a system. So far, my attempts at using EnumDisplayDevices to list all the monitors has worked great - it found two, the first being "\\.\DISPLAY1\Monitor0" (the second is just 2 and 1, respectively, but it's irrelevant to this question). Anyway, I then attempted to call EnumDisplaySettingsEx on it, passing the name of the monitor as above, but it always fails. Calls with a null name parameter

Difficulties with p/invoke and EnumDisplaySettingsEx

萝らか妹 提交于 2021-01-29 04:20:39
问题 I am attempting to retrieve information on all the various monitors (and their adapters) present on a system. So far, my attempts at using EnumDisplayDevices to list all the monitors has worked great - it found two, the first being "\\.\DISPLAY1\Monitor0" (the second is just 2 and 1, respectively, but it's irrelevant to this question). Anyway, I then attempted to call EnumDisplaySettingsEx on it, passing the name of the monitor as above, but it always fails. Calls with a null name parameter

c# DLLImport calling c++ method with char* as parameter

落花浮王杯 提交于 2021-01-28 19:08:29
问题 I got an external DLL (c++) with the follwing method: void _stdcall Set_Config(char* config) I use the following c# code to call the method: [DllImport(DllName,CharSet=CharSet.Auto)] public static extern void Set_Config(String config); But when i execute my c# code i get either an acces violation exception or an System.Runtime.InteropServices.SEHException. (My dll is 32 bit, and my c# compiler compiles to 32 bit) I also tried to replace String config with Stringbuilder, but the same result.

Is there an enumeration for system error codes in .Net framework?

自闭症网瘾萝莉.ら 提交于 2021-01-26 20:37:27
问题 I have a library function that returns GetLastError codes (things like these). I need to compare them with specific errors, like ERROR_INVALID_HANDLE . However I don't feel comfortable to define the constants myself. So the question is, is there a predefined enumeration for this purpose? 回答1: No, you'll have to make your own. 回答2: I published a NuGet package for this: Install-Package BetterWin32Errors First add a using for the library: using BetterWin32Errors; Then you can use it like this:

Is there an enumeration for system error codes in .Net framework?

不羁岁月 提交于 2021-01-26 20:36:20
问题 I have a library function that returns GetLastError codes (things like these). I need to compare them with specific errors, like ERROR_INVALID_HANDLE . However I don't feel comfortable to define the constants myself. So the question is, is there a predefined enumeration for this purpose? 回答1: No, you'll have to make your own. 回答2: I published a NuGet package for this: Install-Package BetterWin32Errors First add a using for the library: using BetterWin32Errors; Then you can use it like this:

How to pass function pointer from C# to a C++ Dll?

杀马特。学长 韩版系。学妹 提交于 2021-01-21 07:59:44
问题 The function defined in C++ dll is: static double (*Func1)(double); EXTERN_C __declspec(dllexport) __stdcall double TestDelegate(double (*fun)(double)) { Func1 = fun; return Func1(25.0); } void My_Real_purpose() { SomeClass a; a.SetFunction(Func1);//Define behaviour of a by C# in runtime a.DoSomething();//Even I want it runs in another thread! } And I tried to call it in C# like this: class A { [DllImport("DllName.dll")] public extern static double TestDelegate(IntPtr f); public delegate

How to pass function pointer from C# to a C++ Dll?

a 夏天 提交于 2021-01-21 07:58:25
问题 The function defined in C++ dll is: static double (*Func1)(double); EXTERN_C __declspec(dllexport) __stdcall double TestDelegate(double (*fun)(double)) { Func1 = fun; return Func1(25.0); } void My_Real_purpose() { SomeClass a; a.SetFunction(Func1);//Define behaviour of a by C# in runtime a.DoSomething();//Even I want it runs in another thread! } And I tried to call it in C# like this: class A { [DllImport("DllName.dll")] public extern static double TestDelegate(IntPtr f); public delegate

Can I simplify method signatures I am not using in a ComImport?

℡╲_俬逩灬. 提交于 2020-12-06 19:27:12
问题 I am trying to call GetImageDlg on IWiaDevMgr2 . There are a number of quite complicated methods (which I am not using) referencing a number of types (that I am also not using). As I cannot find a TLB or an IDL from which to automatically generate my ComImport , I would prefer to avoid having to manually translate all of the referenced types. Can I "skip" methods and types by substituting from [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("79C07CF1-CBDD-41ee-8EC3-F00080CADA7A")]

Can I simplify method signatures I am not using in a ComImport?

☆樱花仙子☆ 提交于 2020-12-06 19:26:57
问题 I am trying to call GetImageDlg on IWiaDevMgr2 . There are a number of quite complicated methods (which I am not using) referencing a number of types (that I am also not using). As I cannot find a TLB or an IDL from which to automatically generate my ComImport , I would prefer to avoid having to manually translate all of the referenced types. Can I "skip" methods and types by substituting from [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("79C07CF1-CBDD-41ee-8EC3-F00080CADA7A")]

Can I simplify method signatures I am not using in a ComImport?

一曲冷凌霜 提交于 2020-12-06 19:26:53
问题 I am trying to call GetImageDlg on IWiaDevMgr2 . There are a number of quite complicated methods (which I am not using) referencing a number of types (that I am also not using). As I cannot find a TLB or an IDL from which to automatically generate my ComImport , I would prefer to avoid having to manually translate all of the referenced types. Can I "skip" methods and types by substituting from [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("79C07CF1-CBDD-41ee-8EC3-F00080CADA7A")]