1

I have imported an Activex component (*.ocx) on Embarcadero C++Builder 10.2 when I build the program I get this warning "Warning W8127 Function defined with different linkage".

Can any one tell me how I can resolve this issue. My code is below:

#include <vcl.h>
#pragma hdrstop
#include <System.Win.ComServ.hpp>
#include <axbase.h>
#include <olectl.h>

#pragma package(smart_init)
#pragma link "System.Win.ComServ"

#pragma package(smart_init)
#pragma link "System.Win.ComServ"

 // -----------------------------------------------------------------------------
 // Entry point of your Server invoked by Windows for processes or threads are
// initialized or terminated.
//
// -----------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
 return TRUE;
}
// -----------------------------------------------------------------------------
// Entry point of your Server invoked to inquire whether the DLL is no
// longer in use and should be unloaded.
// -----------------------------------------------------------------------------
STDAPI __export DllCanUnloadNow(void)
 {
  Comserv::TComServer* comserver = Comserv::GetComServer();
  return (!comserver ||
        ((comserver->ObjectCount /* + comserver->FactoryCount */) == 0)) ?
        S_OK : S_FALSE;
 }
 // -----------------------------------------------------------------------------
 // Entry point of your Server allowing OLE to retrieve a class object from
 // your Server
 // -----------------------------------------------------------------------------
STDAPI __export DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
 Comobj::TComObjectFactory* Factory = Comobj::ComClassManager()->GetFactoryFromClassID(rclsid);
 if (Factory)
 {
  if (Factory->GetInterface(riid, ppv))
    return S_OK;
  else
    return E_NOINTERFACE;
 }
 else
 {
  *ppv = 0;
  return CLASS_E_CLASSNOTAVAILABLE;
 }
}

// -----------------------------------------------------------------------------
// Entry point of your Server invoked to instruct the server to create
// registry entries for all classes supported by the module
// -----------------------------------------------------------------------------
  STDAPI __export DllRegisterServer(void)
  {
   Comserv::TComServer* comserver = Comserv::GetComServer();
   if (comserver)
   {
     try
     {
        comserver->LoadTypeLib();
        comserver->UpdateRegistry(true);
        return S_OK;
     }
    catch(...)
     {
        return E_FAIL;
     }
  }
 else
 {
    return E_FAIL;
}
}

   // -----------------------------------------------------------------------------
   // Entry point of your Server invoked to instruct the server to remove
   // all registry entries created through DllRegisterServer.
   // -----------------------------------------------------------------------------
  STDAPI __export DllUnregisterServer(void)
   {
    Comserv::TComServer* comserver = Comserv::GetComServer();
    if (comserver)
    {
     try
     {
        comserver->LoadTypeLib();
        comserver->UpdateRegistry(false);
        return S_OK;
     }
    catch(...)
    {
        return E_FAIL;
    }
}
else
{
    return E_FAIL;
}
}

    // ------------------------------------------------------------------------------
    // Entry point of your Server installation/setup. Used for 'PerUser' registration
    // Invoked via call to "regsvr32 /n /i:user [/u] axlibrary.dll"
    // ------------------------------------------------------------------------------
    STDAPI __export DllInstall(BOOL bInstall, LPCWSTR pszCmdLine)
      {
       Comserv::TComServer* comserver = Comserv::GetComServer();
       if (comserver)
       {
        bool savePerUser = comserver->PerUserRegistration;
        if (pszCmdLine && !StrIComp(pszCmdLine, L"user"))
        comserver->PerUserRegistration = true;
        else
        comserver->PerUserRegistration = false;
     HRESULT result = E_FAIL;
     if (bInstall)
      {
        result = DllRegisterServer();
        if (result == E_FAIL)
            DllUnregisterServer();
      }
     else
        result = DllUnregisterServer();
        comserver->PerUserRegistration = savePerUser;
        return result;
     }
   else
   {
    return E_FAIL;
  }
 }

The functions DllCanUnloadNow() and DllGetClassObject are declared in this header file "comebaseapi.h" as follow:

_Check_return_ STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID FAR* ppv); __control_entrypoint(DllExport) STDAPI DllCanUnloadNow(void); The functions DllRegisterServer() and DllUnregisterServer() are declared in this header file "olectl.h" as follow: __control_entrypoint(DllExport) STDAPI DllRegisterServer(void); __control_entrypoint(DllExport) STDAPI DllUnregisterServer(void);

The function DllInstall() is declared in this header file "shlwapi.h" as follow:

// DllInstall (to be implemented by self-installing DLLs) STDAPI DllInstall(BOOL bInstall, _In_opt_ PCWSTR pszCmdLine);

I thank you for your support.

geek225
  • 157
  • 8
  • Some claim this may be due to missing `extern "C"` - see https://learn.microsoft.com/en-us/cpp/cpp/extern-cpp?view=vs-2019 – orhtej2 Jan 28 '20 at 10:42
  • Thanks. but where I have to add the `extern "c" ` ? in the header file ?? or in the cpp file ? Thanks. – geek225 Jan 28 '20 at 10:47
  • In the cpp file, around the include. https://stackoverflow.com/a/16851023/193892 – Prof. Falken Jan 28 '20 at 10:47
  • I have added `extern "C"{ #include #include #include }` but I still have the same warning. – geek225 Jan 28 '20 at 10:53
  • Can you check what the macro `STDAPI` evaluates to *in your C++ file*? It *should* be `extern "C" HRESULT __stdcall` (as it is in, e.g. `shlwapi.h`). If it's not (or rather, if it's *different* in the header(s) and source(s)), then that will be the cause. – Adrian Mole Jan 28 '20 at 12:03
  • Or remove the `__export` keyword? – Adrian Mole Jan 28 '20 at 12:08
  • The STDAPI is linked to the the header file "winnt.h" and equal to `EXTERN_C HRESULT STDAPICALLTYPE` and the STDAPICALLTYPE evaluates in the same file "winnt.h" to `__export __stdcall` or to ` __stdcall ` . – geek225 Jan 28 '20 at 12:48

0 Answers0