I have a function in C, that has already been written by other People and
now I have to write a .dll with this function, so that I can call it from
the VB 6.0.
The C-function declaration is as follows:
Public Type mw_ReturnTyp
Type As String * ReturnTypTypeLength
Id As String * ReturnTypIdLength
Number As Long
Message As String * ReturnTypMessageLength
LogNo As String * ReturnTypLogNoLength
LogMsgNo As String * ReturnTypLogMsgNoLength
MessageV1 As String * ReturnTypMessageV1Length
MessageV2 As String * ReturnTypMessageV2Length
MessageV3 As String * ReturnTypMessageV3Length
MessageV4 As String * ReturnTypMessageV4Length
RFC_Key As String * ReturnTypRFC_KeyLength
RFC_Message As String * ReturnTypRFC_MessageLength
End Type
Public Type mw_MatInfoTyp
Lfdnr As Long
Matnr As String
Werk As String
Maktx As String
ValueMentorC As String
ValueF As Double
ValueVisulaC1 As String
ValueVisulaC2 As String
Status As String
Existenzkz As String
MessageType As String
MessageId As String
MessageNumber As Long
Message As String
MessageV1 As String
MessageV2 As String
MessageV3 As String
MessageV4 As String
End Type
Declare Sub mw_CaeMatinfo Lib "ex21c.dll" (pMatTblToCheck() As mw_MatInfoTyp,
ByVal AnzMatToCheck As Integer, pMatInfo() As mw_MatInfoTyp, AnzMat As Integer,
Ret As mw_ReturnTyp)
(????) I don't know, if that is right. Anyway I had no idea how I should
declare the double pointer to pMatInfo[] (**pMatInfo[]).
---- form1.frm ----
Option Explicit
Const MaxSearch = 30
Const MaxResults = 200
Dim IndexMat As Integer
Dim IndexWerk As Integer
Dim pMatTblToCheck(MaxSearch) As mw_MatInfoTyp
Dim AnzMatToCheck As Integer
Dim pMatInfo(MaxResults) As mw_MatInfoTyp
Dim AnzMat As Integer
Dim Ret As mw_ReturnTyp
Private Sub cmbInMat_Click()
IndexMat = cmbInMat.ListIndex
End Sub
Private Sub cmdSearch_Click()
Dim n
For n = 0 To cmbInMat.ListCount - 1
pMatTblToCheck(n).Matnr = cmbInMat.List(n)
pMatTblToCheck(n).Werk = cmbInWerk.List(n)
Next
AnzMatToCheck = cmbInMat.ListCount
mw_CaeMatinfo pMatTblToCheck(), AnzMatToCheck, pMatInfo(), AnzMat, Ret
For n = 0 To AnzMat - 1
cmbOutMat.List(n) = pMatInfo(n).Matnr
cmbOutWerk.List(n) = pMatInfo(n).Werk
Next
End Sub
------------------------------------------------
I have also tried another things just as a test, to see if I could pass an
array of structures to a function in a .dll:
Option Explicit
Declare Sub mult Lib "test2.dll" (A() As Customer, B() As Customer)
Const FirstNameLength = 15
Const MiddleNameLength = 12
Const LastNameLength = 20
Public Type Customer
FirstName As String * FirstNameLength
MiddleName As String * MiddleNameLength
LastName As String * LastNameLength
End Type
Global x() As Customer, y() As Customer
---- VB - Form1.frm ---
Private Sub Command1_Click()
Dim i As Integer
ReDim x(50)
ReDim y(50)
For i = 0 To 10
x(i).FirstName = Text1.Text
x(i).MiddleName = Text2.Text
x(i).LastName = Text3.Text
Next
'I have also called the function with different input values in
each structure
mult x(), y()
End Sub
---------------------------------------
That has worked. With the debug, I can see that I got the right results,
at least when the array is small (size about 50). But when I close the VB-program
(when I'm using the VB-debug or running the executable file), an error ocurrs
(unallowed memory handling, or something like that - my Windows is not in
english -) and the program or the VB-studio shuts down.
When I use bigger arrays, the same error occurs already when call the function.
Then when I change:
void _stdcall mult(customer A[], customer B[]);
for :
void _stdcall mult(customer *A[], customer *B[]);
, because that is what I need in my program, that the same error occurs already
when call the function.
Is there any way of passing pointers of arrays of structures from the VB
to a function in a .dll wrutten in C????