File tree 2 files changed +15
-11
lines changed
Common/src/Interop/Windows/Ole32
System.Private.CoreLib/src/System
2 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,6 @@ internal static partial class Interop
9
9
internal static partial class Ole32
10
10
{
11
11
[ LibraryImport ( Libraries . Ole32 ) ]
12
- internal static partial int CoCreateGuid ( out Guid guid ) ;
12
+ internal static unsafe partial int CoCreateGuid ( Guid * guid ) ;
13
13
}
14
14
}
Original file line number Diff line number Diff line change @@ -5,22 +5,26 @@ namespace System
5
5
{
6
6
public partial struct Guid
7
7
{
8
- public static Guid NewGuid ( )
8
+ public static unsafe Guid NewGuid ( )
9
9
{
10
- // CoCreateGuid should never return Guid.Empty, since it attempts to maintain some
11
- // uniqueness guarantees.
10
+ // CoCreateGuid should never return Guid.Empty, since it attempts to maintain some uniqueness guarantees.
12
11
13
- int hr = Interop . Ole32 . CoCreateGuid ( out Guid g ) ;
14
- // We don't expect that this will ever throw an error, none are even documented, and so we don't want to pull
15
- // in the HR to ComException mappings into the core library just for this so we will try a generic exception if
16
- // we ever hit this condition.
12
+ Guid g ;
13
+ int hr = Interop . Ole32 . CoCreateGuid ( & g ) ;
17
14
if ( hr != 0 )
18
15
{
19
- Exception ex = new Exception ( ) ;
20
- ex . HResult = hr ;
21
- throw ex ;
16
+ ThrowForHr ( hr ) ;
22
17
}
18
+
23
19
return g ;
24
20
}
21
+
22
+ private static void ThrowForHr ( int hr )
23
+ {
24
+ // We don't expect that this will ever throw an error, none are even documented, and so we don't want to pull
25
+ // in the HR to ComException mappings into the core library just for this so we will try a generic exception if
26
+ // we ever hit this condition.
27
+ throw new Exception ( ) { HResult = hr } ;
28
+ }
25
29
}
26
30
}
You can’t perform that action at this time.
0 commit comments