Transferring arrays from C DLL's to VB.Net

  • Thread starter Thread starter Michael Fitzpatrick
  • Start date Start date
M

Michael Fitzpatrick

Transferring arrays from C DLL's to VB.Net

I have a DLL written in C. This DLL reads a text file and creates a several
very large arrays, 500,000 points and even larger. I would like the get the
data in VB.Net so that I can plot it. Presently I am creating an equally
sized array in VB and copying the data from the DLL's array into the VB
array.

There must be a better way. I looked into using a SAFEARRAY but it looks to
me that VB.Net doesn't use them as a native array structure.

Can I get the DLL's pointer to the array and use it in VB.Net?
Can I otherwise package the array in the DLL so that I do not need to
duplicate it?

################################
Details:

The VB.Net program is just a UI for the DLL's and allows the user to select
the file to process and will get the data and plot it, so the VB is just a
shell for the real work being done in the C DLL's.

The DLL's are used in a test system. The data is read from a text file and
processed, so the arrays are not the data in the text file, but rather an
analysis of that data. C Dll's are used so that I can be platform
independent, that is, I need to be able to use this DLL code in other test
systems like National Instruments Labview and Agilent Vee.

I have the system working now, except that it is slower and uses more
resources because of the arrays, there are 30 in all. I usually duplicate 2
at a time, but now I find myself re-reading the same arrays several times
and I am looking for a way to improve performance.
 
You can create a managed C++ class that implements an appropriate collection
interface,
wrapping up a pointer to the array.

If you do not require random access to the array elements you can get away
with
implementing either System::Collections::IEnumerable or
System::Collections::ICollection.
If you require random access to the array you would need to implement
System::Collections::IList, or add an indexer to your class.
 
You could use safearrays and then embed marshalling commands in th
dllimport function or declare function prototypes that you are using in VB.NE
to call the c routines. Don't forget to specify the subarraytype when marshalling.
 
Back
Top