Passing array as parameter to a dll?

Just starting out? Need help? Post your questions and find answers here.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Passing array as parameter to a dll?

Post 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
ARGENTINA WORLD CHAMPION
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

Any more details?

Passing pointer to array? Global mem? locked?
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post 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)
ARGENTINA WORLD CHAMPION
Mr Skunk
User
User
Posts: 12
Joined: Wed May 07, 2003 3:40 pm

Post 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...
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
Mr Skunk
User
User
Posts: 12
Joined: Wed May 07, 2003 3:40 pm

Post 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
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
User avatar
waffle
Enthusiast
Enthusiast
Posts: 129
Joined: Mon May 12, 2003 1:34 pm
Location: USA
Contact:

Post 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.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post 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 : )
ARGENTINA WORLD CHAMPION
Manolo
User
User
Posts: 75
Joined: Fri Apr 25, 2003 7:06 pm
Location: Spain

Post 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:
Return to the forum
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post 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
ARGENTINA WORLD CHAMPION
Post Reply