jskog
Jan 30th, 2003, 08:33 AM
Hello.
I am very new to VB programming, but I have to write a small program to check if it is possible to use a function from my DLL in VB.NET. (The DLL is written in VC.NET and it works just fine in other VC programs.)
The function is declared as
extern "C" _declspec (dllexport) float* RunFilter(char* , long);
and I would like some help on how to use it in VB, and how to handle the pointers.
In VB I have tried to import the function as
Public Declare Function RunMyFilter Lib "Mydll.dll" Alias "RunFilter" (ByVal indata As Byte(), ByRef datalength As Long) As Single()
but I don't know if I got the datatypes correctly... Does it seem correct?
When I use the function the arguments are declared as
Dim Buffer As Byte() = New Byte(lFileSize) {}
Dim lFileSize As Long
and I call the function like
Dim utdata As Single() = New Single(180) {}
utdata = RunMyFilter(Buffer, lFileSize)
The program compiles allright, but when I run it and it is supposed to "RunMyFilter", the program crashes and tells me:
An unhandled exception of type 'System.Runtime.InteropServices.MarshalDirectiveException' occurred in WindowsApplication1.exe
Additional information: Can not marshal return value.
Do you know what I have made wrong?
Best Regards
Johan
I am very new to VB programming, but I have to write a small program to check if it is possible to use a function from my DLL in VB.NET. (The DLL is written in VC.NET and it works just fine in other VC programs.)
The function is declared as
extern "C" _declspec (dllexport) float* RunFilter(char* , long);
and I would like some help on how to use it in VB, and how to handle the pointers.
In VB I have tried to import the function as
Public Declare Function RunMyFilter Lib "Mydll.dll" Alias "RunFilter" (ByVal indata As Byte(), ByRef datalength As Long) As Single()
but I don't know if I got the datatypes correctly... Does it seem correct?
When I use the function the arguments are declared as
Dim Buffer As Byte() = New Byte(lFileSize) {}
Dim lFileSize As Long
and I call the function like
Dim utdata As Single() = New Single(180) {}
utdata = RunMyFilter(Buffer, lFileSize)
The program compiles allright, but when I run it and it is supposed to "RunMyFilter", the program crashes and tells me:
An unhandled exception of type 'System.Runtime.InteropServices.MarshalDirectiveException' occurred in WindowsApplication1.exe
Additional information: Can not marshal return value.
Do you know what I have made wrong?
Best Regards
Johan