pub fn expand_com_module(
    arg_tokens: TokenStreamNightly,
    com_library: bool,
) -> Result<TokenStreamNightly, model::ParseError>
{
    let mut output = vec![];
    let lib = model::ComLibrary::parse(&lib_name(), arg_tokens.into())?;

    // Create the match-statmeent patterns for each supposedly visible COM class.
    let mut match_arms = vec![];
    for struct_path in &lib.coclasses {
        // Construct the match pattern.
        let clsid_path = idents::clsid_path(struct_path);
        match_arms.push(quote_spanned!(struct_path.span() =>
            #clsid_path =>
                return Some(intercom::ClassFactory::<#struct_path>::create(riid, pout))
        ));
    }

    let try_submodule_class_factory = lib.submodules.iter().map(|submod| {
        quote!(
            if let Some(hr) = #submod::__get_module_class_factory(rclsid, riid, pout) {
                return Some(hr);
            }
        )
    });

    // Implement the __get_module_class_factory function.
    output.push(quote!(
        #[allow(dead_code)]
        #[doc(hidden)]
        pub unsafe fn __get_module_class_factory(
            rclsid : intercom::REFCLSID,
            riid : intercom::REFIID,
            pout : *mut intercom::raw::RawComPtr
        ) -> Option<intercom::raw::HRESULT>
        {
            // Create new class factory.
            // Specify a create function that is able to create all the
            // contained coclasses.
            match *rclsid {
                #( #match_arms, )*
                _ => {},
            };

            // Try each sub-module
            #( #try_submodule_class_factory )*

            None
        }
    ));

    // Figure the on_load() function to invoke in DllMain.
    let on_load = if let Some(ref on_load) = &lib.on_load {
        quote!(#on_load();)
    } else {
        quote!()
    };

    // Implement DllGetClassObject and DllMain.
    //
    // This is more or less the only symbolic entry point that the COM
    // infrastructure uses. The COM client uses this method to acquire
    // the IClassFactory interfaces that are then used to construct the
    // actual coclasses.
    if com_library {
        let dll_get_class_object = get_dll_get_class_object_function();
        output.push(dll_get_class_object);
        output.push(quote!(
            #[doc(hidden)]
            static mut __INTERCOM_DLL_INSTANCE: *mut std::os::raw::c_void = 0 as _;

            #[no_mangle]
            #[allow(non_camel_case_types)]
            #[deprecated]
            #[doc(hidden)]
            pub extern "stdcall" fn DllMain(
                dll_instance: *mut std::os::raw::c_void,
                reason: u32,
                _reserved: *mut std::os::raw::c_void,
            ) -> bool
            {
                match reason {
                    // DLL_PROCESS_ATTACH
                    1 => unsafe {
                        __INTERCOM_DLL_INSTANCE = dll_instance;
                        #on_load
                    },
                    _ => {}
                }
                true
            }
        ));
    }

    // Implement get_intercom_typelib()
    output.push(create_gather_module_types(&lib));
    if com_library {
        output.push(create_get_typelib_function(&lib));
    }

    // Implement the global DLL entry points
    if com_library {
        // DllListClassObjects returns all CLSIDs implemented in the crate.
        let list_class_objects = get_intercom_list_class_objects_function();
        output.push(list_class_objects);

        // DllListClassObjects returns all CLSIDs implemented in the crate.
        let dll_register_server = get_register_server_function(&lib);
        output.push(dll_register_server);
    }

    Ok(TokenStream::from_iter(output.into_iter()).into())
}
/// Expands the `com_library` macro.
///
/// The macro expansion results in the following items:
///
/// - `DllGetClassObject` extern function implementation.
/// - `IntercomListClassObjects` extern function implementation.
Expands the `com_library` macro.
The macro expansion results in the following items.

`DllGetClassObject` extern function implementation.
`IntercomListClassObjects` extern function implementation.
Expands the ` com_library ` macro . The macro expansion results in the following items . ` DllGetClassObject ` extern function implementation . ` IntercomListClassObjects ` extern function implementation .
pub fn expand_com_module(
    arg_tokens: TokenStreamNightly,
    com_library: bool,
) -> Result<TokenStreamNightly, model::ParseError>
{
    let mut output = vec![];
    let lib = model::ComLibrary::parse(&lib_name(), arg_tokens.into())?;
    // Create the match-statmeent patterns for each supposedly visible COM class.
    let mut match_arms = vec![];
    for struct_path in &lib.coclasses {
        // Construct the match pattern.
        let clsid_path = idents::clsid_path(struct_path);
        match_arms.push(quote_spanned!(struct_path.span() =>
            #clsid_path =>
                return Some(intercom::ClassFactory::<#struct_path>::create(riid, pout))
        ));
    }
    let try_submodule_class_factory = lib.submodules.iter().map(|submod| {
        quote!(
            if let Some(hr) = #submod::__get_module_class_factory(rclsid, riid, pout) {
                return Some(hr);
            }
        )
    });
    // Implement the __get_module_class_factory function.
    output.push(quote!(
        #[allow(dead_code)]
        #[doc(hidden)]
        pub unsafe fn __get_module_class_factory(
            rclsid : intercom::REFCLSID,
            riid : intercom::REFIID,
            pout : *mut intercom::raw::RawComPtr
        ) -> Option<intercom::raw::HRESULT>
        {
            // Create new class factory.
            // Specify a create function that is able to create all the
            // contained coclasses.
            match *rclsid {
                #( #match_arms, )*
                _ => {},
            };
            // Try each sub-module
            #( #try_submodule_class_factory )*
            None
        }
    ));
    // Figure the on_load() function to invoke in DllMain.
    let on_load = if let Some(ref on_load) = &lib.on_load {
        quote!(#on_load();)
    } else {
        quote!()
    };
    // Implement DllGetClassObject and DllMain.
    //
    // This is more or less the only symbolic entry point that the COM
    // infrastructure uses. The COM client uses this method to acquire
    // the IClassFactory interfaces that are then used to construct the
    // actual coclasses.
    if com_library {
        let dll_get_class_object = get_dll_get_class_object_function();
        output.push(dll_get_class_object);
        output.push(quote!(
            #[doc(hidden)]
            static mut __INTERCOM_DLL_INSTANCE: *mut std::os::raw::c_void = 0 as _;
            #[no_mangle]
            #[allow(non_camel_case_types)]
            #[deprecated]
            #[doc(hidden)]
            pub extern "stdcall" fn DllMain(
                dll_instance: *mut std::os::raw::c_void,
                reason: u32,
                _reserved: *mut std::os::raw::c_void,
            ) -> bool
            {
                match reason {
                    // DLL_PROCESS_ATTACH
                    1 => unsafe {
                        __INTERCOM_DLL_INSTANCE = dll_instance;
                        #on_load
                    },
                    _ => {}
                }
                true
            }
        ));
    }
    // Implement get_intercom_typelib()
    output.push(create_gather_module_types(&lib));
    if com_library {
        output.push(create_get_typelib_function(&lib));
    }
    // Implement the global DLL entry points
    if com_library {
        // DllListClassObjects returns all CLSIDs implemented in the crate.
        let list_class_objects = get_intercom_list_class_objects_function();
        output.push(list_class_objects);
        // DllListClassObjects returns all CLSIDs implemented in the crate.
        let dll_register_server = get_register_server_function(&lib);
        output.push(dll_register_server);
    }
    Ok(TokenStream::from_iter(output.into_iter()).into())
}
pub fn expand_com_module ( arg_tokens : TokenStreamNightly , com_library : bool , ) -> Result < TokenStreamNightly , model :: ParseError > { let mut output = vec ! [ ] ; let lib = model :: ComLibrary :: parse ( & lib_name ( ) , arg_tokens . into ( ) ) ? ; // Create the match-statmeent patterns for each supposedly visible COM class. let mut match_arms = vec ! [ ] ; for struct_path in & lib . coclasses { // Construct the match pattern. let clsid_path = idents :: clsid_path ( struct_path ) ; match_arms . push ( quote_spanned ! ( struct_path span ( ) clsid_path return Some ( intercom ClassFactory struct_path create ( riid pout ) ) ) ) ; } let try_submodule_class_factory = lib . submodules . iter ( ) . map ( | submod | { quote ! ( if let Some ( hr ) submod get_module_class_factory ( rclsid riid pout ) { return Some ( hr ) } ) } ) ; // Implement the __get_module_class_factory function. output . push ( quote ! ( [ allow ( dead_code ) ] [ doc ( hidden ) ] pub unsafe fn __get_module_class_factory ( rclsid intercom REFCLSID riid intercom REFIID pout mut intercom raw RawComPtr ) Option intercom raw HRESULT { // Create new class factory. // Specify a create function that is able to create all the // contained coclasses. match rclsid { ( match_arms ) { } } // Try each sub-module ( try_submodule_class_factory ) None } ) ) ; // Figure the on_load() function to invoke in DllMain. let on_load = if let Some ( ref on_load ) = & lib . on_load { quote ! ( on_load ( ) ) } else { quote ! ( ) } ; // Implement DllGetClassObject and DllMain. // // This is more or less the only symbolic entry point that the COM // infrastructure uses. The COM client uses this method to acquire // the IClassFactory interfaces that are then used to construct the // actual coclasses. if com_library { let dll_get_class_object = get_dll_get_class_object_function ( ) ; output . push ( dll_get_class_object ) ; output . push ( quote ! ( [ doc ( hidden ) ] static mut __INTERCOM_DLL_INSTANCE mut std os raw c_void 0 as [ no_mangle ] [ allow ( non_camel_case_types ) ] [ deprecated ] [ doc ( hidden ) ] pub extern " " fn DllMain ( dll_instance mut std os raw c_void reason u32 _reserved mut std os raw c_void ) bool { match reason { // DLL_PROCESS_ATTACH 1 unsafe { __INTERCOM_DLL_INSTANCE dll_instance on_load } { } } true } ) ) ; } // Implement get_intercom_typelib() output . push ( create_gather_module_types ( & lib ) ) ; if com_library { output . push ( create_get_typelib_function ( & lib ) ) ; } // Implement the global DLL entry points if com_library { // DllListClassObjects returns all CLSIDs implemented in the crate. let list_class_objects = get_intercom_list_class_objects_function ( ) ; output . push ( list_class_objects ) ; // DllListClassObjects returns all CLSIDs implemented in the crate. let dll_register_server = get_register_server_function ( & lib ) ; output . push ( dll_register_server ) ; } Ok ( TokenStream :: from_iter ( output . into_iter ( ) ) . into ( ) ) }
Expands the `com_library` macro.
Expands the ` com_library ` macro .
arg_tokens
TokenStreamNightly
com_library
bool
arg_tokens
TokenStreamNightly
com_library
bool