tags:

views:

18

answers:

2

Hi I have an ATL based COM plugin and there is another 3rd party library that I want to use. It's not COM dll and implemented in C++.

details on 3rd party dll as follows:

Configuration type = Dynamic Library(.dll)

Use of MFC = Use MFC in a static library

Use of ATL = not using ATL

Character set = use multi-btye char set

CRL support=no clr support

details on COM dll project as follows:

Configuration type = Dynamic Library(.dll)

Use of MFC = Use MFC in a shared library

Use of ATL = dynamic link to ATL

Character set = use unicode char set

CRL support=no clr support

This is my code

HRESULT FinalConstruct()
{
    LPCWSTR libPath = _T("LicEnf.dll") ;
    const char * clibPath = "LicEnf.dll" ;

    SetLastError(0);
    HMODULE hMod = LoadLibraryA(clibPath);
    if(hMod==NULL)
    {

        LOG4CXX_TRACE(CALMLogger::GetModuleLogger(ModuleName),
            _T("Could not load library:GetLastError() returned ") << GetLastError());

    }

    return S_OK;
}

FinalConstruct is called 3times. hMod always 0 and on the log file i have

Could not load library:GetLastError() returned 183

Could not load library:GetLastError() returned 126

Could not load library:GetLastError() returned 126

where

-183 (0xB7) =ERROR_ALREADY_EXISTS

-126 (0x7E) =ERROR_MOD_NOT_FOUND

On the other hand if I call this code from another test application which is an ordinary exe file , loadLibrary works fine. Is there any limitation of loading a native win32 dll from COM-dll and what's my mistake here ?

Thanks

+1  A: 

Did you try to specify full path to the library?

vtrz
thnx. I did and worked. How come full path is required even all the dll's and exe's are in the same path ? I thought I should be able to call with just file name.
tguclu
A: 

LoadLibrary required full path name. here is the working code

HRESULT FinalConstruct()
{
    LPCWSTR libPath = _T("d:\\projects\\LMS\\src\\LMS_LIB\\LicEnf\\Debug\\LicEnf.dll" ) ;
    DWORD  retval=0;
    BOOL   success; 
    TCHAR  buffer[BUFSIZE]=TEXT(""); 
    TCHAR  buf[BUFSIZE]=TEXT(""); 
    TCHAR** lppPart={NULL};

    SetLastError(0);
    SetErrorMode(0);
    retval = GetFullPathName(libPath,
         BUFSIZE,
         buffer,
         lppPart);

    HMODULE hMod = LoadLibrary(buffer);
    if(hMod==NULL)
    {
        int lastError = GetLastError();
        CString message;
        message.Format( _T("Failed in finding LicEnf.dll (%d)"), lastError );
        LOG4CXX_TRACE(CALMLogger::GetModuleLogger(ModuleName),message );

    }

    return S_OK;
}
tguclu