LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

exception using Microsoft.WindowsAPICodePack.Shell .net dll (1172)

Solved!
Go to solution

Hi,

 

I tried to use the Microsoft.WindowsAPICodePack.Shell dll as shown in the attachment. I don't have any clue what I've might done wrong. I already tried to run LV as administrator but that didn't help.

Running the exact same code in C# is working.

 

Thanks in advance and best regards,

Lisa

 

 

0 Kudos
Message 1 of 9
(5,990 Views)

C# probably does things under the hood, like maybe initializing forms\presentationframework.

 

You could try to compile an .NET assembly with the C# code to see if that works. .NET has a build in C# compiler, so you won't need Visual Studio...

 

Why do you want this? LV has a multi file selection dialog.

 

Also, Microsoft.WindowsAPICodePack is probably just a wrapper. It's not shipped with WIndows anymore. The function probably calls Microsoft.Forms.OpenFileDialog or Microsoft.Win32.OpenFileDialog (OTOMH). Both of these (I didn't bother downloading WindowsAPICodePack ) just hang infinitely in LV, without ever showing a dialog.

Message 2 of 9
(5,905 Views)

Hi,

 

I did try it in Visual Studio and it worked. When using a dll as a wrapper the same error occurs - hence your assumption might be correct.

 

I need it because I don't want to open files but I need multiple folder directories. Do you have any other ideas how to realize that in LV? 

 

Thank you!

0 Kudos
Message 3 of 9
(5,886 Views)
Solution
Accepted by topic author lisastl

I found a solution. Just built an exe... Was probably the easiest way to implement multiple folder selection 🙂

Message 4 of 9
(5,872 Views)

You'd be helping others a lot if you could post some code. It's probably trivial, but most of us are good in LV, not C#.

0 Kudos
Message 5 of 9
(5,852 Views)

of course:

 

 

using System;
using Microsoft.WindowsAPICodePack.Dialogs;

namespace MF
{
class Program
{

[STAThread]
static void Main(string[] args)
{
if (args.Length > 0 && System.IO.Directory.Exists(args[0]))
{
var openFolder = new CommonOpenFileDialog();
openFolder.AllowNonFileSystemItems = true;
openFolder.Multiselect = true;
openFolder.IsFolderPicker = true;
openFolder.Title = "Select folders";
openFolder.InitialDirectory = args[0];

if (openFolder.ShowDialog() == CommonFileDialogResult.Ok)
{
Console.WriteLine(string.Join(";", openFolder.FileNames));
}
}
}
}
}

 

couldn't be easier I guess 🙂

0 Kudos
Message 6 of 9
(5,825 Views)

@lisastl wrote:

couldn't be easier I guess 🙂


Here's a VI that compiles the exe.

 

It's convenient, there's no need to install VS or anything. And the entire compilation fits in SCC.

 

I can't actually compile the exe, as I didn't install WindowsAPICodePack. But I modified a VI that creates a dll (set generateExecutable to false, change the extension and the code of course), so it should mostly work.

Message 7 of 9
(5,807 Views)

Thank you for your answer!

I don't get why you would need that... (No offense - just really don't understand it.) Isn't it easier to just call the exe in the System Exec VI? Or does that mean that the LV runtime engine was used?

 

You can find my solution in the attachment. You'll need to adapt the path in the VI to the direction where you put the exe. And you'll need to put both dlls at this place. But then you won't need to install the APICode pkg. But unfortunately you'll need the runtime engine for VS 2017 x64.

0 Kudos
Message 8 of 9
(5,793 Views)

@lisastl wrote:

Thank you for your answer!

I don't get why you would need that... (No offense - just really don't understand it.) Isn't it easier to just call the exe in the System Exec VI? Or does that mean that the LV runtime engine was used?


You'd use that code to compile the C# executable.

 

That way, you don't need to download and install VS, saving gigabytes of HD space. Also, the VI ends up in source code control, so the next guy\girl doesn't need to install VS...

 

Once you have the .NET exe, you call it just like before.

0 Kudos
Message 9 of 9
(5,784 Views)