Git Product home page Git Product logo

windows-api-code-pack-1.1's Introduction

Windows-API-Code-Pack-1.1.5

README

This is a fork of the Microsoft © Windows API Code Pack, based on a repository created by Aybe. Due to the lack of updates to the original package, this fork was created to include all open pull requests on the original repository, apply fixes and add support for all current .NET Framework and .NET Core versions.

Now with added .Net5.0 support ! (windows only)

NuGet packages (recommended)

https://www.nuget.org/packages/Microsoft-WindowsAPICodePack-Core/

https://www.nuget.org/packages/Microsoft-WindowsAPICodePack-Shell/

https://www.nuget.org/packages/Microsoft-WindowsAPICodePack-ShellExtensions/

https://www.nuget.org/packages/Microsoft-WindowsAPICodePack-ExtendedLinguisticServices/

https://www.nuget.org/packages/Microsoft-WindowsAPICodePack-Sensors/

Licence

See LICENSE for the original licence (retrieved from WebArchive). The library is not developed anymore by Microsoft and seems to have been left as 'free to use'. A clarification or update about the licence terms from Microsoft is welcome, however.

Release notes

See CHANGELOG for latest changes.

Issues

When you submit a issue:

  • describe the observed behavior/result
  • describe the expected behavior/result
  • provide example code showing the issue where appropriate

windows-api-code-pack-1.1's People

Contributors

a3tom avatar agrueso avatar anhellwig avatar aybe avatar contre avatar crauzer avatar dahall avatar danftrx avatar dgrunwald-qt avatar dizzylyzzie avatar horeaper avatar jozefizso avatar martinchrzan avatar pmoski avatar sgjsakura avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

windows-api-code-pack-1.1's Issues

Fix multi-dotted extensions and CommonSaveFileDialog not using selected filter extension

using (CommonSaveFileDialog dialog = new CommonSaveFileDialog())
{
    dialog.InitialDirectory = Config.Get<string>("SaveWadInitialDirectory");
    dialog.Filters.Add(new CommonFileDialogFilter(".wad.client", "*.wad.client"));
    dialog.Filters.Add(new CommonFileDialogFilter(".wad.mobile", "*.wad.mobile"));
    dialog.Filters.Add(new CommonFileDialogFilter(".wad", "*.wad"));
}

Currently multi-dotted extensions are not supported because the CommonFileDialogFilter class removes all dots from the extension with the Normalize method.

Another issue with extensions is that CommonSaveFileDialog doesn't append the selected Filter extension to the FileName property.

IsExpandedMode causes a System.InvalidCastException

On .NET Core 3.1 -- creating a CommonSaveFileDialog and setting IsExpandedMode to true causes an InvalidCastException:

System.InvalidCastException: 'Interface not registered

Failed to find proxy registration for IID: {BD2C38C2-E064-41D0-A999-940F526219C2}.'

Code to reproduce:

var cfo = new CommonSaveFileDialog();
cfo.IsExpandedMode = true;
cfo.ShowDialog();

Win 7 x64 GeoSense sensor GetTimestamp failure

I installed GeoSense sensor and able to see it in sensor list, but the code still throws an error

Stacktrace:
Microsoft.WindowsAPICodePack.Sensors.SensorPlatformException: No sensors found. Are any sensor drivers installed?
at Microsoft.WindowsAPICodePack.Sensors.SensorManager.GetSensorsByCategoryId(Guid category)
at Microsoft.WindowsAPICodePack.Sensors.SensorManager.GetAllSensors()
at GetLocationEvent.Program.Main(string[] args) in ...

all code is this:

SensorList<Sensor> list = SensorManager.GetAllSensors();

  foreach (var item in list)
  {
         item.UpdateData();
         Console.WriteLine(item.FriendlyName);
   }

Installed same sensor on Win 10, but could not test it, as code above always throws Interop exceptions on UpdateData method
I will try to check it myself, but I am newbie in desktop development.

Enable SourceLink to allow easier debugging (Step into the code of this library)

Visual Studio 2017 supports a new debug option called SourceLink which adds a JSON file to the PDB (which is now part of the NuGet package) which tells the Visual Studio Debugger to fetch the .cs files from a repository like for JSON.net based on commit hash 7217c484e9705b5e76585c8b7fcd489c8e021c23

