survcopt
Messages postés224Date d'inscriptionmardi 27 mai 2003StatutMembreDernière intervention13 mai 2022
-
6 juin 2007 à 13:22
Lutinore
Messages postés3246Date d'inscriptionlundi 25 avril 2005StatutMembreDernière intervention27 octobre 2012
-
6 juin 2007 à 14:38
Bonjour
Je veux appeller une fonction dont un des paramètres doit être nul or ce paramètre est une structure comment puis-je declarer une structure nulle ?
Merci
cs_Bidou
Messages postés5486Date d'inscriptiondimanche 4 août 2002StatutMembreDernière intervention20 juin 201361 6 juin 2007 à 13:43
Salut,
On ne peut pas rendre une structure null (elle n'est pas sur le heap)
A la place, tu peux mettre une property static qui donne une valeur par défaut à ta structure.
Regarde par exemple la structure Point (System.Drawing) qui a une property static Empty.
survcopt
Messages postés224Date d'inscriptionmardi 27 mai 2003StatutMembreDernière intervention13 mai 20223 6 juin 2007 à 13:54
Ben non en fait car ma structure est de ce type
public struct GM_Projection_t
{
public PROJSYS ProjSys; // Projection system
public DATUM Datum; // Horizontal datum
public UNIT Unit; // Ground units
public uint NumAttrs; // Number of attributes in attribute list
public IntPtr AttrList; // Pointer to attribute list. Pointer to GM_ProjAttrValue_t
};
La doc de ma dll me dit
GM_Error_t32 GM_ProjectPoint
(
double aXIn, // IN: X coordinate of input point
double aYIn, // IN: Y coordinate of input point
double* aXOut, // OUT: X coordinate of output point
double* aYOut, // OUT: Y coordinate of output point
const GM_Projection_t* aProjIn, // IN: projection to convert from (NULL for current)
const GM_Projection_t* aProjOut // IN: projection to convert to (NULL for current)
);
et je la déclare en c# comme ceci
[DllImport(DLLFileName, EntryPoint = "GM_ProjectPoint")]
public static extern GM_Error_t32 GM_ProjectPoint(double aXIn, double aYIn, out double aXOut, out double aYOut, ref GM_Projection_t aProjIn, ref GM_Projection_t aProjOut);
et je voudrais essayer de voir comment la fonction reagit avec un parametre nul
Merci
Lutinore
Messages postés3246Date d'inscriptionlundi 25 avril 2005StatutMembreDernière intervention27 octobre 201241 6 juin 2007 à 14:35
Pour passer une structure NULL, c-à-d un pointeur NULL, c'est IntPtr.Zero ( ou null si la prototype est unsafe ). mais je croyais que tu avais déja testé on en a parlé >ICI<
Vous n’avez pas trouvé la réponse que vous recherchez ?
Lutinore
Messages postés3246Date d'inscriptionlundi 25 avril 2005StatutMembreDernière intervention27 octobre 201241 6 juin 2007 à 14:38
Bien sur tu dois modifier aussi le prototype, tu peux très bien définir 2 prototypes ( comme une surcharge de fonction ) l'un avec des ref l'autre avec des IntPtr.