about DLL function char* array parameter

 

i wrote a function


void bb(char* test[3])

{

test[0] = "name1";

test[1]= "name2";

test[2]="name3";

}

use win console function to call bb,


int main()

{

char* abc[3];

bb(abc);

cout<<abc[0]<<"\n";

cout<<abc[1]<<"\n";

cout<<abc[2]<<"\n";

}


that works fine.


i export the function bb from dll

and i call it from mq4.

in import i use

#import "test.dll"

void bb(string& aa[3])

#import

below i call this bb function

string test[3];

bb(test);

print(test[0]) this print "name2"

print(test[1]) this print null

print(test[2]) this print null


i don't get it why test[0] get name2 not name 1 or name3 and the others are null


what is the mistake of my code ? thank you for your help.

 

If you declare your array size as 3, you use array indexes 0 1 2 not index 1 2 3.

That is one problem.

 

sorry for that, it is 0, 1, 2, that is my typing mistake.

and now, i changed the function like this

void f(char* (&p)[3])
{
    p[0] ="test1";
    p[1] = "test2";
    p[2] = "test3";
}

and write it to a dll.

in mq4

#import test.dll

string test[3]

f(test)

still test[0]= "test2" and test[1] test[2] is null.

but i wrote it in vc++ and use console to call that dll, the result is right. so maybe this is a bug. but if it is't please give some help. thank you.

 

Try mq4

#import "test.dll"
   void f(string& test[]);
#import


int start(){
   string test[3];
   f(test);
   Print(test[0]);
   Print(test[1]);
   Print(test[2]);
   return(0);
}

and C

MT4_EXPFUNC void __stdcall f(char* p)
{
    p[0] = "test1";
    p[1] = "test2";
    p[2] = "test3";
}
 
phy:

Try mq4

#import "test.dll"
   void f(string& test[]);
#import


int start(){
   string test[3];
   f(test);
   Print(test[0]);
   Print(test[1]);
   Print(test[2]);
   return(0);
}

and C

MT4_EXPFUNC void __stdcall f(char* p)
{
    p[0] = "test1";
    p[1] = "test2";
    p[2] = "test3";
}

thank you for your reply.

i have tried c code.

and it reports " error c2440: '= ' : cannot convert from 'const char[6]' to 'char'

have you tested the code ? thank you.

 
phy please comin. i need you. how to resolve this.
 

void bb(char* test[3])

void f(string& test[]);

MT4_EXPFUNC void __stdcall f(char* p)

char* test[3]) != string& test[] != char* p ???

which is your function or you have 3 functions ?

Reason: