11-28-2007 04:01 AM
I'm trying to write a wrapper class in VB.NET 2005 for the DIAdem Connectivity Library to write Diadem files within .NET code.
For example I've been successfull with
(Declaration)
Declare
Function GetLibraryErrorDescription Lib "nilibddc.dll" Alias "DDC_GetLibraryErrorDescription" _(Call)
Dim s as IntPtr = DIAdemConnLibWrapper.GetLibraryErrorDescription(deb)
MsgBox(Marshal.PtrToStringAnsi(s)) 'output: error message
But after spending hours with the following declaration I am quite desperate:
(Declaration)
Declare Ansi Function CreateFile Lib "nilibddc.dll" Alias "DDC_CreateFile" _
ByVal filePath As String, _
ByVal fileType As String, _
ByVal name As String, _
ByVal description As String, _
ByVal title As String, _
ByVal author As String, _
ByVal DDCFileHandle As IntPtr) As Integer
(Call)
result = DIAdemConnLibWrapper.CreateFile(str1, str2, str3, str4, str5, str6, myIntPtr)
The arguments (filename and so on) are correct, because using them in a native C-Application works very well. After this call, result is -6202, saying there were invalid arguments. I've tried Ansi/Auto/Unicode in the declaration, StringBuilder as type (even when strings should be OK, according to the MSDN), ByRef/ByVal and different marshalling instructions like <MarshalAs(UnmanagedType.LPWStr)>. I always get the same error.
Has anyone ever done a successfull wrapping of the DLL in .NET? What's wrong with my code?
11-28-2007 04:49 AM
Matthias Alleweldt Project Engineer / Projektingenieur | Twigeater? |
11-29-2007 07:02 AM
Declare
Ansi Function DDC_SaveFile Lib "nilibddc.dll" _or any other function needing a filehandle returns -6202 ( "An invalid file handle was passed to the library. ") although the filehandle IntPtr gets changed by DDC_CreateFile!
11-29-2007 07:33 AM
int __stdcall DDC_CreateFile (const char *filePath,
const char *fileType,
const char *name,
const char *description,
const char *title,
const char *author,
DDCFileHandle *file);
Declare Ansi Function CreateFile Lib "nilibddc.dll" Alias "DDC_CreateFile" _
ByVal filePath As String, _
ByVal fileType As String, _
ByVal name As String, _
ByVal description As String, _
ByVal title As String, _
ByVal author As String, _
ByRef DDCFileHandle As IntPtr) As Integer
int __stdcall DDC_SaveFile (DDCFileHandle file);
Declare Ansi Function SaveFile Lib "nilibddc.dll" Alias "DDC_SaveFile" _
(ByVal DDCFileHandle As IntPtr) As Integer
Matthias Alleweldt Project Engineer / Projektingenieur | Twigeater? |
11-29-2007 07:49 AM
Thank you very much for your explanation, it's working now!
05-31-2022 10:40 AM
Hello I have most of the nilibddc.dll working with VB.NET but I do not get any data saved to my TDMS after calling DDC_SetDataValues.
Are there any good samples for doing this from VB.NET?
I create the Group, Channel, then pass a pointer to an array of double to DDC_SetDataValues. But my TDMS file has 0 points saved under the channel and I get no errors.
Declare Ansi Function SetDataValues Lib "nilibddc.dll" Alias "DDC_SetDataValues" _
(ByVal channelHandle As IntPtr,
ByVal values As IntPtr,
ByVal numValues As UIntPtr) As Integer 'numbvalues is size_t
''The call
Dim values() As Double = {1, 2, 3, 4, 5}
Dim iptr As IntPtr
iptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(Of Double) * values.Length)
Marshal.Copy(values, 0, iptr, values.Length)
result = SetDataValues(channelHandle, iptr, 5)
06-06-2022 02:00 AM
This article is really amazing. Thanks for the sharing. HCA Rewards Login