Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
1 rating:
 1 out of 5     Rate this Document

How Can I Pass an Array Between an ANSI C DLL and Visual Basic 6?

Primary Software: Measurement Studio>>Visual Basic Support
Primary Software Version: 1.0
Primary Software Fixed Version: N/A
Secondary Software: Measurement Studio>>Visual C++ Support

Problem:
When I try to call the an ANSI C function that fills in an array from a DLL that I created, it crashes Visual Basic 6 (VB 6).  Why does the crash in VB 6 happen when the ANSI C DLL tries to assign data to the array that is passed from V B6 to the ANSI C DLL?

Solution:
ANSI C and Visual Basic 6 (VB 6) store array differently so you cannot pass an array from VB 6 and an ANSI C DLL the same way you would pass an array to a VB 6 function.  You have to pass the array as a reference to the datatype that the array consists of and then call the function with the first element in the array.

For example:

The function being called in the ANSI C DLL is declared as this:

    int32 __stdcall ReadArray(double readArray[])


The prototype for the function call in VB 6 needs to be declared like this:

    Declare Function ReadArray (ByRef readArray As Double)


Then you call the function in VB 6 with the first element in the Array:

    ReadArray(Data(0))

Related Links:

Attachments:





Report Date: 01/11/2008
Last Updated: 02/19/2008
Document ID: 4HAEHR9S

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit