Re: Can subroutine in VB6 DLL accept array variable argument???



An array in VB6 is not conformant with a native array in C, but is a
SAFEARRAY. Since your API doesn't accept a SAFEARRAY, you cannot use a VB6
array. Passing (0) sort of fools the C API, but not the VB6 code.

"Felix Cheang" <felix-tm_cheang@xxxxxxxxxxx> wrote in message
news:ef6FKC%23zFHA.3180@xxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> I would like to know if it's possible to pass array variable to a VB
> DLL. I managed to create an ActiveX DLL on VB and convert it to Windows
> DLL by including a .def file to the VB linker.
>
> I have no problem passing variable to the functions in the VB DLL. When
> comes to passing array to the subroutine, my program crashes. What I
> want to do is to have a subroutine in the DLL file to do some processes
> and update an array of variable (which I passed to it) with data so that
> EXE can make use of these array variables' data.
>
> Below is one of a sub in the DLL file that I created,
>
> ****************************************
> Public Sub WriteReport(OutputReportData() As Byte)
>
> 'Send data to the device.
>
> Dim Count As Integer
> Dim NumberOfBytesRead As Long
> Dim NumberOfBytesToSend As Long
> Dim NumberOfBytesWritten As Long
> Dim ReadBuffer() As Byte
> Dim SendBuffer() As Byte
>
> 'The SendBuffer array begins at 0, so subtract 1 from the number of
> bytes.
>
> ReDim SendBuffer(Capabilities.OutputReportByteLength - 1)
>
> '***********************************************************************
> *******
> 'WriteFile
> 'Sends a report to the device.
> 'Returns: success or failure.
> 'Requires: the handle returned by CreateFile and
> 'The output report byte length returned by HidP_GetCaps
> '***********************************************************************
> *******
>
> 'The first byte is the Report ID
>
> SendBuffer(0) = 0
>
> 'The next bytes are data
>
> For Count = 1 To Capabilities.OutputReportByteLength - 1
> SendBuffer(Count) = OutputReportData(Count - 1)
> Next Count
>
> NumberOfBytesWritten = 0
>
> Result = WriteFile _
> (HIDHandle, _
> SendBuffer(0), _
> CLng(Capabilities.OutputReportByteLength), _
> NumberOfBytesWritten, _
> 0)
> 'Call DisplayResultOfAPICall("WriteFile")
>
> 'lstResults.AddItem " OutputReportByteLength = " &
> Capabilities.OutputReportByteLength
> 'lstResults.AddItem " NumberOfBytesWritten = " & NumberOfBytesWritten
> 'lstResults.AddItem " Report ID: " & SendBuffer(0)
> 'lstResults.AddItem " Report Data:";
>
> 'For Count = 1 To UBound(SendBuffer)
> ' lstResults.AddItem " " & Hex$(SendBuffer(Count))
> 'Next Count
>
> End Sub
> ***********************************************
>
> The DLL crashed when it execute the following statement,
>
> For Count = 1 To Capabilities.OutputReportByteLength - 1
> SendBuffer(Count) = OutputReportData(Count - 1)
> Next Count
>
> It gives type mismatch. I believe the mismatch should be on the
> OutputReportData(). Of course on the EXE program declaration part, I
> declare OutputReportData by reference as follow,
>
> Public Declare Sub WriteReport Lib "USBLib.dll" (ByRef OutputReportData
> As Byte)
>
> I declared OutputReportData as public array,
>
> Public OutputReportData(8) As Byte
>
> On the calling sub statement side, I passed the OutputReportData array
> argument to the DLL subroutine as follow,
>
> WriteReport OutputReportData(0)
>
> Can someone tell me what's wrong with my code?
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***


.



Relevant Pages

  • Can subroutine in VB6 DLL accept array variable argument???
    ... I would like to know if it's possible to pass array variable to a VB ... I managed to create an ActiveX DLL on VB and convert it to Windows ... EXE can make use of these array variables' data. ... OutputReportData(). ...
    (microsoft.public.vb.general.discussion)
  • Re: Is a Thread appropriate?
    ... >> Now, if you are not doing dynamic loading of the DLL, you shouldn't need GetProcAddress. ... >> Note that it is foolish to create a char array, particularly a char array of a fixed size. ... >> If you need to declare a separate variable, ... without necessity. ...
    (microsoft.public.vc.mfc)
  • Re: VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.fortran)
  • VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.fortran)
  • Re: VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.basic.visual.misc)