LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing a C# class library and using it in LabWindows

I am sure this has been asked many time before, but the search here doesn't seem to work with C# and I am having trouble finding it.

 

I am attempting to write a very simple DLL in C# and have LabWindows call the DLL

namespace Utilities
{
    public static class GetVersion
    {
        public static string GetFileVersion(string fileName)
        {
            FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(fileName);
            return myFileVersionInfo.FileMajorPart + "." + 
myFileVersionInfo.FileMinorPart + "." +
myFileVersionInfo.FileBuildPart + "." +
myFileVersionInfo.FilePrivatePart; } public static string GetProductVersion(string fileName) { FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(fileName); return myFileVersionInfo.ProductVersion; } } }

The Create .Net Controller... option on the Tools menu fails when trying to convert this DLL, no meaningfull error messages.

 

 

Is there somewhere, a simple example of creating a C# class library and then utilising that class library in LabWindows?

0 Kudos
Message 1 of 4
(3,765 Views)

Hey krugman3,

 

I've looked into this and found some ideas on an MSDN forum here:

 

https://channel9.msdn.com/Forums/Coffeehouse/Do-you-know-a-tool-to-automate-making-C-DLLs-exports-ca...

 

It looks like there's some tweaking you have to do to be able to call your C# DLL from C. I'd try one of the projects within this thread and see if it works from CVI.

 

Cheers,

Ryan C.

0 Kudos
Message 2 of 4
(3,738 Views)

I copy/pasted your example code and it built fine for me (.NET 4.5, CVI 2015 SP1).

Capture.PNG

 

I've seen cryptic error messages from the .NET controller wizard when it's unable to load the assembly for some reason. Try closing out of Visual Studio (and any other apps that may have loaded the assembly), to make sure that nothing else has it reserved. 

https://www.linkedin.com/in/trentweaver
0 Kudos
Message 3 of 4
(3,717 Views)

Thanks for trying that,

I never managed to generate an fp from the dll

 

I was unable to get Visual studio to build the program with the "Register for COM interop" checkbox ticked, this turned out to be because I do not have admin on this machine. I got a colleague (who has got admin) to build it for me, but I was still unable to generate an fp from the resulting dll.

 

Using CVI 2010

 

However, the ultimate aim of the DLL was to make it easier to get file version and product version from exe's and DLLs, but I have now managed to do this from within LabWindows C code. Took some doing though, so much easier with .Net.

0 Kudos
Message 4 of 4
(3,678 Views)