internal void GetDataSource(OleDbConnectionString constr, ref DataSourceWrapper datasrcWrapper) { OleDbHResult result; UnsafeNativeMethods.IDataInitializeGetDataSource dangerousIDataInitializeGetDataSource = this.DangerousIDataInitializeGetDataSource; bool success = false; RuntimeHelpers.PrepareConstrainedRegions(); try { base.DangerousAddRef(ref success); string actualConnectionString = constr.ActualConnectionString; result = dangerousIDataInitializeGetDataSource(base.handle, IntPtr.Zero, 0x17, actualConnectionString, ref ODB.IID_IDBInitialize, ref datasrcWrapper); } finally { if (success) { base.DangerousRelease(); } } if (result < OleDbHResult.S_OK) { if (OleDbHResult.REGDB_E_CLASSNOTREG == result) { throw ODB.ProviderUnavailable(constr.Provider, null); } throw OleDbConnection.ProcessResults(result, null, null); } if (datasrcWrapper.IsInvalid) { SafeNativeMethods.Wrapper.ClearErrorInfo(); throw ODB.ProviderUnavailable(constr.Provider, null); } }
// DataLinks (the unknown parameter) is created via Activator.CreateInstance outside of the SafeHandle internal OleDbServicesWrapper(object unknown) : base() { if (null != unknown) { RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { // store the QI result for IID_IDataInitialize base.handle = Marshal.GetComInterfaceForObject(unknown, typeof(UnsafeNativeMethods.IDataInitialize)); // } // native COM rules are the QI result is the 'this' pointer // the pointer stored at that location is the vtable // since IDataInitialize is a public,shipped COM interface, its layout will not change (ever) IntPtr vtable = Marshal.ReadIntPtr(base.handle, 0); IntPtr method = Marshal.ReadIntPtr(vtable, 3 * IntPtr.Size); // GetDataSource is the 4'th vtable entry DangerousIDataInitializeGetDataSource = (UnsafeNativeMethods.IDataInitializeGetDataSource)Marshal.GetDelegateForFunctionPointer(method, typeof(UnsafeNativeMethods.IDataInitializeGetDataSource)); } }
internal OleDbServicesWrapper(object unknown) { if (unknown != null) { RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { base.handle = Marshal.GetComInterfaceForObject(unknown, typeof(UnsafeNativeMethods.IDataInitialize)); } IntPtr ptr = Marshal.ReadIntPtr(Marshal.ReadIntPtr(base.handle, 0), 3 * IntPtr.Size); this.DangerousIDataInitializeGetDataSource = (UnsafeNativeMethods.IDataInitializeGetDataSource) Marshal.GetDelegateForFunctionPointer(ptr, typeof(UnsafeNativeMethods.IDataInitializeGetDataSource)); } }
internal OleDbServicesWrapper(object unknown) { if (unknown != null) { RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { base.handle = Marshal.GetComInterfaceForObject(unknown, typeof(UnsafeNativeMethods.IDataInitialize)); } IntPtr ptr = Marshal.ReadIntPtr(Marshal.ReadIntPtr(base.handle, 0), 3 * IntPtr.Size); this.DangerousIDataInitializeGetDataSource = (UnsafeNativeMethods.IDataInitializeGetDataSource)Marshal.GetDelegateForFunctionPointer(ptr, typeof(UnsafeNativeMethods.IDataInitializeGetDataSource)); } }
// DataLinks (the unknown parameter) is created via Activator.CreateInstance outside of the SafeHandle internal OleDbServicesWrapper(object unknown) : base() { if (null != unknown) { RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { // store the QI result for IID_IDataInitialize base.handle = Marshal.GetComInterfaceForObject(unknown, typeof(UnsafeNativeMethods.IDataInitialize)); // } // native COM rules are the QI result is the 'this' pointer // the pointer stored at that location is the vtable // since IDataInitialize is a public,shipped COM interface, its layout will not change (ever) IntPtr vtable = Marshal.ReadIntPtr(base.handle, 0); IntPtr method = Marshal.ReadIntPtr(vtable, 3 * IntPtr.Size); // GetDataSource is the 4'th vtable entry DangerousIDataInitializeGetDataSource = (UnsafeNativeMethods.IDataInitializeGetDataSource)Marshal.GetDelegateForFunctionPointer(method, typeof(UnsafeNativeMethods.IDataInitializeGetDataSource)); } }
internal void GetDataSource(OleDbConnectionString constr, ref DataSourceWrapper datasrcWrapper) { OleDbHResult hr; UnsafeNativeMethods.IDataInitializeGetDataSource GetDataSource = DangerousIDataInitializeGetDataSource !; bool mustRelease = false; RuntimeHelpers.PrepareConstrainedRegions(); try { DangerousAddRef(ref mustRelease); // this is the string that DataLinks / OLE DB Services will use to create the provider string connectionString = constr.ActualConnectionString !; // base.handle is the 'this' pointer for making the COM call to GetDataSource // the datasrcWrapper will store the IID_IDBInitialize pointer // call IDataInitiailze::GetDataSource via the delegate hr = GetDataSource(base.handle, IntPtr.Zero, ODB.CLSCTX_ALL, connectionString, ref ODB.IID_IDBInitialize, ref datasrcWrapper); } finally { if (mustRelease) { DangerousRelease(); } } if (hr < 0) { // ignore infomsg if (OleDbHResult.REGDB_E_CLASSNOTREG == hr) { throw ODB.ProviderUnavailable(constr.Provider, null); } Exception?e = OleDbConnection.ProcessResults(hr, null, null); Debug.Assert(null != e, "CreateProviderError"); throw e; } else if (datasrcWrapper.IsInvalid) { SafeNativeMethods.Wrapper.ClearErrorInfo(); throw ODB.ProviderUnavailable(constr.Provider, null); } Debug.Assert(!datasrcWrapper.IsInvalid, "bad DataSource"); }