Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VC++ configuration for Building DLLs?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00068689
Message ID:
00068814
Vues:
43
Also, don't forget that if you _AllocHand memory, YOU ARE RESPONSIBLE TO _FreeHand IT! The only exception to this rule is if you return the string to foxpro using the _RetVal function, which uses a value structure, if you return with _RetChar, you must free the handle yourself. Failure to do so will result in a big memory leak. Chaim > >if (!_SetHandSize(parm->p[0].val.ev_handle,parm->p[0].val.ev_length+1)) { >_Error(182); // "Insufficient memory" >} >_HLock(parm->p[0].val.ev_handle); >string = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle); >string[parm->p[0].val.ev_length] = '\0'; >memcpy(destination,string,parm->p[0].val.ev_length+1); >_HUnLock(parm->p[0].val.ev_handle); > Oops! I figured it out by looking at your code! I set the length of the string to the length + 1 and then I set the value of the character after the end of the string to '\0' instead of setting the last character to null. This WAS my code; I'm amazed that it worked at all: if ((mh_out = _AllocHand(parm->p[1].val.ev_length+1)) == 0) _Error(182); /* "Insufficient memory." */ _HLock(mh_out); in_string = (char FAR *) _HandToPtr(parm->p[1].val.ev_handle); out_string = (char FAR *) _HandToPtr(mh_out); *(out_string + parm->p[1].val.ev_length+1) = '\0'; /* _RetChar() needs null terminated string */ Which is wrong, since C and C++ arrays start with 0 not 1! Thank you very much. -Lou.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform