Home Dashboard Directory Help
Search

AfxOleUnregisterTypeLib cannot handle win64 typelibs by R. de Vreede


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 636148
Opened: 1/14/2011 7:48:10 AM
Access Restriction: Public
1
Workaround(s)
view
0
User(s) can reproduce this bug

Description

One can creat win32 and win64 typelibs. They are nicely registrated under keys win32 and win64 example:

HKEY_CLASSES_ROOT\TypeLib\{660587EF-812A-47C6-9256-DB0917CE510D}\1.0\0\win32

and

HKEY_CLASSES_ROOT\TypeLib\{660587EF-812A-47C6-9256-DB0917CE510D}\1.0\0\win64

However unregistering one of the two typelibs removes also the other.

The bug is in ctlreg.cpp which defines only

#define TYPELIBWIN _T("win32")
#define TYPELIBWIN_2 _T("win16")

and doesn't know anything about win64.

As a sample I added a project open it and choose x64 release.
Choose debug->start debugging, typelib will be registrated win64.
Got to win 32 release and choose debug->start debugging, idem win32.
Now choose x64 debug. Put a breakpoint on AfxOleUnregisterTypeLib in graphics.cpp
Verify with regedit both entries are there. The location I already mentioned above.
Now choose debug->start debugging. Program will halt at breakpoint. Trace from there on and watch both the entries disappear.
This means that after testing installation (which always include a uninstallation) deployment projects I loose my registry entries which make life difficult if I start with a project depending on this typelibs


Details
Sign in to post a comment.
Posted by Microsoft on 1/16/2011 at 10:08 PM
Thanks for your feedback.
We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by R. de Vreede on 1/14/2011 at 8:21 AM
By the way I do not why you do not use the UnregisterTypeLib funtion:

http://msdn.microsoft.com/en-us/library/ms221085.aspx

First use GetLibAttr and the yse the results for UnregisterTypeLib

That makes life a lot easier

Posted by Microsoft on 1/14/2011 at 7:59 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by R. de Vreede on 1/17/2011 at 2:41 AM
Because the bug is in all versions of MFC I offer a workaround. This code follows the syntax of AfxRegisterTypeLib in ctlreg.cpp from VS2005. You can write your own using the syntax of VS2010, but that is not backwards compatible.

In your code replace the call to:

AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor)

to:

AfxOleUnregisterTypeLibRepaired(AfxGetInstanceHandle())

and add the following code to your program

BOOL AFXAPI AfxOleUnregisterTypeLibRepaired(HINSTANCE hInstance)
{    
    BOOL bSuccess = FALSE;
    CStringW strPathNameW;
    wchar_t *szPathNameW = strPathNameW.GetBuffer(_MAX_PATH);
    ::GetModuleFileNameW(hInstance, szPathNameW, _MAX_PATH);
    strPathNameW.ReleaseBuffer();
    LPTYPELIB ptlib = NULL;
    if (SUCCEEDED(LoadTypeLib(strPathNameW.GetString(), &ptlib)))
    {
        ASSERT_POINTER(ptlib, ITypeLib);

        LPTLIBATTR pAttr;
        GUID tlidActual = GUID_NULL;

        if (SUCCEEDED(ptlib->GetLibAttr(&pAttr)))
        {
            ASSERT_POINTER(pAttr, TLIBATTR);
            tlidActual = pAttr->guid;
            ptlib->ReleaseTLibAttr(pAttr);
        }

// UnRegister the type library.

        if (SUCCEEDED(UnRegisterTypeLib(pAttr->guid,pAttr->wMajorVerNum,pAttr->wMinorVerNum,pAttr->lcid,pAttr->syskind)))
        {
            bSuccess = TRUE;
        }
        ptlib->Release();
    }
    else
    {
        TRACE(traceAppMsg, 0, L"Warning: Could not load type library from %s\n", strPathNameW);
    }

    return bSuccess;
}



File Name Submitted By Submitted On File Size  
graphics.zip 1/14/2011 81.86 MB