I am trying to register BHO with APPcontainer.Now as per the blog http://blogs.msdn.com/b/ieinternals/archive/2012/03/23/understanding-ie10-enhanced-protected-mode-network-security-addons-cookies-metro-desktop.aspx
,I have defined following in same cpp file as DLLRegister
DEFINE_GUID(CATID_AppContainerCompatible, 0x59fb2056,0xd625,0x48d0,0xa9,0x44,0x1a,0x85,0xb5,0xab,0x26,0x40);
STDAPI DllRegisterServer(void)
{
// let ATL handle this
HRESULT hr = _AtlModule.DllRegisterServer();
ICatRegister* pcr = NULL ;
hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
if (FAILED(hr))
return hr;
if (SUCCEEDED(hr))
{
// Register this category as being "implemented" by
// the class.
CATID rgcatid[1] ;
rgcatid[0] = CATID_AppContainerCompatible;
hr = pcr->RegisterClassImplCategories(CLSID_ABC, 1, rgcatid);
}
When I try to compile this code I am getting following error:
unresolved external symbol CATID_AppContainerCompatible
Not sure why this is coming. I can navigate to CATID_AppContainerCompatible definition by right click on it.
any suggesitons??
I solved the issue. since DEFINE_GUID declares GUID as extern I need to put const GUID CATID_AppContainerCompatible ; in my file .After putting that statement its compiling.
DEFINE_GUID behavior depends on presence of INITGUID definition. This is a very frequent problem, so it makes no sense to repeat the details once again, here is further reading: How to avoid error "LNK2001 unresolved external" by using DEFINE_GUID.
To avoid falling into this trap you can use __declspec(uuid(...)) specifier and let compiler sort GUIDs out automatically, e.g.:
class __declspec(uuid("{26AFA816-359E-4094-90A8-BA73DE0035FA}"))
AppContainerCompatible;
// ...
rgcatid[0] = __uuidof(AppContainerCompatible); //CATID_AppContainerCompatible;
More on this: Referencing GUIDs
Related
I am starting to work with WIA 2.0 and, as so many others, have started from the MS provided tutorial & example code (see this http://msdn.microsoft.com/en-us/library/ms629848%28v=VS.85%29.aspx).
Unlike the others what I have been unable to find is where the GUIDs CLSID_WiaDevMgr2 & IID_IWiaDevMgr2 are defined.
My code compiles - the variables are declared in wia_lh.h - but fails to build with error messages that these two symbols are unresolved i.e. not defined.
HRESULT CWiaSP::CreateWiaDeviceManager()
{
pWiaDevMgr = NULL;
HRESULT hr = CoCreateInstance( CLSID_WiaDevMgr2, NULL, CLSCTX_LOCAL_SERVER, IID_IWiaDevMgr2, (void**)&pWiaDevMgr );
return hr;
}
How to identify the GUID value for these: can this be done programmatically, or are they well known values that are defined somewhere?
This one is driving me nuts. I've tried everything I can think of. Here are the relevant parts of the DirectInput code.
BOOL CALLBACK EnumDevicesCallback(const DIDEVICEINSTANCE* DeviceInfo, VOID* Context);
if(DirectInput8Interface == DI_OK)
{
DirectInput8InterfacePointer->EnumDevices(
DI8DEVCLASS_GAMECTRL,
(LPDIENUMDEVICESCALLBACKA) EnumDevicesCallback,
NULL,
DIEDFL_ATTACHEDONLY);
}
When I try to compile, I get the error:
unresolved external symbol "int __stdcall EnumDevicesCallback(struct
DIDEVICEINSTANCEA const *,void *)"
(?EnumDevicesCallback##YGHPBUDIDEVICEINSTANCEA##PAX#Z) referenced in
function _WinMain#16.
As you can see, the external symbol the compiler can't find is related to the DIDEVICEINSTANCE parameter of the EnumDevicesCallback function. That shouldn't be, because I've included dinput.h and linked to dinput8.lib and dxguid.lib. I even tried defining DIDEVICEINSTANCE in my own code and got a message that it conflicted with a previous definition.
What could that error message mean?
That is not how callbacks work.
EnumDevicsCallback is not a function that exists. You're supposed to write your own function that EnumDevices will call for each device. Your function doesn't have to be called EnumDevicesCallback - that's an example.
For example, if you just wanted to print the name of each device, you might write
BOOL CALLBACK PrintDevicesCallback(const DIDEVICEINSTANCE* DeviceInfo, VOID* Context)
{
_tprintf("%s %s\n", DeviceInfo->tszProductName, DeviceInfo->tszProductName);
return DIENUM_CONTINUE;
}
and then pass PrintDevicesCallback to EnumDevices.
I dare say, the culprit is BOOL CALLBACK EnumDevicesCallback(const DIDEVICEINSTANCE* DeviceInfo, VOID* Context); - the function is likely a C-function, but you declare it in your .cpp file as C++-function.
Instead of doing that, include a proper .h file with the declaration, which is likely to have correct extern specified.
I am trying to compile a 14 year old C++ program with VS2010 C++ compiler (dont ask why :( ). I am getting the following error
Error 10 error LNK2019: unresolved external symbol "public: __thiscall CConfiguration::CConfiguration(void)" (??0CConfiguration##QAE#XZ) referenced in function
"public: __thiscall CWhoisService::CWhoisService(void)" (??0CWhoisService##QAE#XZ)
I have a cpp file CWhoisService.cpp with a header CWhoisService.h
CWhoisService.h:
class CWhoisService
{
public:
HRESULT Initialize(const char * szServiceName, REFCLSID pMetricsCLSID);
CWhoisService();
~CWhoisService();
HRESULT CheckService();
protected:
CConfiguration m_Configuration;
protected:
bool m_bStartedEvenLog;
bool m_bStartedConfiguration;
private:
//Don't want standard constructor to be called
};
CWhoisService.cpp
#include "ConfigurationLib.h"
#include "CWhoisService.h"
CWhoisService::CWhoisService():
m_bStartedEvenLog(false),
m_bStartedConfiguration(false)
{
}
HRESULT CWhoisService::Initialize(const char * szServiceName, REFCLSID pMetricsCLSID)
{
HRESULT hr = S_OK;
//Initialize the configuration library
hr = m_Configuration.Initialize(VERSION_COMPANY,VERSION_SYSTEM);
the ConfigurationLib.h file referenced in the cpp file and included before CWhoisService.h is as follows:
#ifndef _CONFIGURATION_MODULE
#define _CONFIGURATION_MODULE
class CConfigurationBase
{
public:
CConfigurationBase() : m_bInitialized(false) {};
virtual ~CConfigurationBase() {};
virtual HRESULT Initialize(LPCTSTR szCompanyName, LPCTSTR szSystemName, LPCTSTR szGlobalMachineName = NULL) = 0;
virtual bool IsInitialized() { return m_bInitialized;};
protected:
bool m_bInitialized; // True if the object has been initialized
};
class CConfiguration : public CConfigurationBase
{
public:
CConfiguration();
virtual ~CConfiguration();
// Initialized some values for the class. Must be called first!
virtual HRESULT Initialize(LPCTSTR szCompanyName, LPCTSTR szSystemName, LPCTSTR szGlobalMachineName = NULL);
protected:
// This is the function that actually goes about getting values from the registry
// The other Get functions all call this one
virtual HRESULT GetValue(HKEY hkeyBase, LPCTSTR szSectionName, LPCTSTR szValueName, CString * csValue, DWORD * pdwValue, DWORD dwType);
}; // CConfiguration
#endif // _CONFIGURATION_MODULE
everything was fine last time it compiled around 10 years ago. but now it does not seem to find the ConfigurationLib.h file. i made sure it as part of the project. if i removed it from the start of the cpp file I get the error: missing ';' before identifier 'm_Configuration' so ti obviously see it. yet it does not appear to be able to resolve the class.
Any assistance would be appreciated, i have spend last 3 days on this site and many others but no progress.
i have spend last 3 days on this site and many others but no progress
It is always good to understand the errors that are produced by the linker for Visual C++. Then next time you see such an error, it shouldn't take 3 days to figure out. I know the message looks garbled at first, but it really isn't if you know what to look for.
The trick is to choose the parts of the error that makes sense, and skip over the name-mangling (the gobbledy-gook that looks like the linker is swearing at you). Sometimes the name-mangling is useful, but for your error, it isn't important.
Let's go through the error:
unresolved external symbol "public: __thiscall CConfiguration::CConfiguration(void)"
The line above indicates the function implementation that cannot be found by the linker. The function is CConfiguration::CConfiguration(void). In other words, the 0-argument constructor for CConfiguration cannot be located by the linker.
Next part of the error message states:
referenced in function "public: __thiscall CWhoisService::CWhoisService(void)"
This is the function that is attempting to call the CConfiguration constructor. It is the CWhoisService::CWhoisService(void) constructor. You see it here:
class CWhoisService
{
//...
protected:
CConfiguration m_Configuration;
};
You have a member that is a CConfiguration (m_Configuration), so when you instantiate a CWhoIsService, you are also instantiating a CConfiguration object.
The bottom line is that the linker cannot find the implementation to the CConfiguration constructor that takes no arguments.
Either you
did not add the source module to your project that contains the implementation of the CConfiguration constructor to the project, or
The CConfiguration constructor is in a library and you didn't specify the library to link to in your project, or
You just plain old didn't code a CConfiguration constructor that has no arguments, or
some other unknown issue that causes the linker to miss the code that contains the implementation of the constructor.
My guess is more than likely item 1. above.
Also, this has nothing to do with header files. The header file allows a module to be compiled without error. It does not guarantee that the linker will link successfully.
For example, you can have a module that contains calls to functions that do not exist, but the module will compile successfully. However, at link time, if the function called doesn't actually exist, then you will get the error (as you're seeing now).
At least in the code snippets you showed there is no the constructor definition. It is only declared
class CConfiguration : public CConfigurationBase
{
public:
CConfiguration();
//...
I followed this tuorial to create a COM dll in Visual Basic. http://www.codeproject.com/KB/COM/Basics_of_Idl_file.aspx
I now want to use this dll in a C++ project. I used OLE/COM Viewer to create an .idl file as is described in the second half this tutorial.
http://www.codeproject.com/KB/COM/vb_from_vc.aspx
I compiled the .idl with the midl compiler and included the .h file that was created in my c++ project.
Here is my Visual Basic Code
<ComClass(MyComClass.ClassId, MyComClass.InterfaceId, MyComClass.EventsId)> _
Public Class MyComClass
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "46604f8a-85a2-4027-9728-0390534c9209"
Public Const InterfaceId As String = "30274029-711d-459a-9270-f9d73ad8737f"
Public Const EventsId As String = "5e234d69-5263-4001-86ff-c475b113a77d"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
Public Sub DisplayMessage()
MsgBox("Hello from MyComClass!")
End Sub
End Class
Here is my c++ Code
// Declare an HRESULT and a pointer to the clsVBTestClass interface
HRESULT hr;
_MyComClass *IVBTestClass = NULL;
// Now we will intilize COM
hr = CoInitialize(0);
// Use the SUCCEEDED macro and see if we can get a pointer
// to the interface
if(SUCCEEDED(hr))
{
hr = CoCreateInstance( CLSID_MyComClass,
NULL,
CLSCTX_INPROC_SERVER,
IID__MyComClass,
(void**) &IVBTestClass);
// If we succeeded then call the CountStringLength method,
// if it failed then display an appropriate message to the user.
if(SUCCEEDED(hr))
{
long ReturnValue;
_bstr_t bstrValue("Hello World");
// We can test this HR as well if we wanted to
hr = IVBTestClass->DisplayMessage();
hr = IVBTestClass->Release();
}
else
{
}
}
// Uninitialize COM
CoUninitialize();
I receive the following errors when I compile my c++ project
error LNK2001: unresolved external symbol _CLSID_MyComClass
error LNK2001: unresolved external symbol IID_MyComClass
Could someone help me figure out what I am doing wrong?
If you did not get to the last part of creating a Type Library, that is important.
You then need an #import statement in your C++ code to use the .tlb file (or .dll if the type library is embedded in the dll, which is common).
#import is the equivalent to including a header file with COM, but generates a .tlh file (header) and a .tli (implementation) automatically.
I am trying to call a direct X funciton but I get the following error
error LNK2001: unresolved external symbol _D3DX10CreateTextureFromFileW#24
I understand that possibly there maybe a linker issue. But I am not sure where. I inluded both d3dx10.h and the d3d10.h. I also included the d3d10.lib file. Plus, the intellisense picks up on the method as well. below is my code. The method is D3DX10CreateTextureFromFile
bool MyGame::InitDirect3D()
{
if(!DX3dApp::InitDirect3D())
{
return false;
}
ID3D10Resource* pD3D10Resource = NULL;
HRESULT hr = D3DX10CreateTextureFromFile(mpD3DDevice,
L"C:\\delete.jpg",
NULL,
NULL,
&pD3D10Resource,
NULL);
if(FAILED(hr))
{
return false;
}
return true;
}
Is the appropriate DirectX library (or libraries) configured inthe project or makefile (or whatever build system is being used)?
For this particular function , it's D3DX10.lib.
You need D3DX10.lib: http://msdn.microsoft.com/en-us/library/bb172671%28VS.85%29.aspx