E
eusebiu
Hello... I am making a Sytem.IntPtr with Marshal.AllocHGlobal(int)
(Allocates memory from the unmanaged memory of the process using
GlobalAlloc - MSDN Definition for Marshal.AllocHGlobal) and after
copying the data from a byte[] buffer to the IntPtr(with
Marshal.Copy), I send the IntPtr to an unmanaged library. In the
unmanaged library the function's signature has a unsigned char *
parameter(my IntPtr from C#) and in function's code-block I want to
get the pointer's value.
I use this code to put the pointer's value into a txt file
//C++ code
char* b = new char[10];
sprintf(b,"%2d", (int)pMyPointer);
ofstream out((char *)"aaa.txt");
out.write((const char*)b, 10);
delete[] b;
In C#, when debugging, I have a value for my System.IntPtr but when I
open the txt file, I see other value.
Why is that? Isn't Marshal.AllocHGlobal return pointer a pointer on
the unmanaged heap to an unmanaged memory?
Thanks
(Allocates memory from the unmanaged memory of the process using
GlobalAlloc - MSDN Definition for Marshal.AllocHGlobal) and after
copying the data from a byte[] buffer to the IntPtr(with
Marshal.Copy), I send the IntPtr to an unmanaged library. In the
unmanaged library the function's signature has a unsigned char *
parameter(my IntPtr from C#) and in function's code-block I want to
get the pointer's value.
I use this code to put the pointer's value into a txt file
//C++ code
char* b = new char[10];
sprintf(b,"%2d", (int)pMyPointer);
ofstream out((char *)"aaa.txt");
out.write((const char*)b, 10);
delete[] b;
In C#, when debugging, I have a value for my System.IntPtr but when I
open the txt file, I see other value.
Why is that? Isn't Marshal.AllocHGlobal return pointer a pointer on
the unmanaged heap to an unmanaged memory?
Thanks