@@ -250,52 +250,6 @@ public static IntPtr GetHINSTANCE(Module m)
250250        [ MethodImpl ( MethodImplOptions . InternalCall ) ] 
251251        internal  static extern Exception  GetExceptionForHRInternal ( int  errorCode ,  IntPtr  errorInfo ) ; 
252252
253-         public  static IntPtr  AllocHGlobal ( IntPtr  cb ) 
254-         { 
255-             // For backwards compatibility on 32 bit platforms, ensure we pass values between 
256-             // int.MaxValue and uint.MaxValue to Windows.  If the binary has had the 
257-             // LARGEADDRESSAWARE bit set in the PE header, it may get 3 or 4 GB of user mode 
258-             // address space.  It is remotely that those allocations could have succeeded, 
259-             // though I couldn't reproduce that.  In either case, that means we should continue 
260-             // throwing an OOM instead of an ArgumentOutOfRangeException for "negative" amounts of memory. 
261-             UIntPtr  numBytes ; 
262- #if TARGET_64BIT 
263-             numBytes  =  new  UIntPtr ( unchecked ( ( ulong ) cb . ToInt64 ( ) ) ) ; 
264- #else // 32 
265-             numBytes  =  new  UIntPtr ( unchecked ( ( uint ) cb . ToInt32 ( ) ) ) ; 
266- #endif
267- 
268-             IntPtr  pNewMem  =  Interop . Kernel32 . LocalAlloc ( Interop . Kernel32 . LMEM_FIXED ,  unchecked ( numBytes ) ) ; 
269-             if  ( pNewMem  ==  IntPtr . Zero ) 
270-             { 
271-                 throw  new  OutOfMemoryException ( ) ; 
272-             } 
273- 
274-             return  pNewMem ; 
275-         } 
276- 
277-         public  static void  FreeHGlobal ( IntPtr  hglobal ) 
278-         { 
279-             if  ( ! IsNullOrWin32Atom ( hglobal ) ) 
280-             { 
281-                 if  ( IntPtr . Zero  !=  Interop . Kernel32 . LocalFree ( hglobal ) ) 
282-                 { 
283-                     ThrowExceptionForHR ( GetHRForLastWin32Error ( ) ) ; 
284-                 } 
285-             } 
286-         } 
287- 
288-         public  static IntPtr  ReAllocHGlobal ( IntPtr  pv ,  IntPtr  cb ) 
289-         { 
290-             IntPtr  pNewMem  =  Interop . Kernel32 . LocalReAlloc ( pv ,  cb ,  Interop . Kernel32 . LMEM_MOVEABLE ) ; 
291-             if  ( pNewMem  ==  IntPtr . Zero ) 
292-             { 
293-                 throw  new  OutOfMemoryException ( ) ; 
294-             } 
295- 
296-             return  pNewMem ; 
297-         } 
298- 
299253#if FEATURE_COMINTEROP 
300254        /// <summary> 
301255        /// Converts the CLR exception to an HRESULT. This function also sets 
@@ -481,83 +435,6 @@ public static IntPtr CreateAggregatedObject<T>(IntPtr pOuter, T o) where T : not
481435        [ MethodImpl ( MethodImplOptions . InternalCall ) ] 
482436        public  static extern bool  IsComObject ( object  o ) ; 
483437
484- #endif // FEATURE_COMINTEROP 
485- 
486-         public  static IntPtr  AllocCoTaskMem ( int  cb ) 
487-         { 
488-             IntPtr  pNewMem  =  Interop . Ole32 . CoTaskMemAlloc ( new  UIntPtr ( ( uint ) cb ) ) ; 
489-             if  ( pNewMem  ==  IntPtr . Zero ) 
490-             { 
491-                 throw  new  OutOfMemoryException ( ) ; 
492-             } 
493- 
494-             return  pNewMem ; 
495-         } 
496- 
497-         public  static void  FreeCoTaskMem ( IntPtr  ptr ) 
498-         { 
499-             if  ( ! IsNullOrWin32Atom ( ptr ) ) 
500-             { 
501-                 Interop . Ole32 . CoTaskMemFree ( ptr ) ; 
502-             } 
503-         } 
504- 
505-         public  static IntPtr  ReAllocCoTaskMem ( IntPtr  pv ,  int  cb ) 
506-         { 
507-             IntPtr  pNewMem  =  Interop . Ole32 . CoTaskMemRealloc ( pv ,  new  UIntPtr ( ( uint ) cb ) ) ; 
508-             if  ( pNewMem  ==  IntPtr . Zero  &&  cb  !=  0 ) 
509-             { 
510-                 throw  new  OutOfMemoryException ( ) ; 
511-             } 
512- 
513-             return  pNewMem ; 
514-         } 
515- 
516-         internal  static IntPtr  AllocBSTR ( int  length ) 
517-         { 
518-             IntPtr  bstr  =  Interop . OleAut32 . SysAllocStringLen ( null ,  length ) ; 
519-             if  ( bstr  ==  IntPtr . Zero ) 
520-             { 
521-                 throw  new  OutOfMemoryException ( ) ; 
522-             } 
523-             return  bstr ; 
524-         } 
525- 
526-         public  static void  FreeBSTR ( IntPtr  ptr ) 
527-         { 
528-             if  ( ! IsNullOrWin32Atom ( ptr ) ) 
529-             { 
530-                 Interop . OleAut32 . SysFreeString ( ptr ) ; 
531-             } 
532-         } 
533- 
534-         public  static IntPtr  StringToBSTR ( string ?  s ) 
535-         { 
536-             if  ( s  is  null ) 
537-             { 
538-                 return  IntPtr . Zero ; 
539-             } 
540- 
541-             IntPtr  bstr  =  Interop . OleAut32 . SysAllocStringLen ( s ,  s . Length ) ; 
542-             if  ( bstr  ==  IntPtr . Zero ) 
543-             { 
544-                 throw  new  OutOfMemoryException ( ) ; 
545-             } 
546- 
547-             return  bstr ; 
548-         } 
549- 
550-         public  static string  PtrToStringBSTR ( IntPtr  ptr ) 
551-         { 
552-             if  ( ptr  ==  IntPtr . Zero ) 
553-             { 
554-                 throw  new  ArgumentNullException ( nameof ( ptr ) ) ; 
555-             } 
556- 
557-             return  PtrToStringUni ( ptr ,  ( int ) ( SysStringByteLen ( ptr )  /  sizeof ( char ) ) ) ; 
558-         } 
559- 
560- #if FEATURE_COMINTEROP 
561438        /// <summary> 
562439        /// Release the COM component and if the reference hits 0 zombie this object. 
563440        /// Further usage of this Object might throw an exception 
0 commit comments