1

Topic: Method Marshal. AllocHGlobal (Int32) incorrectly works

I cause Marshal. AllocHGlobal (112) the pointer on a piece of storage in the size of 2137607699712 byte is returned. Such situation is found out only on Windows10 and Win2012 Server R2 (x64), on other OS works normally. How to win the given problem?

2

Re: Method Marshal. AllocHGlobal (Int32) incorrectly works

Hello, Slider_spb, you wrote: S _> I Cause Marshal. AllocHGlobal (112) the pointer on a piece of storage in the size of 2137607699712 byte is returned. S _> such situation is found out only on Windows10 and Win2012 Server R2 (x64), on other OS works normally. S _> how to win the given problem? And unless this method returns the pointer? On idea it should correspond GlobalAlloc.

3

Re: Method Marshal. AllocHGlobal (Int32) incorrectly works

Hello, VTT, you wrote: VTT> Hello, Slider_spb, you wrote: S _>> I Cause Marshal. AllocHGlobal (112) the pointer on a piece of storage in the size of 2137607699712 byte is returned. S _>> such situation is found out only on Windows10 and Win2012 Server R2 (x64), on other OS works normally. S _>> how to win the given problem? VTT> and unless this method returns the pointer? On idea it should correspond GlobalAlloc. IntPtr returns in the description https://msdn.microsoft.com/ru-ru/library/s69bkh17 (v=vs.110).aspx and in the code...

4

Re: Method Marshal. AllocHGlobal (Int32) incorrectly works

Hello, Slider_spb, you wrote: S _> Hello, VTT, you wrote: VTT>> Hello, Slider_spb, you wrote: S _>>> I Cause Marshal. AllocHGlobal (112) the pointer on a piece of storage in the size of 2137607699712 byte is returned. S _>>> such situation is found out only on Windows10 and Win2012 Server R2 (x64), on other OS works normally. S _>>> how to win the given problem? VTT>> and unless this method returns the pointer? On idea it should correspond GlobalAlloc. S _> IntPtr returns in the description https://msdn.microsoft.com/ru-ru/library/s69bkh17 (v=vs.110).aspx and in the code... Yes, but the sense that returned GlobalAlloc actually a descriptor, and for obtaining of the real pointer from it it is necessary to cause the pointer GlobalLock (which can anything and not ).

5

Re: Method Marshal. AllocHGlobal (Int32) incorrectly works

Hello, Slider_spb, you wrote: S _> I Cause Marshal. AllocHGlobal (112) the pointer on a piece of storage in the size of 2137607699712 byte is returned. And you as defined it? using System; using System. Runtime. InteropServices; namespace ConsoleApplication1 {class Program {[DllImport ("kernel32.dll")] static extern IntPtr GlobalSize (IntPtr h); static void Main (string [] args) {IntPtr p = Marshal. AllocHGlobal (112); IntPtr s = GlobalSize (p); System. Console. WriteLine ("Size =" + s);}}}> Size = 112

6

Re: Method Marshal. AllocHGlobal (Int32) incorrectly works

Hello, VTT, you wrote: VTT> Yes, but the sense that returned GlobalAlloc actually a descriptor, and for obtaining of the real pointer from it it is necessary to cause the pointer GlobalLock (which can anything and not ). In Win API, yes, but here it is not necessary When AllocHGlobal calls LocalAlloc, it passes a LMEM_FIXED flag, which causes the allocated memory to be locked in place. https://msdn.microsoft.com/ru-ru/library/s69bkh17 (v=vs.110).aspx