<SourceLink>
    <Conversion FilePath="/_/*" Uri="https://raw.githubusercontent.com/JamesNK/Newtonsoft.Json/7217c484e9705b5e76585c8b7fcd489c8e021c23/*" />
</SourceLink>

See the Json.net pull request how to do it.

Nuget release?

Is there going to be a nuget release for 1.1.5 now that the version was bumped?

Not compatible with .NET 5

I upgraded my project to .NET 5 and the package is not listed as compatible, I assume cause the latest target in it is .netcoreapp3.1.

WindowClassEx - struct layouts do not match native layouts

https://github.com/contre/Windows-API-Code-Pack-1.1/blob/master/source/WindowsAPICodePack/Shell/Interop/ShellObjectWatcher/ShellObjectWatcherNativeMethods.cs

Following is completely incorrect:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct WindowClassEx
{
internal IntPtr BackgroundBrushHandle;
internal string ClassName;
internal IntPtr CursorHandle;
internal int ExtraClassBytes;
internal int ExtraWindowBytes;
internal IntPtr IconHandle;
internal IntPtr InstanceHandle;
internal string MenuName;
internal uint Size;
internal IntPtr SmallIconHandle;
internal uint Style;
internal ShellObjectWatcherNativeMethods.WndProcDelegate WndProc;
}

The original repo
https://github.com/aybe/Windows-API-Code-Pack-1.1/blob/master/source/WindowsAPICodePack/Shell/Interop/ShellObjectWatcher/ShellObjectWatcherNativeMethods.cs

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct WindowClassEx
{
internal uint Size;
internal uint Style;
internal ShellObjectWatcherNativeMethods.WndProcDelegate WndProc;

    internal int ExtraClassBytes;
    internal int ExtraWindowBytes;
    internal IntPtr InstanceHandle;
    internal IntPtr IconHandle;
    internal IntPtr CursorHandle;
    internal IntPtr BackgroundBrushHandle;
    
    internal string MenuName;
    internal string ClassName;
    
    internal IntPtr SmallIconHandle;
}

This above reflectts MS documentation
https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-wndclassexw

