ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

C# wrapper error code 6211

Solved!
Go to solution

I am writing a wrapper in C# to read TDM files too.

But I met the error code 6211 using OpenFileEx.

 

using System.Runtime.InteropServices;

namespace MyTDMSTest_CSharp
{
   class Program
    {
 
        [DllImport("nilibddc.dll")]
        static extern int DDC_OpenFileEx(string filePath, string filetype, int readOnly, out IntPtr pfile);
        [DllImport("nilibddc.dll")]
        static extern string DDC_CloseFile(out IntPtr pfile);
        [DllImport("nilibddc.dll")]
        static extern string DDC_GetLibraryErrorDescription(int errorCode);

        private const string FILE_PATH = "testtdms.tdms";

       static void Main(string[] args)
        {
            int ret;
            IntPtr pfile;

            ret = DDC_OpenFileEx(FILE_PATH, "TDMS", 1, out pfile);
            if (ret < 0)
            {
               string buff = DDC_GetLibraryErrorDescription(ret);
               Console.WriteLine("\nError:{0:D} {1}",ret,buff);
               Console.ReadKey();
            }
            else
            {
               DDC_CloseFile(out pfile);
             }
        }
    }
}

 

This code shows bellow message.

"Error:-6211 The storage could not be opened."

 

I'm using VS2010 with Win7(32bit) . 

How to solve this error?

 

Thanks for any help.

0 Kudos
Message 1 of 5
(4,452 Views)

I have no real knowledge about C wrapper in c# but I assume string does not work.

I think there must be some kind of Marshaller.

[MarshalAs(UnmanagedType.LPStr)]string filepath

because you have to convert to char*.

0 Kudos
Message 2 of 5
(4,426 Views)

Hello Andreask
Thank you for your quick reply.
I have modifed the code.
        [DllImport("nilibddc.dll")]
        static extern int DDC_OpenFileEx(
            [MarshalAs(UnmanagedType.LPStr)]string filePath,
            [MarshalAs(UnmanagedType.LPStr)]string filetype,
            int readOnly,
            out IntPtr pfile);
But that does not work . it shows the same error.

I guess the error code 6211 is caused by pfile because i got other error  "Error:-6209 The file passed to the library does not exist." when i changed the FILEPATH. 

Best regards

 

0 Kudos
Message 3 of 5
(4,420 Views)
Solution
Accepted by Takayama

In case you have copied the dlls to a different location, did you also copy the "DataModels" folder?

Message 4 of 5
(4,409 Views)
Solution
Accepted by Takayama

Smiley Very Happy

Thank a lot. It is solved !!

using System.Runtime.InteropServices;

namespace MyTDMSTest_CSharp
{
   class Program
    {
 
        [DllImport("nilibddc.dll")]
        static extern int DDC_OpenFileEx(string filePath, string filetype, int readOnly, out IntPtr pfile);
        [DllImport("nilibddc.dll")]
        static extern int DDC_CloseFile(IntPtr pfile);
        [DllImport("nilibddc.dll")]
        static extern string DDC_GetLibraryErrorDescription(int errorCode);
        [DllImport("nilibddc.dll")]
        static extern int DDC_GetFileStringPropertyLength(IntPtr pfile, string property, out int length);
        [DllImport("nilibddc.dll")]
        static extern int DDC_GetFileProperty(
                IntPtr pfile, 
                string property, 
                StringBuilder fileproperty,
                int valueSizeInBytes);

        private const string FILE_PATH = "TdmsSampleData.tdms";
        
        static void Main(string[] args)
        {
            int ret;
            IntPtr pfile;
            int length;

            ret = DDC_OpenFileEx(FILE_PATH, "TDMS", 1, out pfile);
            if (ret < 0) return;
            ret = DDC_GetFileStringPropertyLength(pfile, "name", out length);
            if (ret >= 0)
            {
                StringBuilder buff = new StringBuilder(length);
                ret = DDC_GetFileProperty(pfile, "name", buff, length);
                if (ret < 0)
                {
                    string msg = DDC_GetLibraryErrorDescription(ret);
                    Console.WriteLine("\nError:{0:D} {1}", ret, msg);
                    Console.ReadKey();
                }
                else
                {
                    Console.WriteLine("File name property ({0:D}): {1}", length, buff);
                    Console.WriteLine("End of program, press Enter key to quit");
                    Console.ReadLine();
                }
            }
            ret = DDC_CloseFile(pfile);
        }
    }
}

 

 

0 Kudos
Message 5 of 5
(4,398 Views)