C # Call bits (Background Intelligent Transfer Service)

Source: Internet
Author: User
BITs (Background Intelligent Transfer Service) is a technology launched by Microsoft to implement file transmission between the client and server. Microsoft only provides com-based interfaces, rather than hosting-based interfaces. Code . If you want to use a. Net Language (such as C #), you need to manually encapsulate the COM interface or use a third-party encapsulation. BITs has multiple versions, which makes it more difficult to find a suitable one. Msdoes not have a pure TLB file or embed the TLB file into the real-time bits's dll. you cannot use tlbimp.exe to generate com packages. If a TLB file exists, you can use tlbimp.exe to generate com packages. Program Set.

I found that the packaging assembly can be generated by viewing the file windows supervisor, but there is a problem that no matter which version of The IDL file is used, only the packaging assembly of the COM interface of BITs 1.0 can be generated; in addition, if bits4_0.idl is used to generate a packaging class, an exception occurs when you create a backgroundcopymanager4_0class object and experiment on two win7 machines. The exception information is:
Retrieving the com class factory for component with clsid {BB6DF56B-CACE-11DC-9992-0019B93A3A84} failed due to the following error: 80080005.
I have not found a solution for the moment. I doubt it is a Ms bug.

If 4.0 is unavailable, only 3.0 of the Packaged assembly can be generated. The following procedure is performed on the bits3_0.idl file:Library backgroundcopymanager3_0
{
[
UUID (659cdea7 - 489e - 11d9 - A9cd - 000d000065133 ),
Helpstring ( " Background copy Manager 3.0 " )
]
Coclass backgroundcopymanager3_0
{
[ Default ] Interface Ibackgroundcopymanager;
};
Interface Ibackgroundcopyjob4;

InterfaceIbackgroundcopyjobhttpoptions;
InterfaceIbackgroundcopycallback2;
InterfaceIbackgroundcopyfile3;
InterfaceIbitspeercacheadministration;

}

The purpose of this interface is to include the interfacepacket in the interface when generating the TLB file. tlbimp.exe encapsulates these interfaces.
Command Behavior:Midl bits3_0.IDL
Tlbimp bits3_0.TLB

Generate the backgroundcopymanager3_0.dll file and add reference to the. NET project. If you want to obtain an interface of a higher version from an interface of a lower version, you need an interface of a lower version to call QueryInterface. However, the packaging of the COM interface will shield reference counting and QueryInterface. The system. runtime. interopservices namespace will show that there is a QueryInterface method in the marshal class:Public Static IntQueryInterface (intptr punk,RefGuid IID,OutIntptr BPPV );

Solve this problem.

Test the Code:UsingSystem;
UsingSystem. runtime. interopservices;
UsingBackgroundcopymanager3_0;

Namespace Www. xianfen. net
{
Class Program
{
Static Void Main ( String [] ARGs)
{
Backgroundcopymanager3_0class Mgr = New Backgroundcopymanager3_0class ();
Guid;
Ibackgroundcopyjob job;

// create job
Mgr. createjob ( " job " , bg_job_type.bg_job_type_download, out guid, out job );

// guid of The New Interface version.
guid gjob4 = New GUID ( " 659cdeae-489e-11d9-a9cd-000d000065133 " );

// get the pointers of interfaces of earlier versions
intptr punknwjob = marshal. getiunknownforobject (job);
intptr punknwjob4;

// get the pointer of The New Interface version
int hresult = marshal. queryInterface (punknwjob, ref gjob4, out punknwjob4 );

// get the new version of the interface instance
ibackgroundcopyjob4 job4 = (ibackgroundcopyjob4) marshal. getobjectforiunknown (punknwjob4);

Job4.addfile ("Http://www.xianfen.net/GRMSDKX_EN_DVD.iso","C: \ winsdk. ISO");
Job4.setpriority (bg_job_priority.bg_job_priority_foreground );
//Various operations...
}
}
}

Download: Download the modified bits3_0.idl and TLB files and assembly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.