PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → Passage paramètre Windev - ObjC
Passage paramètre Windev - ObjC
Débuté par jérôme, 23 mai 2018 15:36 - 5 réponses
Membre enregistré
34 messages
Popularité : +1 (1 vote)
Posté le 23 mai 2018 - 15:36
Bonjour,
Je cherche actuellement à faire passer un tableau de char d'un code en obj-c à windev.
j'ai d'abord essayé de renvoyer la valeur mais il transforme le tableau en String et celui-ci peut contenir des 0 -> j'ai une chaîne tronqué
J'ai également essayé de renvoyer le pointeur de mon tableau mais même en estimant la taille retournée (je sais ce que je dois recevoir) je n'arrive pas à récupérer l'information.
J'ai alors changé mon fusil d'épaule et passé en paramètre un buffer histoire de récupérer mes valeurs dedans. idem j'ai un tableau vide.

voici la fonction que je cherche à appeler:

void Test(unsigned char* buffer, int* Taille){
int i;
for (i = 0; i < Taille; i++){
buffer[i] = 'i';
}
*Taille = 1;
}


et l'appel:
iTaille est un entier = 6
repIOS est un tableau dynamiquedynamique de iTaille entiers sur 1 octet
Test(&repIOS,&iTaille)
Trace(iTaille+">"+TableauVersChaîne(repIOS))


J'obtient:
1> 0+rc+0+rc+0+rc+0+rc+0+rc+0

or je devrai avoir:
1> 0+rc+1+rc+2+rc+3+rc+4+rc+5


Il s'agit évidemment d'une fonction de test, je peux la changer si besoin mon but étant de récupérer un tableau d'unsigned char.
Membre enregistré
795 messages
Popularité : +40 (42 votes)
Posté le 23 mai 2018 - 16:59
Hi.

Change
buffer[i] = 'i';
to
buffer[i] = i;


Rubén
Membre enregistré
34 messages
Popularité : +1 (1 vote)
Posté le 24 mai 2018 - 08:26
erf, actually.
however even with this code I should have "1> 105 + rc + 105..."

the problem does not come from my test function but from the return I think.
At the begining I used a different function in C, but in order to test I simplify things. (and made a mistake ;) )
Membre enregistré
795 messages
Popularité : +40 (42 votes)
Posté le 24 mai 2018 - 13:19
Hi. You are right, The problem must be somewhere else.

Maybe it's a problem with string encoding in ObjC? The default character encoding in ObjC is ASCII or Unicode? If it is Unicode each character of the string is more than one byte long, so the array you pass and then read will not contain what you expect. The integer value you modify in the function if it is correctly updated.

Look at this https://stackoverflow.com/questions/11193611/get-a-char-from-nsstring-and-convert-to-int…

Rubén
Message modifié, 24 mai 2018 - 13:22
Membre enregistré
34 messages
Popularité : +1 (1 vote)
Posté le 24 mai 2018 - 15:39
I'll give more details maybe.
my unsigned char* must contain something like [0xFF,0x00,0x24,0x24] for exemple.
in that case there is no encoding.

But I see something strange (or not?)
in Windev I trace my buffer adress before and after the call and they are the same but in obj-c process this values is changed as soon as i change his value and nothing change after return statement.

I think that I have to pass a pointer of pointer of char* (unsigned char**) in order to use something like
*buffer = buf; //buf is an unsigned char*


when I use
*iBuffer = 6; //iBuffer is an int* parameter

it works fine. for 1 value...

I tryed so many thing today, I'm a litle confused now about what to do...
Membre enregistré
34 messages
Popularité : +1 (1 vote)
Posté le 25 mai 2018 - 11:28
Bon, après une bonne nuit de sommeil à cogiter la dessus j'ai enfin résolu mon probleme. Si ça peut aider quelqu'un il fallait en fait utiliser un buffer, un int* et memcpy()...
C:
void IOS_TEST(int* pBuf,int* pTaille)
{
char i;
unsigned char* btab;
btab = (unsigned char*) malloc(*pTaille);
for (i = 0; i < *pTaille; i++){
btab[i] = i+66;
}
memcpy(pBuf,btab,*pTaille);
}

Windev:
buf est un Buffer sur 6 octets = " "
temp est un tableau de 6 entiers

QUAND EXCEPTIONEXCEPTION DANS
bVal est un entier = 6
IOS_TEST(&buf,&bVal)
POUR i = 0 _À_ bVal-1
temp[i+1] = BufferVersEntier(buf,i,1)
FIN
Trace("Buff: " + TableauVersChaîne(temp," ") + "( " + bVal + ")")
FAIRE
Trace(TableauVersChaîne(temp," ")+ "( " + bVal + ")"+RC+ExceptionInfo(errComplet))
FIN

RETOUR


Je récupère bien 'A','B','C','D','E','F' (66 à 71) dans mon buffer :)
Merci pour ton temps Rubén, ça fait plaisir de savoir qu'on est pas tout seul parfois ^^
Message modifié, 25 mai 2018 - 11:29