Bonjour,

Question :
Si j'ecrit comme ceux-ci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
    [StructLayout(LayoutKind.Sequential)]
    unsafe struct PCd
    {
        public bool tol;
        public int vxc;
        public void* str;
    }
...
...
int test()
{
....
...
unsafe{
cl=new PCd();
fixed (byte*p = &cl)
{
*p=1; //met tol à true //ligne 1
}
*(p+4)  = 58; //ligne 2 
...
...
}

Question ?
Est ce correct que la ligne 2 soit en dehors de fixed ?

Est ce correcte pour le seconde code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
 unsafe struct FE{
        internal byte* p;
    }
    public partial class Form1 : Form
    {
        FE vv;
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            byte[] pp = new byte[1000];
            pp[8] = 88;
            unsafe
            {
              //  byte* vp = null;
                fixed (byte *p = pp)
                {
                    vv.p = p;
                }
 
                Thread.Sleep(1000);
 
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
 
 
                unsafe
                {
                    if (vv.p != null)
                    {
                        vv.p[9] = 45;
                        vv.p[11] = 47;
                        vv.p[13] = 51;
                    }
                }
 
 
        }
Merci