Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 859 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How to send an array to DLL and receive it back? #376552
07/04/11 11:54
07/04/11 11:54
Joined: Jul 2011
Posts: 69
P
pjotr987 Offline OP
Junior Member
pjotr987  Offline OP
Junior Member
P

Joined: Jul 2011
Posts: 69
Hey guys,
to process single variables in DLLFUNCs is easy, but how works the stuff with arrays? In my particular case i want to receive an array from a DLLFUNC. How to do this?

thanks in advance for any help

Re: How to send an array to DLL and receive it back? [Re: pjotr987] #376557
07/04/11 12:27
07/04/11 12:27
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Online
Senior Expert
Quad  Online
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
return it.

Code:
DLLFUNC int* get_array(){
    int* int_array[10];
    int i = 0;
    for(i=0;i<10;i++){
        int_array[i] = 10;
    }
    return int_array;
}



Last edited by Quad; 07/04/11 12:30.

3333333333
Re: How to send an array to DLL and receive it back? [Re: Quad] #376562
07/04/11 13:15
07/04/11 13:15
Joined: Jul 2011
Posts: 69
P
pjotr987 Offline OP
Junior Member
pjotr987  Offline OP
Junior Member
P

Joined: Jul 2011
Posts: 69
Hi Quad, thanks for ur fast reply.
The code u provided causes in my compiler an error telling "
error C2440: 'return': 'int *[10]' cant be converted to 'int *'
any idea?
would be nice if u also can give an example how to call this function from liteC
since u are Expert wink
any other is also welcome
thanks

Re: How to send an array to DLL and receive it back? [Re: pjotr987] #376565
07/04/11 13:27
07/04/11 13:27
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Online
Senior Expert
Quad  Online
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
oops sorry it should be
int int_array[10];

you call it just you call any other DLLFUNC


3333333333
Re: How to send an array to DLL and receive it back? [Re: Quad] #376645
07/05/11 12:40
07/05/11 12:40
Joined: Jul 2011
Posts: 69
P
pjotr987 Offline OP
Junior Member
pjotr987  Offline OP
Junior Member
P

Joined: Jul 2011
Posts: 69
Hi Quad, i hope you are in today.
somehow i fail to call the function you provided in liteC.
i try it the following way:

int test[10]; //the receiving array
int get_array();// preparing function for calling

then in main:

test=get_array();////the call itself

something i make definitely wrong, but could not figure it out frown

i would be very grateful for a little help
thanks for everyone in advance

Re: How to send an array to DLL and receive it back? [Re: pjotr987] #376647
07/05/11 12:46
07/05/11 12:46
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Hi,

I think that the array is already allocated in the DLL, so all you need to do is :

Code:
int *test;  // the receiving array
int *get_array(); // preparing function for calling

....
int main()
{
...
test = get_array();
...
}



But you must be carefull when doing something like this : how and where to free the memory allocated to the array, etc...

Best regards.

Re: How to send an array to DLL and receive it back? [Re: 3dgs_snake] #376984
07/08/11 12:58
07/08/11 12:58
Joined: Jul 2011
Posts: 69
P
pjotr987 Offline OP
Junior Member
pjotr987  Offline OP
Junior Member
P

Joined: Jul 2011
Posts: 69
3dgs_snake thank you for your help
here i put some examples for DLL functions for people, who like me, use DLLs for the first time. But one doubt left. I want now send two arrays to DLL and receive a processed one back but cant get it working.

LiteC:
int* array1[5];//input array
int* array2[5];// input array
int* array3[5];//output array
int* two_arrays(int* xx,int* yy);///declaration
array3=two_arrays(array1,array2);//executing

///DLL code///
DLLFUNC int* two_arrays(int* array1,int* array2)////NOT-OK
{
int array3[5];
array3[0]=array1[0]+array2[0];
array3[1]=array1[1]+array2[1];
array3[2]=array1[2]+array2[2];
array3[3]=array1[3]+array2[3];
array3[4]=array1[4]+array2[4];
return array3;

}

what is wrong?
anyone has an idea?


here is the mentioned working code for processing arrays in DLL:
Functions in DLL file


DLLFUNC int* tester( )///////////////Function 1
{
int r[10];
// set the seed

for (int i = 0; i < 5; ++i)
{
r[i] = (50+i)*20;
}
return r;
}

DLLFUNC void get_array(VECTOR* int_array)/////////////Function 2
{
int_array->x = 10;
int_array->y = 20;
int_array->z = 30;
}
////////////77

Code in liteC:
/////////////////FUNCTION 1
int* array1[10];//array preparation
int* tester( );//Function declaration
array=tester();// executing the function
printf("array1 %d",array[1]);///shows the result in array[1]

////////////////function 2///////////////

VECTOR* test_vec [3];////array for DLL Function 2
void get_array(VECTOR* xx);///Declaration of the DLL Function 2
get_array(test_vec);/////call of the function
printf("test %d",test_vec->x);////////shows the result in x(y and z can also be shown just by using them instead of x)

i hope it helps someone

Re: How to send an array to DLL and receive it back? [Re: pjotr987] #376986
07/08/11 13:40
07/08/11 13:40
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Hi,

  • The parameters are int arrays not array of int pointers => int array1[5].
  • The result is an array of int so an int pointer to the first element of the array => int* array3.


Code:
int array1[5];//input array
int array2[5];// input array
int* array3;//output array
int* two_arrays(int* xx,int* yy);///declaration
array3=two_arrays(array1,array2);//executing



Best regards.

Re: How to send an array to DLL and receive it back? [Re: 3dgs_snake] #376991
07/08/11 15:55
07/08/11 15:55
Joined: Jul 2011
Posts: 69
P
pjotr987 Offline OP
Junior Member
pjotr987  Offline OP
Junior Member
P

Joined: Jul 2011
Posts: 69
thanks man ur my hero


Moderated by  TWO 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1