>You mean that I can pass only one NTS from C to Fox?
Here's your program:
typedef struct tst_stru
{
int iVal;
} TST_STRU;
TST_STRU getstru()
{
TST_STRU local_struct;
local_struct.iVal = 154;
return (local_struct);
}
And here's what happens in C:
1. local_struct is allocated on the stack (and it will be deallocated as soon as the getstru() function ends).
2. The iVal member is assigned.
3. The local_struct is copied and this copy is returned to the caller, the local_struct is deallocated.
Because you declared (in VFP) that getstru() function returns a string, the returned structure is interpreted as pointer to char. So, the first 4 bytes of the structure are taken as pointer to char (in this case, 154 is taken as the memory address 154). So, VFP will try to read the memory (being a string, it will read up to the first chr(0) if the address is correct) from that pointer (address 154) which is an incorrect memory address.
If you want to receive a string in VFP, here's what you have to do:
TST_STRU* getstru()
{
TST_STRU* local_struct = malloc(sizeof(TST_STRU));
// Or, in C++:
// TST_STRU* local_struct = new TST_STRU;
local_struct->iVal = 154;
return (local_struct);
}
But this will not work because your struct will contain chr(0) and VFP will not read beyond it. It is also a little problematic because you allocate memory inside the dll function and we don't know if VFP will use this memory or it will copy the value into a separate memory area. So, you don't know if the memory will be properly deallocated (probably it won't be).
So, in order to recap all this, return the struct into a char* param (you pass a long enough string from VFP).
Vlad
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement