pinvoke

Performance differences between P/Invoke and C++ Wrappers

旧城冷巷雨未停 提交于 2020-01-09 19:10:11
问题 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

How to get the icon associated with a specific folder?

北慕城南 提交于 2020-01-09 11:57:45
问题 I was required in one of my projects to get the icon for specific folders from their paths. For example: If I use C:\Users\Username\Desktop I want to get the icon associated with the Desktop folder If I use the path of a folder that has a custom icon, I want to get that icon AND NO, I DO NOT WANT THE GENERAL DEFAULT FOLDER ICON I've been searching for nearly 3 days with no luck. Any help is appreciated. 回答1: You could use the native SHGetFileInfo function. You can import it using the .net

How to show printer properties/preferences dialog and save changes?

时光怂恿深爱的人放手 提交于 2020-01-09 09:39:54
问题 EDIT: My fault! I expected the changes to be written back to the default printer settings when in fact only the local instance of the PrinterSettings are changed. - The below code seems to work as intended I am trying to show the custom printer properties of a given printer. I need this as part of a custom PrintDialog which I am trying to write. Most of the examples that I can find online manage to show the dialog but any changes the user might make are lost which makes it useless. Example:

How do I handle null or optional dll struct parameters in C#

南楼画角 提交于 2020-01-08 14:36:15
问题 How do I deal with optional struct arguments in dll methods called from C# using pinvoke? For example, the lpSecurityAttributes parameter here should be passed null when absent. The correct way of passing struct 's seems to be using ref , but it cannot have optional parameters, or take null in general. What ways are there to achieve this? 回答1: You have a few options 1) Use a class instead of a struct I think this method is the easiest. Simply declare the struct as a class : [StructLayout

How to call an unmanaged C++ function with a std::vector<>::iterator as parameter from C#?

隐身守侯 提交于 2020-01-07 04:58:12
问题 In unmanaged C++ I have a function which I'm trying to call from C#. This C++ function is as follows: typedef std::vector<Point> Points; typedef std::back_insert_iterator<Points> OutputIterator; namespace MYNAMESPACE{ DLLEXPORT OutputIterator convexHull(Points::iterator first, Points::iterator last, OutputIterator result); } When called from C++, the function is used as follows: Points points, result; points.push_back(Point(0,0)); points.push_back(Point(10,0)); points.push_back(Point(10,10));

DllNotFoundException when web application p/invokes a win32 DLL

两盒软妹~` 提交于 2020-01-07 04:18:29
问题 I get this error when my web application p/invokes a win32 dll (Player.dll) System.DllNotFoundException: Unable to load DLL 'Player.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Player.PlayerProxy.Initialize() atRunaware.WpfBrowserApp.Player.Page1.PlayFile(Object sender, RoutedEventArgs e) The application is written in WPF (XBAP). I've the following info in the .manifest file. Although all .Net DLLs are mentioned in <dependency> tags, the win32 dll is

Managed Debugging Assistant 'PInvokeStackImbalance' has detected a… on trivial method

走远了吗. 提交于 2020-01-06 15:54:08
问题 I am calling a Delphi function from C# and get the error: Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in ... I've exhausted attempts changing the .Net code to fit the Delphi signatures, why it doesn't work with basic Integers has me stumped, does anyone know where I am going wrong? Even the simplest function using 2 integers produces the error. I'm targeting x86 and have put in a couple of hours research but the following solutions haven't helped here, here and

DLLImport a variable MFC dll

风格不统一 提交于 2020-01-06 15:40:22
问题 So I created the following test project: [DllImportAttribute("TestMFCDLL.dll", CallingConvention = CallingConvention.Cdecl)] internal static extern int test(int number); private void button1_Click(object sender, EventArgs e) { int x = test(5); } Which works fine for my MFC dll that has the function test defined, however what I actually have is many MFC dlls that all share a common entry function and run differently based on my inputs. So basically I have tons of dlls that I cannot know at

P/Invoke SHSetKnownFolderPath

◇◆丶佛笑我妖孽 提交于 2020-01-06 06:09:28
问题 EDIT: Scotty2012 and David Morton's answers don't work for me so I have put a bounty on this question. I think I need to change the type of the string to something else before passing it in. I'm not much cop at P/Invoke and I'm struggling with declaring and calling SHSetKnownFolderPath. I'm using VB9 but if anyone puts answers in C# I should be able to translate. I have got SHGetKnowFolderPath working. Here is my code. In VB Imports System.Runtime.InteropServices Public Class Form1 <DllImport

P/Invoke SHSetKnownFolderPath

折月煮酒 提交于 2020-01-06 06:08:22
问题 EDIT: Scotty2012 and David Morton's answers don't work for me so I have put a bounty on this question. I think I need to change the type of the string to something else before passing it in. I'm not much cop at P/Invoke and I'm struggling with declaring and calling SHSetKnownFolderPath. I'm using VB9 but if anyone puts answers in C# I should be able to translate. I have got SHGetKnowFolderPath working. Here is my code. In VB Imports System.Runtime.InteropServices Public Class Form1 <DllImport