pinvoke

How to disconnect a bluetooth device from C# .Net in Win7

强颜欢笑 提交于 2019-12-22 01:15:55
问题 I would like to disconnect a bluetooth device from my c# .Net application, that runs on Win 7 x64. I Know that MS provides very little functionnality reguarding BT on .Net. I've searched 32feet.Net, and found how to connect, discover, get information, ... but nothing about disconnecting (Have I missed something ?). Then, I found on Msdn IOCTL_BTH_DISCONNECT_DEVICE. The problem is that I can't understand how to call it. It Seems that I shoud use DeviceIOControl with Platform Invoke, but I'm

P/Invoke throw System.ExecutionEngineException

情到浓时终转凉″ 提交于 2019-12-22 00:35:48
问题 I have a closed source unmanaged DLL coded in C++ that I wanted to use in a C# solution so I created a wrapper managed DLL that use P/Invoke to call the closed source DLL function. That works pretty well for no param function and int variables. However I get a System.ExecutionEngineException when running a more complex function that take an array of struct as parameter which contains array of char for strings. Here is what I had: [StructLayout(LayoutKind.Sequential)] public struct Target {

Mono fails to load a dll

跟風遠走 提交于 2019-12-22 00:30:43
问题 I am trying to load use a native shared library via P/Invoke. However, it won't load from under MonoDevelop. This is the console output with MONO_LOG_LEVEL=debug and MONO_LOG_MASK=dll : Creating a V8Engine instance ...Mono: DllImport attempting to load: 'V8_Net_Proxy'. Mono: DllImport error loading library '/localhome/rryk/v8netmonolinux/Source/bin/Debug/libV8_Net_Proxy': '/localhome/rryk/v8netmonolinux/Source/bin/Debug/libV8_Net_Proxy: cannot open shared object file: No such file or

Is it possible to get the name of current active application

本小妞迷上赌 提交于 2019-12-21 22:26:01
问题 User can switch active application by Alt+Tab or by clicking on their icons in TaskBar. Is it possible to get the name (or other unique characteristic) of current active application? I want to write a program which collects statistic of the applications usage. 回答1: The Windows API has a function called GetForegroundWindow(). You will need to use P/Invoke to call into the Win32 API. The P/Invoke wiki has more info for C# users. See this page for an example which gets the caption (name) of the

Getting any special folder path in Powershell using folder GUID

余生长醉 提交于 2019-12-21 21:26:28
问题 I want to use a PowerShell script to automate tasks related to the user when the user logs in. Sometimes a user will have moved his Documents folder from the default location. How can I determine the location of the user's Documents folder in PowerShell with a method that will work for all special folders? I tried to use SHGetKnownFolderPath calls from PowerShell based on Lee Holmes work As pinvoke website C# sample doesn't use StringBuilder, I assumed it was not required and stripped builder

calling unmanaged function char returns char *

瘦欲@ 提交于 2019-12-21 21:09:33
问题 I have a function in unmanaged C/C++ code (dll) that returns a structure containing a char array. I created C# struct to receive this return value uppon calling the function. And uppon calling this function i get 'System.Runtime.InteropServices.MarshalDirectiveException' This is C declaration: typedef struct T_SAMPLE_STRUCT { int num; char text[20]; } SAMPLE_STRUCT; SAMPLE_STRUCT sampleFunction( SAMPLE_STRUCT ss ); This is C# declaration: struct SAMPLE_STRUCT { public int num; public string

C#, DLL import API not working properly in VS2012 .NET Framework 4.5

喜欢而已 提交于 2019-12-21 20:22:16
问题 I have an issue with my WinForms project which was created in VS2005 .NET Framework 2.0, which I just upgraded to VS2012 .NET Framework 4.5. In my project, I used a third-party DLL by DllImport and used its functions as I had all documentation for them. The problem is one of the functions in the imported DLL which works fine in VS2005 .NET Framework 2.0 is not working in VS2012 .NET 4.5. Following are my code snippets from my project: [DllImport("W5EditLD.dll", CallingConvention =

Viewing export table on an unmanaged dll in C#

我是研究僧i 提交于 2019-12-21 19:57:57
问题 I am currently trying to create a C# application that will allow me to view the export table from an unmanaged DLL. My problem is, once I have all the pointers I need, I have no idea how to loop through the information that the API has provided me. Here is what I have right now: using System; using System.ComponentModel; using System.Runtime.InteropServices; namespace DLLMapper { class DLLExportViewer { #region APIs [DllImport("imagehlp.dll")] public static extern Boolean MapAndLoad(String

How to call DrawThemeTextEx in .NET

℡╲_俬逩灬. 提交于 2019-12-21 06:00:54
问题 I need to write a text with glow in a Vista/seven glass window, and I'm, trying to call the API to write some text there. I have checked out a great sample in CodeProject, but the problem is that I'm using .NET 1 (please, don't ask :-) I need to translate the follwing .NET 2 code to PInvoke, .NET 1 code. // using System.Windows.Forms.VisualStyles VisualStyleRenderer renderer = new VisualStyleRenderer( VisualStyleElement.Window.Caption.Active); // call to UxTheme.dll DrawThemeTextEx(renderer

How do I check if an NTAccount object represents a Group or a User?

梦想与她 提交于 2019-12-21 05:09:23
问题 When working with the access rules returned by GetAccessRules(True, True, GetType(System.Security.Principal.NTAccount)) how can I tell if the NTAccount object referenced in each rule is a user account or a group? Update: I was able to solve this as follows. Note, the intent of this code is to return True if the NTAccount is a group, and False otherwise or if an error occurs during checking. Is there a better way to do this? Public Function IsGroup(ByVal account As NTAccount) as Boolean Dim