Vendor things

This commit is contained in:
John Doty 2024-03-08 11:03:01 -08:00
parent 5deceec006
commit 977e3c17e5
19434 changed files with 10682014 additions and 0 deletions

View file

@ -0,0 +1 @@
{"files":{"Cargo.toml":"0ee80d815a0682d67a988d9b39d454f3d0b5164fb1b26784870f406a98820152","LICENSE-APACHE":"cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30","LICENSE-MIT":"a3948ea576691eff1ab7362faca8d4c066fa3f8308c4a15bb53487c550919c51","README.md":"68ef8df7e574f25df59e93509da64f7dabd89d00467a25b7a47815c8d4adbc97","appveyor.yml":"269e1362528746931551ba4484f85e25857189f248d9a20d2a7a65ba53c3f12b","build.rs":"08988a3099ed8d965202c2fb4002af5c37da30d3b305a9d492ade244eaa6aef0","src/comptr.rs":"6c2e16e687039a0cd3ca36bf5db9d8b5198aaaff807adbf614e13f32f00efaf5","src/lib.rs":"4e152c534dc6a6e72605c116f23cf111fecc8c7b676f3b4a0c1824faa2f2f3fb","src/macros.rs":"f459c756a55c92399a3483d08b8289a280d462b7343a7050a2bb5dd89144088e","src/unknown.rs":"a777d593bf1fc6e08bbd06ccde25241701d3f22741b54e8d3ed68887a7a18ec9","tests/test_as_ptr.rs":"eb20b0d8254441e96d146433c4836636f245492513b6409a6187529127604d99"},"package":"bf43edc576402991846b093a7ca18a3477e0ef9c588cde84964b5d3e43016642"}

24
third-party/vendor/com-rs/Cargo.toml vendored Normal file
View file

@ -0,0 +1,24 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
name = "com-rs"
version = "0.2.1"
authors = ["Lee Jeffery <lee@leejeffery.co.uk>"]
build = "build.rs"
description = "Deprecated. Use the `com` crate instead."
documentation = "http://eljay.github.io/com-rs/com_rs/index.html"
readme = "README.md"
license = "MIT/Apache-2.0"
repository = "https://github.com/Eljay/com-rs"
[badges.maintenance]
status = "deprecated"

202
third-party/vendor/com-rs/LICENSE-APACHE vendored Normal file
View file

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

21
third-party/vendor/com-rs/LICENSE-MIT vendored Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Lee Jeffery
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

1
third-party/vendor/com-rs/README.md vendored Normal file
View file

