Tag Archives: Managed c + +

Solution to the error code of 0x80040154 in COM / ole call

1. The background
In the project development, in order to make C# call the original C++ developed OLE interface program, the following method was adopted to establish C++CLI project as an intermediate DLL, with the following advantages:
(1) on the one hand, he can better use C++ to access OLE API functions, and the original C++ development of OLE programs better combination;
(2) on the other hand, C# can easily reference C++CLI DLL, so that the implementation of C# code on the old version of OLE program calls quickly;
(3) low coupling, easy to test, about the correctness of OLE interface and C++CLI, you can independently set up a test project to test.

Therefore, C# projects utilize the invocation relationship of C++ OLE as follows:
C # = = & gt; > > C + + the CLR = = & gt; > > C + +, OLE

Problem 2.
In the real project, the OLE program is developed by another TEAM, we just call it. But during the testing process, the call to OLE interface in the latest test environment failed. Debug finds that the C++CLI failed to initialize the specified OLE program when calling the OLE interface with the error code 0x80040154, which means the following:

OLE error code 0x80040154. Class is not registered.

The main online solution is to call the RegSVR32 command to register your program. The purpose of registration is to establish the mapping relationship between ProgramID and CLSID in the registry. In my understanding, ProgramID is equivalent to our name. When we use the API to call the COM/OLE interface, we pass a plain string called ProgramID, and the API internally operates on the CLSID based on the mapping stored in the registry. There is a subkey in the registry with CLSID as key and its name is LocalService32. The corresponding key value of this key stores the local full path of the final OLE program. Finally, it is found that this key value in our test environment is wrong and does not point to the real OLE program path, thus causing failure in the initialization of OLE program. Given the wrong program path, the loader must fail.

3. Solutions

Modify the CLSID stored in the OLE program full path.