Marshalling from unmanaged to managed code
- From: "Victor" <big.boss@xxxxxxxxxxx>
- Date: 11 Aug 2005 12:43:30 -0700
Hi everybody,
in my C#-class Form1 there are following elements:
a)
[StructLayout(LayoutKind.Sequential, Pack = 1)]
private class _data {
[MarshalAs(UnmanagedType.ByValArray,SizeConst=90000)]
public ushort[] buf;
public _data() {
buf = new ushort[90000];
}
}
_data data;
b)
[StructLayout(LayoutKind.Sequential, Pack = 4)]
internal unsafe struct _pult {
public byte instr;
public void* pointer;
}
_pult pult;
b)
A thread with following contents (partially omitted):
private unsafe void threadFunc() {
data = new _data;
fixed (_pult* ptr = &pult) {
ptr->instr = 1;
IntPtr point = Marshal.AllocHGlobal(90000);
ptr->pointer = (void*)point;
while (ptr->instr) {
Marshal.PtrToStructure(point,dataMic);
Thread.Sleep(25);
}
Marshal.FreeHGlobal(point);
}
}
There is another thread coded inside a C++ DLL; this thread
writes a regularly updated array of 30,000 USHORT's to the
address ptr->pointer. I hope to be able to see those values
within my managed code as members of the array 'data.buf'
indexed from [0] thru [29999].
The reality is somehow different : I do see the first
16384 (!) array elements [0]...[16383], whereas the rest
remains rigidly 0, notwithstanding the real values in the
memory area on the address 'ptr->pointer'...
What could cause this behaviour?
Thank you in advance for your time and attention to my problem.
Regards
Victor
.
- Follow-Ups:
- Re: Marshalling from unmanaged to managed code
- From: Willy Denoyette [MVP]
- Re: Marshalling from unmanaged to managed code
- Prev by Date: Re: Incorrect value when converting accountExpires to long
- Next by Date: Re: ReadXml for DataSet chokes if the root element has an attribute?
- Previous by thread: dynamic DLL loading
- Next by thread: Re: Marshalling from unmanaged to managed code
- Index(es):