@ -0,0 +1 @@
Deprecated. Use the [com](https://github.com/microsoft/com-rs) crate instead.

37
third-party/vendor/com-rs/appveyor.yml vendored Normal file
View file

@ -0,0 +1,37 @@
platform:
- x86
- x64
branches:
except:
- gh-pages
environment:
matrix:
# Rust 1.3 required for $ty followed by ; in com_interface! macro
# - RUST_VERSION: 1.3.0
- RUST_VERSION: beta
RUST_TOOLCHAIN: gnu
- RUST_VERSION: beta
RUST_TOOLCHAIN: msvc
- RUST_VERSION: nightly
RUST_TOOLCHAIN: gnu
- RUST_VERSION: nightly
RUST_TOOLCHAIN: msvc
install:
- ps: |
if ($env:PLATFORM -eq "x86") {
Start-FileDownload "https://static.rust-lang.org/dist/rust-$env:RUST_VERSION-i686-pc-windows-$env:RUST_TOOLCHAIN.exe" -FileName rust.exe
} else {
Start-FileDownload "https://static.rust-lang.org/dist/rust-$env:RUST_VERSION-x86_64-pc-windows-$env:RUST_TOOLCHAIN.exe" -FileName rust.exe
}
- rust.exe /VERYSILENT /NORESTART /DIR="C:\Program Files\Rust"
- SET PATH=%PATH%;C:\Program Files\Rust\bin
- rustc -V
- cargo -V
build: false
test_script:
- cargo test -v

3
third-party/vendor/com-rs/build.rs vendored Normal file
View file

@ -0,0 +1,3 @@
fn main() {
println!("cargo:rustc-link-lib=dylib=uuid");
}

187
third-party/vendor/com-rs/src/comptr.rs vendored Normal file
View file

@ -0,0 +1,187 @@
// Copyright (c) 2016 com-rs developers
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. All files in the project carrying such notice may not be copied,
// modified, or distributed except according to those terms.
use std::mem;
use std::ops::Deref;
use std::os::raw::c_void;
use std::ptr;
use {IID, IUnknown};
/**
Wrapper type for COM interface pointers.
# Usage
## Passing COM pointers to/from FFI methods
`ComPtr<T>` has the following methods for accessing the underlying pointer:
* `as_ptr` returns the raw pointer `*const T`
* `as_mut_ptr` returns a mutable reference to the raw pointer `&mut *mut T`
The `AsComPtr` trait defines which pointer types can be returned by these
methods. These methods should be used carefully to ensure the returned pointers
do not outlive the `ComPtr` object.
```
extern crate com_rs;
use com_rs::*;
fn create_iunknown_object(p: *mut *mut IUnknown) { }
fn use_iunknown_object(p: *const IUnknown) { }
fn main() {
let mut unknown: ComPtr<IUnknown> = ComPtr::new();
create_iunknown_object(unknown.as_mut_ptr());
use_iunknown_object(unknown.as_ptr());
}
```
## Reference Counting
`ComPtr` implements the `Clone` and `Drop` traits, which call the
`IUnknown::add_ref` and `IUnknown::release` methods respectively to handle the
internal reference counting.
## Accessing COM interface methods
`ComPtr<T>` coerces into `T` using the `Deref` trait, allowing interface methods
to be called directly. However, dereferencing a `ComPtr` containing a null
pointer in this way results in a panic. All method calls should be guarded with
`is_null` checks to prevent this.
```
# use com_rs::*;
# fn create_iunknown_object(p: *mut *mut IUnknown) { }
let mut ptr: ComPtr<IUnknown> = ComPtr::new();
create_iunknown_object(ptr.as_mut_ptr());
if !ptr.is_null() {
// This is just for demonstration, don't call these directly
unsafe { ptr.add_ref() };
unsafe { ptr.release() };
}
```
## Conversion using `From`
`ComPtr<T>` also implements the `From` trait for conversion between different
COM interfaces. This is a wrapper around the `IUnknown::query_interface` method
which automatically uses the IID of the target type.
```
# use com_rs::*;
# fn create_iunknown_object(p: *mut *mut IUnknown) { }
# type IFoobar = IUnknown;
let mut unknown: ComPtr<IUnknown> = ComPtr::new();
create_iunknown_object(unknown.as_mut_ptr());
let other: ComPtr<IFoobar> = ComPtr::from(&unknown);
```
This will try to query the `IFoobar` interface on the unknown object. If the
interface is unavailable (or `unknown` is null), the returned object will be
null.
*/
#[derive(Debug)]
pub struct ComPtr<T: ComInterface> {
ptr: *mut T
}
/// Helper trait for `ComPtr`. Implemented automatically by the
/// `com_interface!` macro.
pub unsafe trait ComInterface: AsComPtr<IUnknown> {
#[doc(hidden)]
type Vtable;
/// Get the IID associated with a COM interface struct.
fn iid() -> IID;
}
/// Helper trait for `ComPtr`. Defines which types of raw pointer can be
/// returned by `as_ptr`/`as_mut_ptr`.
pub unsafe trait AsComPtr<T> { }
impl<T: ComInterface> ComPtr<T> {
/// Constructs a new `ComPtr<T>`.
pub fn new() -> ComPtr<T> {
ComPtr { ptr: ptr::null_mut() }
}
/// Returns the raw pointer as type `U`. Depends on the `AsComPtr` trait.
pub fn as_ptr<U>(&self) -> *const U where T: AsComPtr<U> {
self.ptr as *const U
}
/// Returns a mutable reference to the raw pointer.
/// Depends on the 'AsComPtr' trait.
pub fn as_mut_ptr<U>(&mut self) -> &mut *mut U where T: AsComPtr<U> {
unsafe { mem::transmute(&mut self.ptr) }
}
/// Returns true if the contained interface pointer is null. This should
/// always be checked before calling any methods on the contained interface.
pub fn is_null(&self) -> bool {
self.ptr.is_null()
}
/// Return the IID associated with type `T`.
pub fn iid(&self) -> IID {
T::iid()
}
}
/// All types can be cast into `c_void` pointers.
unsafe impl<T: ComInterface> AsComPtr<c_void> for T { }
impl<'a, T, U> From<&'a ComPtr<T>> for ComPtr<U>
where T: ComInterface, U: ComInterface + AsComPtr<c_void> {
/// Create a `ComPtr` of a different interface type `U`. Calls
/// `IUnknown::query_interface` and returns a new `ComPtr<U>` object.
/// If the requested interface is unavailable, the returned `ComPtr<U>`
/// will contain a null pointer.
fn from(other: &'a ComPtr<T>) -> ComPtr<U> {
let mut new: ComPtr<U> = ComPtr::new();
if !other.is_null() {
unsafe {
(*other.as_ptr()).query_interface(&U::iid(), new.as_mut_ptr());
}
}
new
}
}
impl<T: ComInterface> Deref for ComPtr<T> {
type Target = T;
/// Dereference into contained interface `T` to call methods directly.
///
/// # Panics
/// If the contained pointer is null, any dereference will result in a
/// panic. Use the [`is_null`](#method.is_null) method before dereferencing.
fn deref<'a>(&'a self) -> &'a T {
assert!(!self.is_null(), "dereferenced null ComPtr");
unsafe { &*self.ptr }
}
}
impl<T: ComInterface> Clone for ComPtr<T> {
/// Clones the `ComPtr<T>`. Increments the internal reference counter by
/// calling `IUnknown::add_ref` on the contained COM object
/// (if the pointer is non-null).
fn clone(&self) -> ComPtr<T> {
if !self.is_null() {
unsafe { (*self.as_ptr()).add_ref() };
}
ComPtr { ptr: self.ptr }
}
}
impl<T: ComInterface> Drop for ComPtr<T> {
/// Drops the `ComPtr<T>`. Decrements the internal reference counter by
/// calling `IUnknown::release` on the contained COM object
/// (if the pointer is non-null).
fn drop(&mut self) {
if !self.is_null() {
unsafe { (*self.as_ptr()).release() };
}
}
}

