01-10-2017 08:25 AM
Hello everyone,
I was wondering if someone can help me understand a few things. I am writing a program in C# using a C DcPwr library. I read that I can use the DllImport function but I'm having some trouble understanding some things.
The function I'm importing is
ViStatus _VI_FUNC CPX400_init (ViRsrc resourceName, ViBoolean IDQuery, ViBoolean resetDevice, ViSession *newVi)
so I'm confused about two things
The first things is the _VI_FUNC. Can someone explain what that does and how it interacts with the C code.
The second is importing the C function into my C# application. How do I translate the declared types to C# types? I assume I can change ViBoolean to bool, and maybe ViRsrc to string, but how about the others? If I'm wrong, please let me know.
01-12-2017 10:01 AM
Hello,
All of the questions you are asking are about typedefs and definitions. Probably on your computer is a visatype.h file which shows definitions of _VI_Func as well as all of those data types. For example, I have a copy of this located in C:\Program Files\IVI Foundation\VISA\Win64\Include.
For example, depending on your processor, if you are running Windows 64 bit, _VI_Func gets defined as a _fastcall function type, but if you are running Windows 32 bit, then _VI_Func gets defined as a _stdcall function.
To go further, this visatype.h file also defines unsigned short as a ViBoolean. So that would show which filetypes you can use when transferring over to C#. You could try using the original data types instead of the custom typedefs, but if you run into issues then it might be easier to create a C wrapper which converts your C# inputs into the typedef parameters.
Best,
Shamik C
Applications Engineer
National Instruments