Hi,
I have built a VC++.NET dll function in which you pass an array of double data and 2 additional input arguments and it returns a pointer of the data address and 2 additional scallar values.
#define CRCDLLEXPORT __declspec(dllexport) long __stdcall
/**** Methods ****/
CRCDLLEXPORT m_CrcCheck (double *pInput, // Input short nInputLength, // Input value short nCrcLength, // Input value [out] double *pOutput, // Output short *pOutputLength, // Output
short *pCrcRes); // Output
I built a VB.NET project to call the above function and extract the (pOutput) data by declaring ByRef
pOutput as it follows and setting Dim pOut() As Double
The way I am calling the function is:
nError = m_CrcCheck(pIn(0), x1, ...., pOut(0), ....)
When I am stepping into the dll function (in debug mode) I can see that *pOutput contents are updated but when I am stepping into the VB.NET code again the contents are 0.
Note that I do not delete the memory in the C++ function.
I have used the same approach in VB6 and as far I remember it worked fine.
Any suggestions/comments are welcome. Thanks.
The VB code is (in the VB class):
Public Declare Function m_CrcCheck Lib "CRC_DLL.dll" _
(ByRef pInput As Double, _
ByVal nInputLength As Short, _
ByVal nCrcLength As Short, _
ByRef pOutput As Double, _
ByRef pOutputLength As Short, _
ByRef pCrcRes As Short) As Integer
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim pOut() As Double
Dim nInLen As Short
Dim i As Short
Dim nError As Integer
Dim nCrcLen As Short
Dim pOutLen As Short
Dim pCrcRes As Short
Dim pIn() As Double = {1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1}
nInLen = pIn.Length
nCrcLen = 8
ReDim pOut(nInLen - 1)
nError = m_CrcCheck(pIn(0), nInLen, nCrcLen, pOut(0), pOutLen, pCrcRes)
End Sub