pinvoke

How to use interface pointer exported by C++ DLL in C#

旧街凉风 提交于 2020-01-14 08:49:04
问题 I have a DLL written in C++, which exports a function CreateRisk. The function returns an interface pointer, as follows: extern "C" { __declspec(dllexport) IRisk* __stdcall CreateRisk() { return new Risk(); } } IRisk is derived from IUnknown and has a custom method Calculate: class IRisk: public IUnknown { public: virtual int __stdcall Calculate(int i,double s) = 0; }; the class Risk implements IRisk interfaces (the implementation is omitted here). What I want is to call the function

C# p/invoke, Reading data from an Owner Drawn List Box

 ̄綄美尐妖づ 提交于 2020-01-14 04:24:11
问题 I have an Owner Drawn List Box in an external application ( America Online ) that I need to get data out of for building a component to assist people with its usability. (the utility will be making access of certain things more simple, etc). Notice My knowledge of C++ is very poor . I am a C# programmer. I have the hWnd to the List Box in question, but it appears to be owner drawn. Using LB_GETTEXT returns bad data, I just get junk (it renders in my debugger as a bunch of chinese characters)

marshaling variable arguments - __arglist or alternative

点点圈 提交于 2020-01-14 03:30:30
问题 Best way to describe the problem I'm trying to solve is to talk in code. I see a lot of __arglist questions on this forum, but not a lot of helpful answers. I know _arglist should be avoided so I'm open to alternative methods In one C++ module I have something like the following void SomeFunction(LPCWSTR pszFormat, va_args args) { // this function is not exported... // it is designed to take a format specifier and a list of variable // arguments and "printf" it into a buffer. This code //

How to detect if window is flashing

Deadly 提交于 2020-01-13 14:05:40
问题 I'm using FlashWindowEx() to flash an application window when it needs to attract a user's attention. The window caption and taskbar button flashes continuously until the application receives focus. How can I check whether the application is currently flashing (i.e. has not received focus since it was instructed to flash). 回答1: Here are two possible solutions. One uses WH_SHELL, and one uses a NativeWindow. You will have to provide your own extension method ( FlashWindow() ) to start the

How to P/Invoke to a native dll from Metro?

别来无恙 提交于 2020-01-13 09:36:26
问题 I've got a library consisting of two parts - One .net assembly that P/Invokes to a native 3rd party dll. In desktop mode this works just fine: However, when referencing the assembly from a Metro style app and running it, it throws a System.DllNotFoundException on the P/Invoke complaining that "Unable to load DLL 'library': The specified module could not be found." The native dll does not do anything special but only creates out-going TCP/IP connections to a server. The system cannot know this

C# USB driver from C++: SetupDiGetDeviceInterfaceDetail

馋奶兔 提交于 2020-01-11 12:27:07
问题 I've a problem trying to call SetupDiGetDeviceInterfaceDetail from C#. It always returns 1784 error code ("The supplied user buffer is not valid for the requested operation"). This is my C# code: Guid GUID_DEVINTERFACE_DFU = new Guid(0x3fe809ab, 0xfb91, 0x4cb5, 0xa6, 0x43, 0x69, 0x67, 0x0d, 0x52,0x36,0x6e); Guid classGuid = GUID_DEVINTERFACE_DFU; IntPtr hDevInfo = Win32.SetupDiGetClassDevs(ref classGuid, IntPtr.Zero, IntPtr.Zero, Win32.DIGCF_DEVICEINTERFACE | Win32.DIGCF_PRESENT); if

How to create suspended process from c# without P/Invoke?

六月ゝ 毕业季﹏ 提交于 2020-01-11 10:10:15
问题 WinAPI CreateProcess has the flag CREATE_SUSPENDED so it's possible to attach process to JobObject before it has done something and then to call ResumeThread for its main thread. The only that I found searching for a solution is this post written 11 years ago! 回答1: The only way to do this is with CreateProcess . The .net Process class does not offer the functionality. Either p/invoke CreateProcess or use a mixed mode C++/CLI assembly to call the same. 来源: https://stackoverflow.com/questions

How to create suspended process from c# without P/Invoke?

[亡魂溺海] 提交于 2020-01-11 10:08:14
问题 WinAPI CreateProcess has the flag CREATE_SUSPENDED so it's possible to attach process to JobObject before it has done something and then to call ResumeThread for its main thread. The only that I found searching for a solution is this post written 11 years ago! 回答1: The only way to do this is with CreateProcess . The .net Process class does not offer the functionality. Either p/invoke CreateProcess or use a mixed mode C++/CLI assembly to call the same. 来源: https://stackoverflow.com/questions

Unable to find an entry point named 'TaskDialogIndirect' in DLL 'ComCtl32'

烈酒焚心 提交于 2020-01-11 08:59:10
问题 We have a particular Vista x64 machine that, when running our C# WinForms app, displays the following error: System.EntryPointNotFoundException: Unable to find an entry point named 'TaskDialogIndirect' in DLL 'ComCtl32'. This same code works fine on other Vista machines. For some reason, this particular Vista machine always throws this exception. How can we fix this? 回答1: I had problems with this and Naughter's free XTaskDialog API, to get a fallback mechanism on Windows XP machines via

Performance differences between P/Invoke and C++ Wrappers

无人久伴 提交于 2020-01-09 19:11:27
问题 In the process of learning P/Invoke, I asked this previous question: How to P/Invoke when pointers are involved However, I don't quite understand the implications of using P/Invoke in C# over creating a wrapper in Managed C++. Creating the same DLL using P/Invoke in C# definately resulted in a cleaner interface since I could use DLLImport on an embedded resource, but would a Managed C++ wrapper for a native DLL, where I do the marshaling myself, have better performance? 回答1: C++ wrapper