76
third-party/vendor/com-rs/src/lib.rs vendored Normal file
View file

@ -0,0 +1,76 @@
// Copyright (c) 2016 com-rs developers
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. All files in the project carrying such notice may not be copied,
// modified, or distributed except according to those terms.
/*!
# com-rs 0.1.4
Rust bindings for the Win32 [Component Object Model]
(https://msdn.microsoft.com/en-us/library/ms680573.aspx).
# Overview
This crate is composed of three main components:
* The [`com_interface!`] (macro.com_interface!.html) macro for
defining new interface types.
* The [`ComPtr`](struct.ComPtr.html) type for making use of them.
* Definition of [`IUnknown`](struct.IUnknown.html), the base COM interface.
*/
// TODO:
// * Implement the rest of COM, this is just a tiny subset necessary to consume
// IUnknown interfaces.
// * Tests for IUnknown/ComPtr, hard to test with no way of acquiring
// IUnknown objects directly.
#![deny(dead_code)]
#![deny(missing_debug_implementations)]
#![deny(missing_docs)]
use std::fmt;
pub use comptr::{AsComPtr, ComInterface, ComPtr};
pub use unknown::IUnknown;
/// Interface identifier.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct IID {
/// First component, 32-bit value.
pub data1: u32,
/// Second component, 16-bit value.
pub data2: u16,
/// Third component, 16-bit value.
pub data3: u16,
/// Fourth component, array of 8-bit values.
pub data4: [u8; 8],
}
/// Print IID in Windows registry format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}.
impl fmt::Display for IID {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{{{:08X}-{:04X}-{:04X}-{:02X}{:02X}-\
{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}}}",
self.data1, self.data2, self.data3,
self.data4[0], self.data4[1], self.data4[2], self.data4[3],
self.data4[4], self.data4[5], self.data4[6], self.data4[7])
}
}
#[test]
fn iid_display() {
assert_eq!(IUnknown::iid().to_string(),
"{00000000-0000-0000-C000-000000000046}");
}
/// Result type.
pub type HResult = i32;
#[macro_use]
mod macros;
mod comptr;
mod unknown;

199
third-party/vendor/com-rs/src/macros.rs vendored Normal file
View file

