NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a type library from Visual C++ .Net

I want to export a function from a dll wich has the folowing prototype:

void DummyFunctionName(SequenceContext *seqContext, CNiString &reportText, bool &errorOccurred, int &errorCode, CNiString &errorMsg)

How should the entry for this function look like in the ".odl" file?
0 Kudos
Message 1 of 12
(3,613 Views)
Hello krs,

If you're using Visual Studio .NET to create a Visual C++ MFC DLL and you want to use it in TestStand, it is easiest to use the "__declspec(dllexport)" syntax in your source code and header file:

void __declspec(dllexport) DummyFunctionName(SequenceContext *seqContext, CNiString &reportText, bool &errorOccurred, int &errorCode, CNiString &errorMsg)

I haven't used a .ODL file for exporting a function in Visual C++ .NET.


David Mc.
National Instruments
Message 2 of 12
(3,613 Views)
In fact I want Teststand3 to reconize a functions prototype( function exported from a VC++ .net dll). With TestStand2 and VC++6 I was building a type library for this.
I want to do the same thing in VC++ .net, but I have some problems writing the .odl file, because of the CNiString parameter. How should the .odl entry for this parameter look like?

Or, Is there another way, to make teststand3 recognize the functions prototype?
0 Kudos
Message 3 of 12
(3,613 Views)
Hello krs,

As I mentioned above, the best way I know of to export function prototypes from a Visual C++ DLL is using this syntax (both in the header file and the C++ source code file):

__declspec(dllexport) ()

There's nothing else you have to do at this point to get the function to be exported with your DLL. The syntax I listed in my first posting is exactly the syntax you will need to use for your function prototype.

Because of how easy it is to do the export this way, I have never needed to use a .ODL file with Visual C++ 6 or Visual C++ .NET.

Regards,
David Mc.
NI Applications Engineering
0 Kudos
Message 4 of 12
(3,613 Views)
Please correct me if I am wrong, but by only using __declspec(dllexport) you only export the function. You provide no information on it's parameters.

So I want TestStand to automatically recognize my function's parameters(especially the NiString). So, what do I have to do?

Can you help me with this?
0 Kudos
Message 5 of 12
(3,613 Views)
Using __declspec(dllexport) is sufficient (and necessary). Visual Studio encodes the parameters and return value information in the decorated name of the function in the DLL. As long as you use types recognized by TestStand 3.0 (such as CNiString), TestStand can decode the parameter information directly from the DLL and does not need a type library. In fact, you cannot use a type library with the Measurement Studio types such as CNiString.

See the online help topic entitled "Exporting Class Methods and Functions in Visual Studio .NET"
0 Kudos
Message 6 of 12
(3,613 Views)
Here is a MS kb that describes how to create a type library for the dll. But you probably should not use CNiString as a parameter to be described in an odl file, since its not a COM data type. You might want to use a LPCTSTR instead and use the CniString internally.

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 7 of 12
(3,613 Views)
Ok thanks, now it's clear.

I was trying to use for the exported function the same prototype as in the NI code templates. And there, one of the parameters was a CNiString. And I could not put this parameter into the type lib.

I think I will change it and use a LPCTSTR instead like you said.
0 Kudos
Message 8 of 12
(3,613 Views)
If I only export the function from the dll, TestStand will not automaticaly recognize the prototype. That is why I was trying to use a type lib.
0 Kudos
Message 9 of 12
(3,613 Views)
To krs -
In summary, TestStand can discover the parameter information from a DLL created by VC++, including functions with a CNiString type parameter. TestStand cannot see the parameter information in a function if the project uses a .DEF file or if the function uses the extern "C" syntax.

The TestStand online help topic entitled "Exporting Class Methods and Functions in Visual Studio .NET" discusses the above VC limitations.

If you choose to use a .DEF file or the extern "C" syntax in your VC++ DLL, then TestStand can only discover the prototype of a function if you add the function to a type library in the DLL.

Scott Richardson (NI)
Scott Richardson
National Instruments
0 Kudos
Message 10 of 12
(3,613 Views)