typedef struct tagWNDCLASSEXW {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCWSTR lpszMenuName;
LPCWSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEXW, *PWNDCLASSEXW, *NPWNDCLASSEXW, *LPWNDCLASSEXW

Customize text label cancel button

Dear All,
I am a new in this package and now i have a little trouble, i can not customize text label cancel button.

Pls help me. Thanks all.

ERROR using Microsoft.WindowsAPICodePack.Shell; --> Missing using directive

Hello,
i try to run the following Powershell Script
###########################################
_**using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;

string filePath = @"D:\temp\example.docx";
var file = ShellFile.FromFilePath(filePath);

// Read and Write:

string[] oldAuthors = file.Properties.System.Author.Value;
string oldTitle = file.Properties.System.Title.Value;

file.Properties.System.Author.Value = new string[] { "Author #1", "Author #2" };
file.Properties.System.Title.Value = "Example Title";

// Alternate way to Write:

ShellPropertyWriter propertyWriter = file.Properties.GetPropertyWriter();
propertyWriter.WriteProperty(SystemProperties.System.Author, new string[] { "Author" });
propertyWriter.Close();**_
#########################################################################
I have the following error

ParserError:
Line |
1 | using Microsoft.WindowsAPICodePack.Shell;
| ~
| Missing using directive

Can you help me please.

Regards,
Djeff

Exception 0x800700B7 "Cannot create a file when that file already exists."

"Code pack" works properly with magnetometer on 2 of our devices, but on third tablet it produces an exception (row 698 in Sensor.cs):
System.Runtime.InteropServices.COMException: "Cannot create a file when that file already exists. (Exception from HRESULT: 0x800700B7)"
I'm trying to find out why it's happening or what is especially with this tablet, but not succeed yet.

CommonSaveFileDialog - File name with dots will be misinterpreted as file extension

Hi,
I am using CommonSaveFileDialog with the following code lines:

CommonSaveFileDialog dialogSave = new CommonSaveFileDialog();
dialogSave.InitialDirectory = PdfOutputPath;
dialogSave.DefaultFileName = $"{DateTime.Now:yyyyMMdd}_Merged{".pdf"}";
dialogSave.Filters.Add(new CommonFileDialogFilter("PDF-Dokument", $"*.pdf"));
if (dialogSave.ShowDialog() == CommonFileDialogResult.Ok) {
     string pdfOutputFile = dialogSave.FileName;
}

But if I enter as filename without the file extension (.pdf), e.g. 'Ummeldung 01.01.2024 THURNHOFER' it will be cutted to 'Ummeldung 01.01.' - '.2024' will be interpreted as file extension from my filename.

I can prevent this behaviour, if I set
dialogSave.DefaultExtension = ".pdf";

but it seems to me, that it is a bug!

Best regards, Karl

[Regression] TaskDialog feature needs to load version 6 of comctl32.dll but a different version is current loaded in memory

Hello and thank you for maintaining this module.

I notice today that you publish an update (1.1.4).
I tried to update the NuGet package from 1.1.3.3 on a personal WPF project but after that my app crash with an exception :

TaskDialog feature needs to load version 6 of comctl32.dll but a different version is current loaded in memory

This exception pop up when I call the Show() method of a new TaskDialog object.

Everything works fine if I revert to 1.1.3.3.

Out of Memory

Hello, I encountered a memory overflow problem. Locate the following Demo:

Task.Run(async() => {

            while (true)
            {
                try
                {
                    using (IKnownFolder appsFolder = KnownFolderHelper.FromCanonicalName("AppsFolder"))
                    {
                        if (appsFolder == null) continue;
                        foreach (var item in appsFolder)
                        {
                            if (!item.Properties.DefaultPropertyCollection.Contains("System.Link.TargetParsingPath")) continue;
                        }
                    }    
                }
                catch (Exception ex)
                {

                    System.Diagnostics.Debug.WriteLine(ex);
                }
                await Task.Delay (1000);
            }
        });

I hope I can get your help!
I wish you a happy life!

Create an editorconfig

Create an editor config file so we can make sure all the formatting and style stuff is defined.

Things like tabs vs spaces, brace styles, all other coding holy wars, etc...

CommonOpenFileDialog triggers rescaling of other forms

I have a simple WindowsForm application that uses CommonOpenFileDialog from Window-API-Code-Pack 1.1.4. When I run my form using greater than 100% display scaling, showing CommonOpenFileDialog causes the parent form (and any child forms) to rescale. This video illustrates the issue:
https://www.dropbox.com/s/wa5o5d6awv7zfuz/formRescalingIssue.mp4?dl=0

Using the attached Visual Studio project:
ResolutionScalingIssue.zip

Is there a way to disable this automatic rescaling?

Deleting files to the recycle bin.

Hi.

I was wondering, is there any funcionality in API code pack to delete a file by sending it to the recycle bin?

Files deleted with System.IO.File.Delete are usually deleted permanently, and I've found that sending files to the bin is surprisingly non trivial.

I already found a few solutions, but I would preffer to use something already in built in another library, specially if it's related to shell operations.

CommonFileDialogs are not extensible.

CommonFileOpenDialog and CommonFileSaveDialog are both sealed and can't be extended.

CommonFileDialog's abstract methods are all internal and can't be extended.

IFileDialogCustomize is completely internal.

etc., etc.

This is a common thing for BCL classes (and obviously a legacy of the original source) -- but it would be nice to have these permissions opened up so that we can extend the code without having to compile from scratch.

Cannot run on machine with FIPS mode enabled

On a Windows system with FIPS enforcement enabled, I get the following stacktrace:

System.TypeInitializationException: The type initializer for 'Microsoft.WindowsAPICodePack.Shell.ShellObject' threw an exception. ---> System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.
   at System.Security.Cryptography.MD5CryptoServiceProvider..ctor()
   at Microsoft.WindowsAPICodePack.Shell.ShellObject..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.WindowsAPICodePack.Shell.ShellObject.op_Inequality(ShellObject leftShellObject, ShellObject rightShellObject)
   at Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialog.ApplyNativeSettings(IFileDialog dialog)
   at Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialog.ShowDialog()
   at PcbDrImporter.ProjectGeneration.ProjectGeneration.SelectProjectPath()
   at PcbDrImporter.ProjectGeneration.ProjectGeneration.Main()
   at PcbDrImporter.Layout.ImportLayout.Import()
   at CSharpPlugin.PluginServerModule.ImportLayoutCommand(IServerDocumentView view, String& parameters)
   at DXP.CommandLauncher.LaunchCommandImpl(String argCommandName, String& argParameters, IServerDocumentView argContext)

Code:

var dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
dialog.showDialog()

Environment

  • Windows 10 with FIPS mode crypto enforcement enabled
  • C# 7.3
  • .NET Framework 4.8
  • <PackageReference Include="Microsoft-WindowsAPICodePack-Shell" Version="1.1.4"/>

Solution

Can a newer hash crypto service provider be used, such as SHA-256?

Problem with getting property of sensor

Hello. I'm working with magnetometer sensor. The project supports .NET 4.0 so probably the "Windows-API-Code-Pack" platform is my only option. (By the way, why you changed the target framework of aybe's source?) Sensor.GetSupportedProperties returns of 7 values. There are correct ids among them, I checked it by https://docs.microsoft.com/en-us/windows-hardware/drivers/sensors/sensor-category-orientation. But when I call, for example, Sensor.GetProperty(new PropertyKey("1637d8a2-4248-4275-865d-558de84aedfd", 11)), which is supposed to be "SENSOR_DATA_TYPE_MAGNETIC_HEADING_COMPENSATED_MAGNETIC_NORTH_DEGREES" according to link above and is presented in GetSupportedProperties's results, it returns exception "not found property" or something like this. I would be very grateful, if you could suppose why it's happening. I've tried to debug source but there is COM-technology there that I cannot handle.