@ -0,0 +1,199 @@
// Copyright (c) 2016 com-rs developers
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. All files in the project carrying such notice may not be copied,
// modified, or distributed except according to those terms.
/**
Macro for generating COM interface definitions.
# Usage
```
#[macro_use]
extern crate com_rs;
use com_rs::IUnknown;
iid!(IID_IFOO =
0x12345678, 0x90AB, 0xCDEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF);
com_interface! {
interface IFoo: IUnknown {
iid: IID_IFOO,
vtable: IFooVtbl,
fn foo() -> bool;
}
}
# fn main() { }
```
This example defines an interface called `IFoo`. In this case, the base type is
IUnknown, the root COM type. The IID for the interface must also be defined,
along with the name of the vtable type, `IFooVtbl`. This isn't publicly exposed,
but there is currently no way to generate an ident within a macro so the callee
must define one instead.
The trait `Foo` defines the methods available for the interface, in this case
a single method named `foo`. Note that any methods that return no value
(e.g. the `void` type in C/C++) should return the unit type `()`.
## Inheritance
To define interfaces with a deeper hierarchy, add additional parent identifiers
to the type definitions. e.g:
```
# #[macro_use]
# extern crate com_rs;
# use com_rs::IUnknown;
# iid!(IID_IFOO = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
# com_interface! {
# interface IFoo: IUnknown {
# iid: IID_IFOO,
# vtable: IFooVtbl,
# fn foo() -> bool;
# }
# }
iid!(IID_IBAR =
0x12345678, 0x90AB, 0xCDEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF);
com_interface! {
interface IBar: IFoo, IUnknown {
iid: IID_IBAR,
vtable: IBarVtbl,
fn bar(baz: i32) -> ();
}
}
# fn main() { }
```
This example defines an interface called `IBar` which extends `IFoo` from the
previous example. Note that it is necessary to specify the parent types
for both the interface and trait declarations.
The interface hierarchy automates pointer conversion using the `AsComPtr` trait,
and the trait hierarchy automatically implements the parent methods for the
child interface.
*/
#[macro_export]
macro_rules! com_interface {
(
$(#[$iface_attr:meta])*
interface $iface:ident: $base_iface:ty {
iid: $iid:ident,
vtable: $vtable:ident,
$(
$(#[$fn_attr:meta])*
fn $func:ident($($i:ident: $t:ty),*) -> $rt:ty;
)*
}
) => (
#[allow(missing_debug_implementations)]
#[doc(hidden)]
#[repr(C)]
pub struct $vtable {
base: <$base_iface as $crate::ComInterface>::Vtable,
$($func: extern "stdcall" fn(*const $iface, $($t),*) -> $rt),*
}
$(#[$iface_attr])*
#[derive(Debug)]
#[repr(C)]
pub struct $iface {
vtable: *const $vtable
}
impl $iface {
$($(#[$fn_attr])*
pub unsafe fn $func(&self, $($i: $t),*) -> $rt {
((*self.vtable).$func)(self $(,$i)*)
})*
}
impl ::std::ops::Deref for $iface {
type Target = $base_iface;
fn deref(&self) -> &$base_iface {
unsafe { ::std::mem::transmute(self) }
}
}
unsafe impl $crate::AsComPtr<$iface> for $iface {}
unsafe impl $crate::AsComPtr<$base_iface> for $iface {}
unsafe impl $crate::ComInterface for $iface {
#[doc(hidden)]
type Vtable = $vtable;
#[allow(unused_unsafe)]
fn iid() -> $crate::IID { unsafe { $iid } }
}
);
(
$(#[$iface_attr:meta])*
interface $iface:ident: $base_iface:ty, $($extra_base:ty),+ {
iid: $iid:ident,
vtable: $vtable:ident,
$(
$(#[$fn_attr:meta])*
fn $func:ident($($i:ident: $t:ty),*) -> $rt:ty;
)*
}
) => (
com_interface! {
$(#[$iface_attr])*
interface $iface: $base_iface {
iid: $iid,
vtable: $vtable,
$($(#[$fn_attr])* fn $func($($i: $t),*) -> $rt;)*
}
}
$(unsafe impl $crate::AsComPtr<$extra_base> for $iface {})*
)
}
/**
Helper macro for defining [`IID`](struct.IID.html) constants.
# Usage
```
# #[macro_use]
# extern crate com_rs;
iid!(IID_IFOO = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
# fn main() {}
```
IIDs are private by default as they are only supposed to be exposed by the
`ComPtr::iid` method. If you want to make them public, just add the `pub`
keyword before the identifier.
```
# #[macro_use]
# extern crate com_rs;
iid!(pub IID_IBAR = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
# fn main() {}
```
*/
#[macro_export]
macro_rules! iid {
($(#[$iid_attr:meta])*
$name:ident = $d1:expr, $d2:expr, $d3:expr, $($d4:expr),*) => (
$(#[$iid_attr])*
const $name: $crate::IID = $crate::IID {
data1: $d1,
data2: $d2,
data3: $d3,
data4: [$($d4),*],
};
);
($(#[$iid_attr:meta])*
pub $name:ident = $d1:expr, $d2:expr, $d3:expr, $($d4:expr),*) => (
$(#[$iid_attr])*
pub const $name: $crate::IID = $crate::IID {
data1: $d1,
data2: $d2,
data3: $d3,
data4: [$($d4),*],
};
);
}

View file

@ -0,0 +1,65 @@
// Copyright (c) 2016 com-rs developers
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. All files in the project carrying such notice may not be copied,
// modified, or distributed except according to those terms.
use std::os::raw::c_void;
use super::{AsComPtr, HResult, IID};
/// Base interface for all COM types.
///
/// None of the methods on this struct should be called directly,
/// use [`ComPtr`](struct.ComPtr.html) instead.
#[derive(Debug)]
#[repr(C)]
pub struct IUnknown {
vtable: *const IUnknownVtbl
}
#[allow(missing_debug_implementations)]
#[repr(C)]
#[doc(hidden)]
pub struct IUnknownVtbl {
query_interface: extern "stdcall" fn(
*const IUnknown, &IID, *mut *mut c_void) -> HResult,
add_ref: extern "stdcall" fn(*const IUnknown) -> u32,
release: extern "stdcall" fn(*const IUnknown) -> u32
}
extern {
static IID_IUnknown: IID;
}
impl IUnknown {
/// Retrieves pointers to the supported interfaces on an object.
/// Use [`ComPtr::from`](struct.ComPtr.html#method.from) instead.
pub unsafe fn query_interface(&self, iid: &IID, object: *mut *mut c_void)
-> HResult {
((*self.vtable).query_interface)(self, iid, object)
}
/// Increments the reference count for an interface on an object.
/// Should never need to call this directly.
pub unsafe fn add_ref(&self) -> u32 {
((*self.vtable).add_ref)(self)
}
/// Decrements the reference count for an interface on an object.
/// Should never need to call this directly.
pub unsafe fn release(&self) -> u32 {
((*self.vtable).release)(self)
}
}
unsafe impl AsComPtr<IUnknown> for IUnknown { }
unsafe impl ::ComInterface for IUnknown {
#[doc(hidden)]
type Vtable = IUnknownVtbl;
fn iid() -> ::IID { unsafe { IID_IUnknown } }
}

View file

@ -0,0 +1,61 @@
#[macro_use]
extern crate com_rs;
use com_rs::{ComPtr, IUnknown};
iid!(IID_IFOO = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
com_interface! {
/// IFoo struct
interface IFoo: IUnknown {
iid: IID_IFOO,
vtable: IFooVtbl,
/// foo fn
fn foo() -> ();
}
}
iid!(IID_IBAR = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
com_interface! {
/// IBar struct
interface IBar: IFoo, IUnknown {
iid: IID_IBAR,
vtable: IBarVtbl,
/// bar method
fn bar() -> ();
}
}
iid!(IID_IBAZ = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
com_interface! {
/// IBaz struct
interface IBaz: IBar, IFoo, IUnknown {
iid: IID_IBAZ,
vtable: IBazVtbl,
/// baz method
fn baz() -> ();
}
}
#[test]
fn test_as_ptr() {
use std::os::raw::c_void;
let foo = ComPtr::<IFoo>::new();
let bar = ComPtr::<IBar>::new();
let baz = ComPtr::<IBaz>::new();
let _foo_ptr1: *const c_void = foo.as_ptr();
let _foo_ptr2: *const IUnknown = foo.as_ptr();
let _foo_ptr3: *const IFoo = foo.as_ptr();
let _bar_ptr1: *const c_void = bar.as_ptr();
let _bar_ptr2: *const IUnknown = bar.as_ptr();
let _bar_ptr3: *const IFoo = bar.as_ptr();
let _bar_ptr4: *const IBar = bar.as_ptr();
let _baz_ptr1: *const c_void = baz.as_ptr();
let _baz_ptr2: *const IUnknown = baz.as_ptr();
let _baz_ptr3: *const IFoo = baz.as_ptr();
let _baz_ptr4: *const IBar = baz.as_ptr();
let _baz_ptr5: *const IBaz = baz.as_ptr();
}