Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

FCreate in c#

Hi all

 

I am trying to call lvrt.dll from C#.

 

Need to create file descriptor and pass it to FNewRefNum to get the LVRefNum.

 

So far I have imported dll functins:

 

[DllImport("/lib/lvrt.dll",CallingConvention=CallingConvention.Cdecl)]

public extern static Int32 FCreate(

IntPtr fdp,                       

[MarshalAs(UnmanagedType.LPStr)]string path,

Int32 permission,                       

Int32 openMode, 

Int32 denyMode,                       

ref SByte group);

 

[DllImport("/lib/lvrt.dll", CallingConvention = CallingConvention.Cdecl)]           

public extern static Int32 FNewRefNum(                       

[MarshalAs(UnmanagedType.LPStr)]string path,                       

IntPtr fd,                       

IntPtr refNumPtr);

 

And when I call these functions, I getting error message "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

 

Trying to port them right however I can't figure out what is wrong..

One suspicious part is that I don't know how to convert Labview type "File" in C#..

I just used "ref Int32" above.. but it might not be correct.

 

Anyone who can teach me will be a great help.

 

Thanks in advance

 

 

0 Kudos
Message 1 of 6
(4,231 Views)

JP_Med,

 

Im curious, what is the ultimater goal of the program? Calling the LVrt.dll can be difficult because from my understanding, some of the data types do not line up directly with C#, including the path type, which is a LV unique data type. Depending on what functionality you want, we may have a much simpler way to accomplish it already available, so I think it would be helpful to get perspective on the ultimate goal. 

 

Regards,

 

Kyle Mozdzyn

Applications Engineering

National Instruments

Regards,

Kyle M.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 6
(4,195 Views)

Hi Kyle

 

The ultimate goal is to pass the open file pointer(LVRefNum) to the function that is using that refnum to generate data file.

 

The function that I am calling is only accepting LVRefNum.

 

I was thinking, to generate LVRefNum, I need a fd(file descriptor) and one way came up with was using the FCreate to gerenate the fd.

 

thanks

 

 

 

 

 

0 Kudos
Message 3 of 6
(4,191 Views)

JP_Mead,

 

I was more curious about what the entire program is trying to do, and why it is calling into the LV RTE, to see if there is a better way than by calling the LVRT.dll, which gets a bit sloppy at times because it has some private data types and such.

 

I think the way to do this will be to create the fd value by either using FCreate or FMOpen, then using FNewRefNum to create the LV refnum to use in the desired function.

 

The LV manager help has a short bit of C code which you can translate over to C# (although again sloppy because C# typically passes by value and not by reference) here, and copied below.

 

foo(Path path) {

    Str255 buf; /* allocated buffer of 256 chars */

    File fd;

    MgErr err;

    err = FNamePtr(path, buf);

    err = FMOpen(&fd, path, openReadOnly, denyWriteOnly);

}

 

Regards,

 

Kyle Mozdzyn

Applications Engineering

National Instruments

Regards,

Kyle M.
Applications Engineering
National Instruments
0 Kudos
Message 4 of 6
(4,176 Views)

Thanks Kyle

 

So how do you declare File or Path type (Labview type I guess), in C# ?

 

 

0 Kudos
Message 5 of 6
(4,170 Views)

JP_med,


I saw in your prior posts, that it sounded like you were using this to communicate with a DLL provided by a third party dll. Is this the same project, and if so, what device is it. Instead of trying to force this through the LV RTE in C#, we may simply have a much easier method to communicate with this. It would also possibly let me look at the same dll and see if there is a much easier way to do this. The File datatype is unique to us, and may be very difficult to work with. 

 

Regards,

 

Kyle Mozdzyn

Applications Engineering

National Instruments

Regards,

Kyle M.
Applications Engineering
National Instruments
0 Kudos
Message 6 of 6
(4,161 Views)