10-24-2017 09:01 PM
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.
Solved! Go to Solution.
10-25-2017 01:08 AM
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*.
10-25-2017 01:59 AM
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
10-25-2017 06:07 AM
In case you have copied the dlls to a different location, did you also copy the "DataModels" folder?
10-26-2017 12:33 AM
![]()
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);
}
}
}