Wrong size of taskbar thumbnail at first show

Hello,

With Windows 10 v1803 and later, the taskbar thumbnails don't show up with the good ratio width/height. They are fine after the second show.

The enclosed archive contains a Visual Studio 2019 project that exhibits the problem: it generates a new thumbnail every 10 seconds. When hovering on the taskbar, the thumbnail doesn't have the expected square aspect. When leaving the taskbar and coming back, the thumbnail now has the good aspect.
You can then wait 10 seconds to invalidate the thumbnail and see the problem again.

Thumbnail.zip

Activeform shrinks when I open Folder dialog

I start my App and the form is the size I specified. I then click a button to set the folder in a text box as below. When the dialog runs the active form shrinks in size. It shrinks so small it is hard to use. I tried a workround to get size before I open dialog and restore it after but even that is not good. Maybe it is to do with the Desktop size in "Display scale and layout" which I have set to 125%. Maybe this dialog tries to set it to 100%? If you need more info please just get in touch.

Here is the test code I am using.
CommonOpenFileDialog folderDialog = new CommonOpenFileDialog();

        folderDialog.InitialDirectory = "C:\\temp";
        folderDialog.RestoreDirectory = true;
        folderDialog.IsFolderPicker = true;
                   
        if (folderDialog.ShowDialog() == CommonFileDialogResult.Ok)
        {
                          txtbx_save_as.Text = folderDialog.FileName; 
        }

ArgumentNullException when showing TaskDialog is self-contained app

The reason is that for self-contained apps Assembly.Location is empty here (https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?tabs=cli#api-incompatibility):

CoreCLR Version: 6.0.2123.36311
.NET Version: 6.0.21
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
   at System.IO.Path.Combine(String path1, String path2)
   at Microsoft.WindowsAPICodePack.Dialogs.EnableThemingInScope.EnsureActivateContextCreated()
   at Microsoft.WindowsAPICodePack.Dialogs.EnableThemingInScope..ctor(Boolean enable)
   at Microsoft.WindowsAPICodePack.Dialogs.NativeTaskDialog.NativeShow()
   at Microsoft.WindowsAPICodePack.Dialogs.TaskDialog.ShowCore()

In the same Microsoft doc it is recommended to use AppContext.BaseDirectory instead of Assembly.Location for such cases.

Compatibility with newer .NET Framework

Hi,
I cannot install this on application targeting .NET Framework v4.6.1. Is there any option to make this work?

Error:

Could not install package 'Microsoft-WindowsAPICodePack-Core 1.1.3.2'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.