Page 1 of 1
Passing array as parameter to a dll?
Posted: Fri May 09, 2003 6:22 pm
by ricardo
Hi,
I need to pass an array as parameter to a dll function, i tried some ways to do it but fails. Can anybody help?
Thanks in advance
Posted: Fri May 09, 2003 6:43 pm
by dmoc
Any more details?
Passing pointer to array? Global mem? locked?
Posted: Fri May 09, 2003 7:03 pm
by ricardo
dmoc wrote:Any more details?
Passing pointer to array? Global mem? locked?
Dim MyArrar.s(2)
MyArray(0) = "Hello"
MyArray(1) = "World"
CallfunctionFast(*MyFunction,@MyArray(0))
or
CallfunctionFast(*MyFunction,@MyArray())
or
CallfunctionFast(*MyFunction,@MyArray)
Dosent works, the function is asking for a pointer (i think) to the array.
In VB it was easy:
ReDim params(2) As String
params(0) = "Hello, I'm param1"
params(1) = "Hi, I'm param2"
RunIt(params)
Posted: Fri May 09, 2003 8:01 pm
by Mr Skunk
Hi Ricardo, I checked how arrays store strings.
@MyArray() does not point to the string, but to a Long which points to the real string.
Does your function takes care of that? or does it consider you have to pass directly the address of the real string?
If this is the second, you can't use array to pass the strings.
@MyArray() is the adresse of the pointer which point to the real string.
PeekL(@MyArray())) is the address of the real string. But if you use PeekL(...) you only point to one string not to the entiere array.
Hope it can help you to find a solution...
Posted: Sat May 10, 2003 12:08 am
by freak
@MyArray() gives the pointer to the array, so at the address you get, there is an array of string pointers actually (as Mr. Skunk said).
@MyArray(0) gives the pointer directly to the first string, this can't be what you need here, because there is no array on that address, but a
string variable.
@MyArray
This is considered a variable. variables can have the same name as a
Array, but they are different things then. So this creates a LONG variable,
and gives the address of that LONG, also not what you need.
the @MyArray() should be compleetly right, there must be some other
problem why it doesn't work with that.
Timo
Posted: Sat May 10, 2003 12:34 am
by Mr Skunk
freak wrote:the @MyArray() should be compleetly right, there must be some other problem why it doesn't work with that.
If the function doesn't care that @MyArray() gives a pointer to the address of the string instead of the address the string directely, this can be the problem that ricardo is looking for
Posted: Sat May 10, 2003 12:46 am
by freak
This depends on that a VB string array is. I would guess that it is also
an array of pointers, but i can be wrong here.
It it is not the same in PB, then you can't just pass it like that.
Some VB guy need's to answer this
Timo
Posted: Tue May 13, 2003 4:54 am
by waffle
i had that problem before....
way back when i used borland c++ 3.0
this is why many languages do not support strings in structure arrays that are of variable lengths. It is almost impossible to determine
1 - the size of each string
2 - how many strings in the array
3 - how many dimentions the array has
The way i solved the problem in a .dll i wrote was to permit passing those paramenters to the function and also to use fixed length strings.
In that manner, each string should be sequential in memory, say 40 bytes for the first string and so on. Using that method, passing the address of the fist string, with the string length, number of strings and so forth, the strings can be read by the dll..... in theory. Unless VB places the strings in random memory and only passes the array of string pointers in which case you must access each pointer to obtain the string. But, this does create many possibilities for a system crash if you just start reading and writing directly to memory that may be protected..... or at least thought to be protected.
Posted: Tue May 13, 2003 7:37 am
by ricardo
As far as i can see now, the only wat to do it is sending and array of longs in where every long is a pointer to the string.
In fact what im trying to do is to send a variable number of parameters to some function... and as i can't know how many parameters the function will have since its a user function.
Im trying to find a solution.
Thanks for your help : )
Posted: Tue May 13, 2003 8:32 am
by Manolo
Hi Ricardo,
You dont need call with pointer. Only the name of the array, for example:
CallfunctionFast(*MyFunction,MyArray())
And you code will work perfectly
Regards,
Manolo :roll:
Posted: Wed May 14, 2003 4:36 am
by ricardo
Manolo wrote:Hi Ricardo,
You dont need call with pointer. Only the name of the array, for example:
CallfunctionFast(*MyFunction,MyArray())
And you code will work perfectly
Regards,
Manolo :roll:
Hi Manolo
But it dosen't works with a C++ dll at least not for me. I finally found a workaround : ) Doing it by other way (not an array)
Thanks