|
-
August 2nd, 2005, 02:57 AM
#1
what datatype to pass to DLL?
Hi!
I want to call a function in a DLL (written in C++). One of the arguments expected is of type "array of void pointers".
When passing the datatype "IntPrt" from VB.net, the 4 element size array from VB.net is truncated to a one element size array after the call.
What argument should be passed from VB.net to handle "arrays of void pointers"??
Thanks!!!
Adri Gerritsen
-
August 2nd, 2005, 07:11 AM
#2
Re: what datatype to pass to DLL?
an array of void pointers would be a pointer of pointer to me.. so a pointer to the first address of your structure would be good.
Nicolas Bohemier
-
August 2nd, 2005, 07:36 AM
#3
Re: what datatype to pass to DLL?
Here some code: C++ DLL code
Code:
//a C++ dll function taking an array
int _stdcall FillArr(int * inArr, int ArrSize) {
int LoopArr; // Loop variable
// Make sure they didn't pass anything silly
if (ArrSize < 1) return 0;
// Fill the array
for (LoopArr = 0; LoopArr < ArrSize; LoopArr++) {
inArr[LoopArr] = LoopArr;
}
// Return 1 if all went well
return 1;
}
Here the VB code:
Code:
'VB code which calls the dll function.
Private Sub Form_Load()
Dim MyArr() As Long
Dim ArrSize As Long
Dim LoopArr As Long
Dim MakeString As String
' Create the array
ArrSize = 10
ReDim MyArr(ArrSize - 1) As Long
' Get the DLL to fill the array
' Note here that we pass the first entry of the array and not the
' array pointer itself, this is to make sure we fill the array
' data and not overwrite the array descriptor by mistake.
Call MsgBox(FillArr(MyArr(0), ArrSize))
' Loop through the new array contents and make a string message
For LoopArr = 0 To ArrSize - 1
MakeString = MakeString & MyArr(LoopArr) & vbCrLf
Next LoopArr
' Report array contents
Call MsgBox(MakeString)
End Sub
The point to note here is that we pass the first entry of the array and not the array pointer itself, this is to make sure we fill the array data and not overwrite the array descriptor by mistake. This seems to be the issue with your code. Hope this helps.
If not then please paste some code so that we can have a look at what is happening.
Here are some links to some good articles upon this:
1. MSDN - How To Pass Arrays Between Visual Basic and C
2. FlipCode - Interfacing Visual Basic And C++
3. Passing Arrays to a DLL
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|