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.