Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I use .Net COM Reference "Import" (TlbImp.exe) to access Measurement Studio 7.0 NIReports from C#?

The "import" (actually just adding a reference to the NIReports COM dll in Visual Studio) occurs without any errors listed.
However, when I look at the classes that are available to me I cannot match them 100% to the classes/attributes in the NIReports documentation. Specifically, I cannot find an equivalent to "CNIReport". The closest thing seems to be something called NIReport.ApplicationClass which, alas, contains no "Body" property.
What point am I not getting about this process?
Am I limited to accessing NIReports from Visual C++.Net?
Thanks
0 Kudos
Message 1 of 8
(6,305 Views)
The reference that you're adding is to the NI Reports COM interface. CNiReport is part of the Measurement Studio for C++ API to NI Reports. This API uses the COM interface internally, but does not have an exact 1-to-1 mapping to the COM interface. You can either use the interop wrapper to the COM interface as you are now or you can create a Managed C++ wrapper around the parts of the Measurement Studio for C++ NI Reports API that you're using and use this wrapper from the .NET language of your choice. If you go with the first option, you can post questions here about equivalents in the COM API to the Measurement Studio for C++ API. For starters, the ReportData property on the NIReport.ApplicationClass is the equivalent to the CNiReport::Body property.

- Elton
0 Kudos
Message 2 of 8
(6,302 Views)
Is there any example code available covering Managed C++ wrappers accessing Measurement Studio resources?
Thanks
0 Kudos
Message 3 of 8
(6,274 Views)
Could you clarify what you mean by Measurement Studio resources? Do you mean wrapping the Measurement Studio C++ classes using managed C++ ? Were you looking to wrap the C++ CNIReport classes in a managed class? This document describes some of the common ways to wrap unmanaged C++ classes using managed C++.
Were there any other classes you were interested in that you thought were missing from the MStudio .NET class libraries?

Hope this helps
Bilal Durrani
NI
0 Kudos
Message 4 of 8
(6,263 Views)
By "resources" I meant any and all Measurement Studio C++ classes that do not have .Net equivalents.

I have indeed been trying to create a Managed C++ wrapper class for the CNiReports class. The document to which you have referred me is the one I have been studying.
I've run into problems because the wrapper dll needs to #include NiReports.h which indirectly includes MFC-defined stuff. I have not found a way to include MFC definitions within a Managed C++ dll except by modifying NI header files. Any suggestions?

I'm using Measurement Studio 7.0 and have available to me only a subset of its many C++ classes available in the form of .Net classes. I would like them all available as .Net classes. (YOU ASKED!)
0 Kudos
Message 5 of 8
(6,257 Views)
(This is an addendum to my most-recent message.)

I have solved the problem of referencing NiReports.h by replacing the "stdafx.h" file generated by the Managed C++ .Net Class Library wizard with the "stdafx.h" file generated by the MFC DLL project wizard for a separate project. The wrapper class source file compiles successfully.

My next problem is getting the project to build.

The project I'm trying to build consists of the Managed C++ dll containing the wrapper class for CNiReport plus a simple C# Form project that just instantiates the wrapper class, at least at this stage. The wrapper class only implements the simple constructor, the destructor, and the private pointer to CNiReport. I describe this to you to emphasize the bare-bones character of my project.

My problem comes in the link process for the Managed C++ dll. I get only two unresolved tokens (references?) as follows:
Net_NIReports error LNK2020: unresolved token (0A00004D) NI.CNiComplex.__dtor
Net_NIReports error LNK2020: unresolved token (0A000056) NI.CNiString.__dtor
The obvious thing it seems to me is to include the CNiReports .lib file in the list of Additional Dependencies in the linker. However, when I try NiReports71.lib or NiReports71S.lib, I get many errors of duplicate reference.
The obvious thing to do then is to ignore default libraries. However, if I change the linker's Ignore All Default Libraries to Yes, I am left with many unresolved references.
What am I missing?
0 Kudos
Message 6 of 8
(6,255 Views)
So just to clarify a point. This is not something that we officially support. I know we do not have the NI-Reports functionality in the .NET libraries. I'll file a suggestion for this to be evaluated for future releases. A workaround would be to use the Primary Interop Assembly that Microsoft provides for MS Office, or basically wrap the NI-Reports C++ API in a managed layer, like you are doing.

With that out of the way, here is a project I was playing around with. Here is what I did.

I started with a standard managed C++ class library project. I added MFC support to it by checking out this link here and then modified the project to fix the mixed-dll loading problem from here. This mixed dll problem is an important one, so I suggest checking this one carefully. Otherwise you get weird errors that dont make sense. The wizard that the guy has on code project didnt work so I had to copy and paste some stuff manually. And change some project settings.

Once I have included MFC support, I was able to use the Measurement Studio Add/Remove Components Wizard (the little MStudio icon that shows up on the toolbar) to add the NI-REports classes to my project. From there on, it was just walking thru the document I referenced. The Components wizards didn the hard part about adding all the correct libraries. I'm attaching the wrapper project here. You can better decide how to want to design the wrapper, but I suggest using the Dispose pattern for cleaning up, since this is recommneded by Microsoft, especailly when dealing with unmanaged resources.

To use the class from C#, I had the following

private void button1_Click(object sender, System.EventArgs e)
{
Class1.InitializeReports();
Class1 test = new Class1();

test.Printing();
test.Dispose();

return;
}

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Class1.TerminateReports();
}


Hope this helps. Best of luck with your project.
Bilal Durrani
NI
0 Kudos
Message 7 of 8
(6,244 Views)
Project didnt come thru. Let me try again
Bilal Durrani
NI
0 Kudos
Message 8 of 8
(6,242 Views)