Facing issue in using a COM library

kamleshm

Member
Joined
Nov 18, 2021
Messages
10
Programming Experience
5-10
Hello All
I have a C# project developed in dotnet framework 4.5 , windows 10 machine. The project "adds a reference" to the COM library , that has been developed in VB6
The project compiles properly but when it is run , I get the exception as below


C#:
System.TypeInitializationException:
'The type initializer for 'CcWanPipesClientLib.ClearcaseHelper' threw an exception.'

innerexception:
BadImageFormatException: Retrieving the COM class factory for component with CLSID {B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F} failed due to the following error: 800700c1  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1).

On different links and forums , dllsurrogate method " Using a 32bit COM object in a 64bit environment" , I followed the same
But still the exception comes.

Please guide me through it as I am new to both C# and COM
 
_Module.RegisterServer:
inline HRESULT CComModule::RegisterServer(
    _In_ BOOL bRegTypeLib /*= FALSE*/,
    _In_opt_ const CLSID* pCLSID /*= NULL*/) throw()
{
    HRESULT hr = S_OK;
    _ATL_OBJMAP_ENTRY* pEntry = m_pObjMap;
    if (pEntry != NULL)
    {
        for (;pEntry->pclsid != NULL; pEntry++)
        {
            if (pCLSID != NULL)
            {
                if (!IsEqualGUID(*pCLSID, *pEntry->pclsid))
                    continue;
            }
            hr = pEntry->pfnUpdateRegistry(TRUE);
            if (FAILED(hr))
                break;
            hr = AtlRegisterClassCategoriesHelper( *pEntry->pclsid,
                pEntry->pfnGetCategoryMap(), TRUE );
            if (FAILED(hr))
                break;
        }
    }
    if (SUCCEEDED(hr))
        hr = CAtlModuleT<CComModule>::RegisterServer(bRegTypeLib, pCLSID);
    return hr;
}
 
Command: >reg export "HKEY_CLASSES_ROOT\CLSID\{B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F}" "ccauto32_32.reg" /reg:32
32bit:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F}]
@="B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F"
"AppID"="B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F"

[HKEY_CLASSES_ROOT\CLSID\{B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F}\InprocServer32]
@="C:\\Program Files\\IBM\\RationalSDLC\\clearcase\\bin\\ccauto.dll"

[HKEY_CLASSES_ROOT\CLSID\{B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F}\ProgID]
@=""

[HKEY_CLASSES_ROOT\CLSID\{B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F}\VersionIndependentProgID]
@=""



Command : reg export "HKEY_CLASSES_ROOT\CLSID\{B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F}" "ccauto32_64.reg" /reg:64
64bit:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F}]
@="ClearCase Class"

[HKEY_CLASSES_ROOT\CLSID\{B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F}\InprocServer32]
@="C:\\Program Files\\IBM\\RationalSDLC\\clearcase\\bin\\ccauto.dll"
"ThreadingModel"="Both"

[HKEY_CLASSES_ROOT\CLSID\{B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F}\ProgID]
@="ClearCase.Application.1"

[HKEY_CLASSES_ROOT\CLSID\{B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F}\Programmable]

[HKEY_CLASSES_ROOT\CLSID\{B22C7EFB-5A5E-11D3-B1CD-00C04F8ECE2F}\VersionIndependentProgID]
@="ClearCase.Application"
 
Last edited:
I thought that you were now building your COM object as 64-bit. Why are you still registering it as 32-bit?
 
The crux part is if I create a console application and add the COM library as a reference, it works as expected . But in my case I have a wanservice.dll that refers to the COM dll and thats the place where the exception comes . Also while building the code , I get few Metasource code ( C# files ) . Its different for a console application and a dll
 
Is the running console application running as 32-bit or 64-bit? Compile your C# program to run with that same bit width. Abandon trying to use the DllSurrogate since you don't have to. You have the ability to compile against the bit width that you want to use. The error that you are getting ( 0x800700c1) is saying that it's not recognizing "C:\Program Files\IBM\RationalSDLC\clearcase\bin\ccauto.dll" as binary that it can load. That normally happens when the DLL is of the wrong bit width for the process that is trying to load the DLL.
 
Hopefully you switched to 4.6.2 which is the lowest currently supported version. Ideally you should go all the way to 4.8 to get all the security fixes.
 

Latest posts

Back
Top Bottom