05-02-2010 09:25 AM
I am writing a wrapper in C# to read TDM files.
OpenEx works fine.
[DllImport(lib, CharSet = CharSet.Auto)] static extern int DDC_OpenFileEx( [MarshalAs(UnmanagedType.LPStr)] string filePath, [MarshalAs(UnmanagedType.LPStr)] string fileType, int read_only, ref long file);
but
[DllImport(lib, CharSet = CharSet.Auto)] static extern int DDC_GetFileStringPropertyLength(long file,
[MarshalAs(UnmanagedType.LPStr)]
string property, ref int length);
int len = 0;
errCode = ReadTDM.DDC_GetFileStringPropertyLength(fileh, "name", ref len);// fileh is passed form OpenEx fun
System.Console.WriteLine("length {0}", len);
System.Console.WriteLine("Error Code {0}", errCode);
gives me an error An invalid argument was passed to the library. I had tried ref uint length , didn't help.
05-04-2010 01:50 PM
We looked at the source code for DDC_GetFileStringPropertyLength and the only things that would cause it to
return DDC_InvalidArgument (-6202) is:
I'm not familiar enough with C# to tell whether there are any problems in the declarations of the DLL functions
or in how they are being called but maybe that helps you to solve the issue.
05-05-2010 05:34 AM
Thx for the reply.
I found out that I have two headers files nilibddc_m.h and nilibddc.h
in first one DDCFileHandle is a long type in the second on is a structure
typedef struct _DDCFile DDCFile; typedef struct _DDCChannelGroup DDCChannelGroup; typedef struct _DDCChannel DDCChannel; typedef DDCFile* DDCFileHandle; typedef DDCChannelGroup* DDCChannelGroupHandle; typedef DDCChannel* DDCChannelHandle;
but according to your post it should not be the cause of this error, should be?
05-05-2010 06:26 AM
some additional info:
Windows 7 32bit and lib form the 32-bit subfoler
example SinData.tdm form http://digital.ni.com/public.nsf/allkb/A3663DE39D6A2C5A86257204005C11CA?OpenDocument
and the String is not the problem
/// <summary> /// GetNumChannelGroups /// </summary> [DllImport(lib)] static extern int DDC_GetNumChannelGroups(long file, ref uint numChannelGroups);
uint numGru = 0; errCode = ReadTDM.DDC_GetNumChannelGroups(fileh, ref numGru); System.Console.WriteLine("Error Code {0} GetNumChannelGroups", errCode);
also returs the -6202 code, hence is numGru.
05-09-2010 12:17 AM
Solved 🙂
file must be int not long
http://digital.ni.com/public.nsf/allkb/A3663DE39D6A2C5A86257204005C11CA?OpenDocument
nilibddc.h says
typedef long DDCFileHandle;
typedef long DDCChannelGroupHandle;
typedef long DDCChannelHandle;