C # COM component registration and Microsoft regasm registration bug

Source: Internet
Author: User

At work, I used C # To write a COM component dedicated to reading and writing Excel (without the office environment, directly reading the original file, fast, it was found that there was a problem with the original registration program. The same problem has been encountered by netizens on the Internet, but no proper solution has been found. Now I have written all the questions and solutions for your reference.

 

In fact, the problem lies in the registration of COM components. The root cause is that the regasm/u command is sometimes invalid! The registration process provided here is to uninstall and then register. The original registration process was: (1) regasm/u xlsrw. DLL (2) regasm xlsrw. DLL (/codebase), in fact, the above anti-registration command is problematic, the specific example is as follows: (xlsrw. the clsid of the DLL is 61d993f1-cb5e-444d-bb3d-eb2bea4acb8d)

 

I registered version 1.0.0.2 and version 1.0.0.3 respectively, and then found that version 1.0.0.2 is used. DLL registration is invalid because the program still looks for xlsrw of 1.0.0.3 by default. DLL (because 1.0.0.3 still exists in the Registry key ). Program search xlsrw. the DLL process is to first find the xlsrw under the Registration path. DLL. If you find that the version is incorrect or does not exist, find it in the current path of the program and load it. This will undoubtedly cause a disaster to the COM component version upgrade.

To solve this problem, modify the registration process of COM and directly Delete the registry key corresponding to the COM component (the Registration path of the COM component is hkey_classes_root/CLSID ):

(1) reg Delete "hkey_classes_root/CLSID/{61d993f1-cb5e-444d-bb3d-eb2bea4acb8d}"/F

(2) regasm xlsrw. dll/codebase

The code for writing the console program is as follows: (main. c)

# Include <windows. h>
Void main ()
{

Winexec ("Reg delete/" hkey_classes_root // CLSID // {61d993f1-cb5e-444d-bb3d-eb2bea4acb8d}/"/F", sw_hide );
Sleep (100 );
Winexec ("regasm xlsrw. dll/codebase", sw_hide );
}

 

So far, the problem has been solved. Readers can solve your problem by using the above registration method when updating the COM component version written in C. Only the CLSID corresponding to the COM component and the corresponding COM component name are changed.

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.