Home

How can I add a reference to Shell32.dll?

edited February 2023

I've tried adding a reference but it still doesn't recognize it, I tried it in both LP5 and LP 6 with the same result. What am I doing wrong?

I've also tried adding it using the Powershell assembly, but same result:

Comments

  • Right now, you cannot load PowerShell assemblies into LINQPad. This is because PowerShell is hardcoded to run only in the default ALC. This excludes a number of scenarios, including running as a plug-in, and running in a scripting environment such as LINQPad. I created an issue here last year to track this:
    https://github.com/PowerShell/PowerShell/issues/17492

    What are trying to accomplish with Shell32? There should be easier ways to do most of this in .NET.

  • edited February 2023

    Hi Joe

    A little update after a ton of GoogleFu; I found that I can use Shell32 by adding in a reference to "Microsoft Shell Controls and Automation". I can do that in the VS IDE because it shows up in the .COM tab (reference) but I'm not sure how to add it in LP, because all I get is the Browse For File dialog, and I think that .COM reference in the IDE isn't directly linked to Shell32.dll?

    I'm just trying to run the code in the last screenshot, to install a font in the system folder, and register it with the system. That particular code comes from here.

  • The system32\shell32.dll file in that StackOverflow answer is an unmanaged DLL. I don't know how that answer can possibly be valid.

  • I'm not sure whether or not that code works yet, but I did at least see that I can access the Shell32.dll methods by adding the reference I mentioned above in VS IDE; but for future reference in case I ever want to use that reference again in LP, is there a way to add it?

  • Yes, you can use Shell32 just as you would in Visual Studio. But not by adding a reference to it, because it's a native DLL that's part of Windows. Here' an example from StackOverflow that you can run in LINQPad:

    void Main()
    {
        ShellAboutW(IntPtr.Zero, "hello#whats up", null, IntPtr.Zero);
    }
    
    [DllImport ("shell32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
    public static extern int ShellAboutW (
        IntPtr hWnd,
        string szApp,
        string szOtherStuff,
        IntPtr hIcon);
    
  • Oh ok, so just call it as an API instead of reference. TY!

Sign In or Register to comment.