pinvoke

Unable to find an entry point when calling C++ dll in C#

独自空忆成欢 提交于 2020-01-01 04:05:27
问题 I am trying to learn P/Invoke, so I created a simple dll in C++ KingFucs.h: namespace KingFuncs { class KingFuncs { public: static __declspec(dllexport) int GiveMeNumber(int i); }; } KingFuns.cpp: #include "KingFuncs.h" #include <stdexcept> using namespace std; namespace KingFuncs { int KingFuncs::GiveMeNumber(int i) { return i; } } So it does compile, then I copied this dll into my WPF's debug folder, with code: [DllImport("KingFuncDll.dll", EntryPoint = "GiveMeNumber", SetLastError = true,

Triggering event in C# from C++ DLL

末鹿安然 提交于 2020-01-01 03:18:05
问题 I have an umanaged C++ DLL which is communicating with a Cisco Server (UCCX). It sends and receives messages to and from this server via TCP/IP. Now there are some types of messages it receives which contains some parameters which it needs to send to a C# GUI which will display these parameters on screen. Please tell me an efficient method to trigger an event in C# from this DLL. 回答1: http://blogs.msdn.com/b/davidnotario/archive/2006/01/13/512436.aspx seems to answer your question. You use a

How to solve Private bytes (Native memory) leak?

自作多情 提交于 2020-01-01 02:44:08
问题 I'm developing a C# application which seems to have a leak. I've used memory profiler and found that my private bytes keep increasing but Bytes in all Heaps do not, which means that probably it's a native memory leak Now I'm stuck, how do I find memory leaks in native code ? 回答1: First, if you have a dump of the leaking process, you can open it in WinDbg and issue the command : !address -summary if RegionUsageHeap is large, then it should be a native memory leak if RegionUsageIsVAD, then it

Use XGBoost DLL from c# via p/invoke

倾然丶 夕夏残阳落幕 提交于 2019-12-31 07:15:12
问题 I'm trying to use XGBoost's dll (libxgboost.dll) to create a DMatrix (which is like a 2D array) and get how many columns it has. It runs fine until it throws a System.AccessViolationException at the int cols = ... line in the code below: using System; using System.Runtime.InteropServices; namespace basicXgboost { class Program { [DllImport("../../libs/libxgboost.dll", CharSet = CharSet.Auto)] public static extern int XGDMatrixCreateFromFile([MarshalAs(UnmanagedType.LPStr)] string file, int

C# p/Invoke How to simulate a keyPRESS event using SendInput for DirectX games

北城余情 提交于 2019-12-31 06:57:33
问题 I've often struggled with simulating keyboard press events for various bots, or other GUI automating programs. I've managed to simulate keydown events using: INPUT[] kInput = new INPUT[1]; kInput[j].type = SendInputEventType.InputKeyboard; kInput[j].mkhi.ki.wVk = 0; kInput[j].mkhi.ki.wScan = (ushort) MapVirtualKey((uint) Keys.D5, 0); kInput[j].mkhi.ki.dwFlags = KeyboardEventFlags.SCANCODE; kInput[j].mkhi.ki.time = 0; kInput[j].mkhi.ki.dwExtraInfo = IntPtr.Zero; SendInput(1, kInput, Marshal

Unable to get free disk space from Metro-style app

拜拜、爱过 提交于 2019-12-31 05:12:33
问题 I am writting a Metro-style app and want to determine the available storage capacity of the drive that hosts the user's music library. I want to disable some app functions while there's no or little space left on the disk. I am Using P/Invoke to call GetDiskFreeSpaceExW and get errors and no valid byte counts. [DllImport("kernel32.dll", SetLastError = true)] static extern bool GetDiskFreeSpaceExW( string lpDirectoryName, out ulong lpFreeBytesAvailable, out ulong lpTotalNumberOfBytes, out

Get tooltips text from C# with PInvoke

我的梦境 提交于 2019-12-31 04:25:05
问题 I'm using PInvoke in C#, trying to read tooltips visible in a window with a known handler, but the apps who's windows I try to inspect in this manner crash with memory access violation errors, or simply don't reveal the tooltip text in the lpszText TOOLINFO member. I'm calling EnumWindows with a callback and then sending a message to the tooltip window in that function: public delegate bool CallBackPtr(IntPtr hwnd, IntPtr lParam); static void Main(string[] args) { callBackPtr = new

C#: Marshalling a “pointer to an int array” from a SendMessage() lParam

一笑奈何 提交于 2019-12-31 04:17:53
问题 I'm trying to subclass an unmanaged statusbar window from my managed COM server using a class inherited from NativeWindow, and am running into a wall trying to make sense of how to properly marshal the contents of an lParam. http://msdn.microsoft.com/en-us/library/bb760757%28VS.85%29.aspx says that the contents of this lParam is of type (LPARAM)(LPINT) aWidths , and that the contents of this variable is actually a "pointer to an integer array." I can't figure out a way to marshal this

Disable Aero Peek in WPF application

心不动则不痛 提交于 2019-12-30 09:39:49
问题 I want to disable Aero Peek in my WPF application (my application must be visible when user placed the mouse over the button "Show desktop"). I use this PInvoke signature: [Flags] public enum DwmWindowAttribute : uint { DWMWA_NCRENDERING_ENABLED = 1, DWMWA_NCRENDERING_POLICY, DWMWA_TRANSITIONS_FORCEDISABLED, DWMWA_ALLOW_NCPAINT, DWMWA_CAPTION_BUTTON_BOUNDS, DWMWA_NONCLIENT_RTL_LAYOUT, DWMWA_FORCE_ICONIC_REPRESENTATION, DWMWA_FLIP3D_POLICY, DWMWA_EXTENDED_FRAME_BOUNDS, DWMWA_HAS_ICONIC_BITMAP,

How can i use a C# dll in a Win32 C++ project?

﹥>﹥吖頭↗ 提交于 2019-12-30 03:38:30
问题 I am working on a solution, most of its core engine is developed as Win32 C++ (and is Platform independent and is also used on OS X), some time ago we needed to call C++ dll's of core engine from C# and I was able to Load main solution's DLL in C# (by the help of some threads here on SO). but now we have certain things implemented in Managed C# dll and need to use it in Win32 C++ project? (and just function definitions and dll are provided) 回答1: You can create a managed C++ interop DLL to act