Passing array as parameter to a dll?
Passing array as parameter to a dll?
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
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
ARGENTINA WORLD CHAMPION
Dim MyArrar.s(2)dmoc wrote:Any more details?
Passing pointer to array? Global mem? locked?
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)
ARGENTINA WORLD CHAMPION
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...
@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...
@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
@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
quidquid Latine dictum sit altum videtur
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 forfreak wrote:the @MyArray() should be compleetly right, there must be some other problem why it doesn't work with that.
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.
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.
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 : )
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 : )
ARGENTINA WORLD CHAMPION
Hi ManoloManolo 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:
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
ARGENTINA WORLD CHAMPION