From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

DiAdem library to write TDMS file from VB.net

I'm tring to to use the DDC_Create function from the TDM C dll the problem is that I keep getting a -6202 Error (Invalid Argument) 

 

<DllImport("nilibddc.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)> _
  Public Function DDC_CreateFile(ByVal FilePath As String, ByVal FileType As String, _
                                   ByVal FileName As String, ByVal Desc As String, _
                                   ByVal Title As String, ByVal Author As String, _
                                  ByRef File As IntPtr) As Integer

 

I have looked everywhere for help and tried every combination of possible solutions that I could think of without luck.  I know that this should work is it is the way that others on this forum are doing it with success, I'm definitly getting frustrated. This is how I call the function.

 

Dim FilePtr as IntPtr

DDC_CreateFile("C:\Temp", "DDC_FILE_TYPE_TDMS", "Test.tdms", "None", _
                               "title", "Author", FilePtr)

0 Kudos
Message 1 of 2
(4,662 Views)

Hello jrwilk,

I am not too familar with calling c dlls from VB.NET however I found the following article on MSDN. Here is the section that may apply:

 

2.0 Calling DLLs from Visual Basic

In Visual Basic, all functions, including DLL functions, that you want to call must first be declared by using the Declare statement. You can declare your functions in the declarations section of a Form or a Module. If you declare a DLL procedure or function in a Form, it is private to that Form. To make it public, you must declare it in a Module. The following is an example Declare statement:

   Declare Sub getdiskinfo Lib "c:\somepath\diskinfo.dll"
      (ByVal mydrive As String, ByVal myvolume As String, free As Long)
				

You must enter the entire Declare statement as one, single line. This particular Declare statement declares the user-defined procedure GETDISKINFO located in user-created DISKINFO.DLL file. 

Once you declare the function, you can call and use the function just as you would call and use a Visual Basic function.

 

Another section from that article that is important is how to pass parameters to a function:

 

Passing Arguments by Value or by Reference

By default, Visual Basic passes all arguments by reference. (When passing by reference, Visual Basic supplies a 32-bit far address.) However, many DLL functions expect an argument to be passed by value. This can be achieved by placing the ByVal keyword in front of the argument declaration.

 

Based on the functions help, everything should be passed by reference; however the function prototype you posted seems to require everything to be passed by val. I would double check those as well as the last argument.

Jacob R. | Applications Engineer | National Instruments

0 Kudos
Message 2 of 2
(4,643 Views)