Have some code originally designed for Windows 2000 and the WMI SDK. I am trying to resolve the linker error. After trying the options referneced in What is an undefined reference/unresolved external symbol error and how do I fix it? was unable to find a solution.
The unresolved symbols error:
1>WmiProvider.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall Provider::Provider(wchar_t const *,wchar_t const *)" (__imp_??0Provider@@QAE@PB_W0@Z)
1>WmiProvider.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __thiscall CInstance::SetCHString(wchar_t const *,char const *)" (__imp_?SetCHString@CInstance@@QAE_NPB_WPBD@Z)
1>dllmain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static int __stdcall CWbemProviderGlue::FrameworkLogoffDLL(wchar_t const *)" (__imp_?FrameworkLogoffDLL@CWbemProviderGlue@@SGHPB_W@Z)
1>dllmain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static int __stdcall CWbemProviderGlue::FrameworkLoginDLL(wchar_t const *)" (__imp_?FrameworkLoginDLL@CWbemProviderGlue@@SGHPB_W@Z)
I've tried adding code:
#pragma comment(lib,"Framedyn.lib")
and tried adding to lib to framedyn.lib linker options but still get same error.
The project has the following defined to allow running on Windows XP:
#define _WIN32_WINNT 0x0501
Project settings include:
- Target Platform Version 7.0
- Platform Toolset Visual Studio 2017 - Windows XP (v141_xp)
- C++ Language Standard Default (ISO C++14 Standard7)
- Language - Conformance Mode - No
- Target X86
Example usage:
case DLL_PROCESS_ATTACH:
ghModule = hInstDLL;
bRet = CWbemProviderGlue::FrameworkLoginDLL(L"WmiProvider");
break;
CL.exe and MSBUILD.exe load WbemGlue.h from:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\WbemGlue.h
link.exe loads FrameDyn.lib from:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\FrameDyn.Lib
dumpbin /exports "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\FrameDyn.Lib" shows entry for FrameworkLoginDLL as:
?FrameworkLoginDLL@CWbemProviderGlue@@SGHPBG@Z (public: static int __stdcall CWbemProviderGlue::FrameworkLoginDLL(unsigned short const *))
?FrameworkLoginDLL@CWbemProviderGlue@@SGHPBGPAJ@Z (public: static int __stdcall CWbemProviderGlue::FrameworkLoginDLL(unsigned short const *,long *))
Looking at the symbols difference is when I compile visual studio is looking for FrameworkLoginDLL@CWbemProviderGlue@@SGHPB_W@Z whereas the lib file has a G at the end and no W i.e. **FrameworkLoginDLL@CWbemProviderGlue@@SGHPBG@Z**
The old MSDN documentation (from August 2001) specifies this use:
The FrameworkLoginDLL method is called when the DLL_PROCESS_ATTACH value is sent to DllMain to determine whether the provider server can be loaded.
static BOOL WINAPI CWbemProviderGlue::FrameworkLoginDLL(
LPCWSTR name
);
Requires:
- Windows NT/2000/XP: Included in Windows NT 4.0 SP4 and later.
- Windows 95/98/Me: Included in Windows 95 and later.
- Header: Declared in WbemGlue.h; include FwCommon.h.
- Library: Use Framedyn.lib.
The current documentation here specifies use:
BOOL FrameworkLoginDLL(
LPCWSTR name
);
With following requirements:
- Minimum supported client Windows Vista
- Minimum supported server Windows Server 2008
- Target Platform Windows Header wbemglue.h (include FwCommon.h)
- Library FrameDyn.lib
- DLL FrameDynOS.dll; FrameDyn.dll
Creating a new Visual Studio 2019 Project with Desktop C++ Wizard, selecting DLL, and all other defaults reproduces same issue with this code:
#include "framework.h"
#include <FwCommon.h>
#pragma comment(lib,"FrameDyn.lib")
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
BOOL bRet = TRUE;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
bRet = CWbemProviderGlue::FrameworkLoginDLL(L"WmiProvider");
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return bRet;
}
Demangling the symbol linker is trying to use get the following:
__imp_public: static int __stdcall CWbemProviderGlue::FrameworkLoginDLL(wchar_t const *)
Demangling the symbol in actual .lib file:
public: static int __stdcall CWbemProviderGlue::FrameworkLoginDLL(unsigned short const *)
Definition in WbemGlue.h
static BOOL WINAPI FrameworkLoginDLL(LPCWSTR name);