COM technology insider Reading Notes-Chapter 1 dynamic connection

Source: Internet
Author: User

The pre-course is a PE file structure and DLL dynamic connection technology. If you do not know the PE file structure (this chapter is not very important, but this is a basic and basic content, for more information about the compilation and Loading Principles and the memory structure, see the official PE File Format documentation. If you have not written the DLL, see Chapter 19 and 20 of Windows core programming.

Return to the correct question. here we need to do a COM component server-using the DLL form, so it is different from the general DLL. Functions such as registration, uninstallation, initialization, object creation, and status determination are required. The list is as follows:

CMPAPI int APIENTRY DllMain(HINSTANCE hModule,DWORD dwReason,LPVOID lpReserved);CMPAPI STDAPI DllCanUnloadNow();CMPAPI STDAPI DllGetClassObject(const CLSID& clsid,const IID& iid,void** ppv);CMPAPI STDAPI DllRegisterServer(void);CMPAPI STDAPI DllUnregisterServer();

Note: The above cmpapi is my project compilation header and can be left blank.

The export function table is:

; CMPNT.def : Declares the module parameters for the DLL.LIBRARY      "CMPNT"EXPORTS    ; Explicit exports can go hereDllCanUnloadNow @1 PRIVATEDllGetClassObject @2 PRIVATEDllRegisterServer @3 PRIVATEDllUnregisterServer @4 PRIVATE

This part of the content is compiled and debugged Based on the code in this chapter and passed the test. It is attached to my resources. The environment is win7 and vs2008sp1.

Compile the cmpntproject and use regsvr32.exe dllfullpath for registration at runtime. This registration process needs to be tracked and understood. I have played a lot of MessageBox in it. When executing the regsvr32 command, when the first window is displayed, append the regsvr32 process to the debugging. You can clearly see the registration process and the order in which the above functions are called. It is of great help to deepen the registration principle of COM. If you are familiar with MessageBox, you can delete fewer items as needed.

Next, compile the mychap project and use the debugging process to observe the entire com running process. In this process, I learned a lot about the internal principles of COM.

Connection: http://u.download.csdn.net/upload/success

Any questions, pls contact me.

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.