-
Notifications
You must be signed in to change notification settings - Fork 5.2k
First round of converting System.Data.OleDb to COMWrappers #54822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
b91ee8d
First round of converting System.Data.OleDb to COMWrappers
kant2002 68ba34e
Update src/libraries/System.Data.OleDb/src/OleDbComWrappers.cs
kant2002 2e0441c
Update src/libraries/System.Data.OleDb/src/OleDbComWrappers.cs
kant2002 2a753ac
Apply PR recommendations
kant2002 5b7c9dc
Make closer to original
kant2002 749fee8
One more change
kant2002 505e6f2
Apply PR feedback
kant2002 51b3456
Merge remote-tracking branch 'upstream/main' into kant/remove-il2050-…
kant2002 db65b0b
Update src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj
kant2002 7e9e956
Update src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj
kant2002 2cf1788
Fix compilation errors
kant2002 b928f03
Fix errors
kant2002 7401706
Consolidate code
kant2002 5750c8e
Fix compilation warnings
kant2002 c301fb6
Fix compilation error
kant2002 5d11dea
Fix compilation error
kant2002 a1189fd
Address PR feedback
kant2002 0e12c02
Update PR feedback
kant2002 0364575
Address PR feedback
kant2002 a2bbb45
Direct cast
kant2002 26859c5
Ask wrapper to implement IDisposable
kant2002 2c6d072
Merge branch 'main' into kant/remove-il2050-oledb
kant2002 0e1177f
Update src/libraries/System.Data.OleDb/src/OleDbConnection.COMWrapper…
kant2002 9f3a972
Update src/libraries/System.Data.OleDb/src/OleDbComWrappers.cs
kant2002 f41457f
Update src/libraries/System.Data.OleDb/src/OleDbComWrappers.cs
kant2002 dd9e48a
Update src/libraries/System.Data.OleDb/src/DbPropSet.COMWrappers.cs
kant2002 adf11e5
Restore changes in OnInfoMessage
kant2002 27a857b
Consolidate different part of code
kant2002 eca9732
Remove junk (probably from merge)
kant2002 76b3032
Found that last commit was a mess
kant2002 75567c2
Remove no longer needed annotations
kant2002 3c66ce7
Apply suggestions from code review
kant2002 af6d01e
Update src/libraries/System.Data.OleDb/src/OleDbComWrappers.cs
kant2002 ed5e796
Free BSTR
kant2002 c897950
Remove reference to no longer used files in this PR
kant2002 a331a8e
Add data
kant2002 e6efd5c
Fix compilation errors
kant2002 93b8fd3
Last blow to compiler
kant2002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/libraries/System.Data.OleDb/src/OleDbComWrappers.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections; | ||
| using System.Diagnostics; | ||
| using System.Data.Common; | ||
| using System.IO; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace System.Data.OleDb | ||
| { | ||
| /// <summary> | ||
| /// The ComWrappers implementation for System.Data.OleDb's COM interop usages. | ||
| /// | ||
| /// Supports IErrorInfo COM interface. | ||
| /// </summary> | ||
| internal unsafe sealed class OleDbComWrappers : ComWrappers | ||
| { | ||
| private const int S_OK = (int)OleDbHResult.S_OK; | ||
| private static readonly Guid IID_IErrorInfo = new Guid(0x1CF2B120, 0x547D, 0x101B, 0x8E, 0x65, 0x08, 0x00, 0x2B, 0x2B, 0xD1, 0x19); | ||
|
|
||
| internal static OleDbComWrappers Instance { get; } = new OleDbComWrappers(); | ||
|
|
||
| private OleDbComWrappers() { } | ||
|
|
||
| protected override unsafe ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| protected override object CreateObject(IntPtr externalComObject, CreateObjectFlags flags) | ||
| { | ||
| Debug.Assert(flags == CreateObjectFlags.UniqueInstance); | ||
|
|
||
| Guid errorInfoIID = IID_IErrorInfo; | ||
| int hr = Marshal.QueryInterface(externalComObject, ref errorInfoIID, out IntPtr comObject); | ||
| if (hr == S_OK) | ||
| { | ||
| return new ErrorInfoWrapper(comObject); | ||
| } | ||
|
|
||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| protected override void ReleaseObjects(IEnumerable objects) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| // Doc and type layout: https://docs.microsoft.com/windows/win32/api/oaidl/nn-oaidl-ierrorinfo | ||
| private class ErrorInfoWrapper : UnsafeNativeMethods.IErrorInfo, IDisposable | ||
| { | ||
| private readonly IntPtr _wrappedInstance; | ||
|
|
||
| public ErrorInfoWrapper(IntPtr wrappedInstance) | ||
| { | ||
| _wrappedInstance = wrappedInstance; | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| Marshal.Release(_wrappedInstance); | ||
| } | ||
|
|
||
| [Obsolete("not used", true)] | ||
| void UnsafeNativeMethods.IErrorInfo.GetGUID(/*deleted parameter signature*/) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| public unsafe System.Data.OleDb.OleDbHResult GetSource(out string? source) | ||
| { | ||
| IntPtr pSource = IntPtr.Zero; | ||
| int errorCode = ((delegate* unmanaged<IntPtr, IntPtr*, int>)(*(*(void***)_wrappedInstance + 4 /* IErrorInfo.GetSource slot */))) | ||
| (_wrappedInstance, &pSource); | ||
| if (pSource == IntPtr.Zero || errorCode < 0) | ||
| { | ||
| source = null; | ||
| } | ||
| else | ||
| { | ||
| source = Marshal.PtrToStringBSTR(pSource); | ||
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if (pSource != IntPtr.Zero) | ||
| { | ||
| Marshal.FreeBSTR(pSource); | ||
| } | ||
|
|
||
| return (System.Data.OleDb.OleDbHResult)errorCode; | ||
| } | ||
|
|
||
| public unsafe System.Data.OleDb.OleDbHResult GetDescription(out string? description) | ||
| { | ||
| IntPtr pDescription = IntPtr.Zero; | ||
| int errorCode = ((delegate* unmanaged<IntPtr, IntPtr*, int>)(*(*(void***)_wrappedInstance + 5 /* IErrorInfo.GetDescription slot */))) | ||
| (_wrappedInstance, &pDescription); | ||
| if (pDescription == IntPtr.Zero || errorCode < 0) | ||
| { | ||
| description = null; | ||
| } | ||
| else | ||
| { | ||
| description = Marshal.PtrToStringBSTR(pDescription); | ||
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if (pDescription != IntPtr.Zero) | ||
| { | ||
| Marshal.FreeBSTR(pDescription); | ||
| } | ||
|
|
||
| return (System.Data.OleDb.OleDbHResult)errorCode; | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,13 +70,8 @@ internal static OleDbException CreateException(UnsafeNativeMethods.IErrorInfo er | |
| string? message = null; | ||
| string? source = null; | ||
| OleDbHResult hr = 0; | ||
|
|
||
| if (null != errorInfo) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't we need a null check here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There discussion about that #54822 (comment) |
||
| { | ||
| hr = errorInfo.GetDescription(out message); | ||
|
|
||
| hr = errorInfo.GetSource(out source); | ||
| } | ||
| hr = errorInfo.GetDescription(out message); | ||
| hr = errorInfo.GetSource(out source); | ||
|
|
||
| int count = errors.Count; | ||
| if (0 < errors.Count) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.COMWrappers.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Data.OleDb; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace System.Data.Common | ||
| { | ||
| internal static partial class UnsafeNativeMethods | ||
| { | ||
| // | ||
| // Oleaut32 | ||
| // | ||
|
|
||
| [DllImport(Interop.Libraries.OleAut32)] | ||
| internal static unsafe extern OleDbHResult GetErrorInfo( | ||
| int dwReserved, | ||
| System.IntPtr* ppIErrorInfo); | ||
|
|
||
| internal static unsafe OleDbHResult GetErrorInfo( | ||
| int dwReserved, | ||
| out UnsafeNativeMethods.IErrorInfo? ppIErrorInfo) | ||
| { | ||
| ppIErrorInfo = null; | ||
| IntPtr pErrorInfo; | ||
| var hr = GetErrorInfo(dwReserved, &pErrorInfo); | ||
| if (hr == OleDbHResult.S_OK) | ||
| { | ||
| ppIErrorInfo = (UnsafeNativeMethods.IErrorInfo)OleDbComWrappers.Instance | ||
| .GetOrCreateObjectForComInstance(pErrorInfo, CreateObjectFlags.UniqueInstance); | ||
| } | ||
|
|
||
| return hr; | ||
| } | ||
|
|
||
| internal static void ReleaseErrorInfoObject(UnsafeNativeMethods.IErrorInfo errorInfo) | ||
| { | ||
| ((IDisposable)errorInfo).Dispose(); | ||
| } | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.NoCOMWrappers.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace System.Data.Common | ||
| { | ||
| internal static partial class UnsafeNativeMethods | ||
| { | ||
| // | ||
| // Oleaut32 | ||
| // | ||
|
|
||
| [DllImport(Interop.Libraries.OleAut32, CharSet = CharSet.Unicode, PreserveSig = true)] | ||
| internal static extern System.Data.OleDb.OleDbHResult GetErrorInfo( | ||
| int dwReserved, | ||
| [MarshalAs(UnmanagedType.Interface)] out UnsafeNativeMethods.IErrorInfo? ppIErrorInfo); | ||
|
|
||
| internal static void ReleaseErrorInfoObject(UnsafeNativeMethods.IErrorInfo errorInfo) | ||
| { | ||
| Marshal.ReleaseComObject(errorInfo); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.