How to call COM controls in Windows in the D language

Source: Internet
Author: User
Tags ole

A COM component in Windows is an important part of Windows, can be registered as a public component of the system, or may not be registered for direct invocation. Before calling COM components in the D language, we need to understand COM components. COM components have a common interface, written in the IDL language, using the Mild.exe compiler to generate a TLB format file, usually called a type library, when generating a COM component DLL, the file is placed in the DLL's resource file, the resource name is called TypeLib

To invoke a COM component, you first need to know the interface of the COM component, so you can export the type library from the DLL to the IDL interface file, and then convert the IDL interface file into the D-language interface file so that you can use the COM control in the D language.

I. Extract the interface in the COM file as an IDL file

Drag and drop the Mscomm32.ocx file into vs to view, as shown, you can see the typelib resource, right---and export file, named Mscomm32.tlb, the file is the compilation format of the interface file, you need to use the ole/com Object The viewer is converted to an IDL file. Here we use a tool of the D language Tlb2idl.exe to convert, this tool is a tool in the Visuald. The third parameter of the transformation needs to specify the path to the IViewers.dll, and is actually converted using the Ole/com Object Viewer.

After the conversion succeeds, the I.dll file becomes heavy,

Since the Tlb2idl.exe program uses the LoadTypeLib function to load the type library, the type library needs to be exported from the DLL first, if the type library is read directly from Exe/dll using the Loadtypelibfromresource function. You can export the IDL file directly from the Exe/dll. Using the Loadregtypelib function, you can directly export a registered COM control interface.

Second, the IDL file into the D language interface

Converting IDL to D can be done using Visuald's Vsi2d.exe tool.

This generates the I.D file, which is the interface file for the Mscomm32.ocx.

Third, call COM control

With the COM control interface, the use of COM controls has finished more than half, now just need to use the COM control. Calling a COM control requires the following steps:

1) Loading DLL files with LoadLibrary

2) Use GetProcAddress to get DllGetClassObject function pointer

3) Obtain the IClassFactory factory by calling the DllGetClassObject function pointer.

4) Call the CreateInstance function of the IClassFactory factory to create the instance.

5) Turn the pointer of the instance into an interface, then you can use it.

Reference: http://blog.csdn.net/wangqiulin123456/article/details/8962453

Reference c++:http://blog.csdn.net/haijun286972766/article/details/6273414

Reference c++:http://www.cnblogs.com/cpper-kaixuan/p/3540446.html?utm_source=tuicool&utm_medium=referral

How to call COM controls in Windows in the D language

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.