Link error LNK2001 in VC7

G

Guest

I have some code that compiles and links fine in VC6 but does not
link in VC7. Here are the relevant parts of the code:

class AView : public CScrollView
{
....
public:
AFX_DISPMAP_ENTRY* _dispatchEntries;
UINT _dispatchEntryCount;
DWORD _dwStockPropMask;
AFX_DATA AFX_DISPMAP dispatchMap;
#ifdef _AFXDLL
static const AFX_DISPMAP* PASCAL _GetBaseDispatchMap();
#endif
virtual const AFX_DISPMAP* GetDispatchMap() const;

}


void AView::MakeMap()
{
#ifdef _AFXDLL
dispatchMap.pfnGetBaseMap = _GetBaseDispatchMap;
#else
dispatchMap.pBaseMap = &CScrollView::dispatchMap;
#endif
_dispatchEntries = new AFX_DISPMAP_ENTRY[nSize];
dispatchMap.lpEntries = _dispatchEntries;
dispatchMap.lpEntryCount = &_dispatchEntryCount;
dispatchMap.lpStockPropMask = &_dwStockPropMask;
_dispatchEntryCount = (UINT) -1;
_dwStockPropMask = (DWORD)-1;
}

#ifdef _AFXDLL
const AFX_DISPMAP* PASCAL AView::_GetBaseDispatchMap()
{ return &CScrollView::dispatchMap; }
const AFX_DISPMAP* AView::GetDispatchMap() const
{ return &dispatchMap; }
#else
const AFX_DISPMAP* AView::GetDispatchMap() const
{ return &dispatchMap; }
#endif

During linking, I get the following error:
error LNK2001: unresolved external symbol "protected: static struct
AFX_DISPMAP const CCmdTarget::dispatchMap"
(?dispatchMap@CCmdTarget@@1UAFX_DISPMAP@@B)

My /LIBPATH includes Vc7/atlmfc/lib which is where I'm
assuming the necessary library resides.

There was a virtually identical problem submitted to
microsoft.public.languages.vc
on July 30, 2002 by sunil, but there was no response.

I would appreciate suggestions how to resolve this.
Tom
 
G

Gary Chang[MSFT]

Hi Tom,

This is because MFC7.0 and 7.1 no longer export CCmdTarget::dispatchMap
from the MFC DLL's, if you look in the corresponding DEF file the export is
no longer present. You can also find this out by doing a dumpbin /Exports
on the lib file that you are linking to.

Since this is a member you can only access it if you are inheriting from
the class anyway and the best thing to do is use the Accessor functions
that are provided to
us. you simply need to change the function to call
CCmdTarget::GetThisDispatchMap()


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
G

Gary Chang[MSFT]

OK, Tom,

I am very glad to know it resolved your problem, good luck!


Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
Joined
Dec 10, 2011
Messages
2
Reaction score
0
Gary Chang[MSFT];4338351 said:
Hi Tom,

This is because MFC7.0 and 7.1 no longer export CCmdTarget::dispatchMap
from the MFC DLL's, if you look in the corresponding DEF file the export is
no longer present. You can also find this out by doing a dumpbin /Exports
on the lib file that you are linking to.

Since this is a member you can only access it if you are inheriting from
the class anyway and the best thing to do is use the Accessor functions
that are provided to
us. you simply need to change the function to call
CCmdTarget::GetThisDispatchMap()


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

I added the code above as shown below. That allowed the original library to link.
Now when I try and link that library into another DLL I get the same error.

#ifdef _AFXDLL
const AFX_DISPMAP* PASCAL CHyperRunView::_GetBaseDispatchMap()
{
return CCmdTarget::GetThisDispatchMap(); }
const AFX_DISPMAP* CHyperRunView::GetDispatchMap() const
{ return CCmdTarget::GetThisDispatchMap(); }
#else
const
AFX_DISPMAP* CHyperRunView::GetDispatchMap() const
{ return &dispatchMap; }
#endif
void CHyperRunView::DispatchMakeMap(BOOL bWithObs /*=TRUE*/)
{
delete [] _dispatchEntries;
int nSize = 1;
if (bWithObs)
nSize += __min(2+m_array.GetSize(), HVW_MAX_DISPOBS);
#ifdef _AFXDLL
dispatchMap.pfnGetBaseMap = _GetBaseDispatchMap;
#else
dispatchMap.pBaseMap = &baseCHyperRunView::dispatchMap;
#endif
_dispatchEntries = new AFX_DISPMAP_ENTRY[nSize];
dispatchMap.lpEntries = _dispatchEntries;
dispatchMap.lpEntryCount = &_dispatchEntryCount;
dispatchMap.lpStockPropMask = &_dwStockPropMask;
_dispatchEntryCount = (UINT) -1;
_dwStockPropMask = (DWORD)-1;
int i=0;
for (i=0; i < nSize; i++)
{
_dispatchEntries.lpszName = VTS_NONE;
_dispatchEntries.lDispID = DISPID_UNKNOWN;
_dispatchEntries.lpszParams = VTS_NONE;
_dispatchEntries.vt = VT_VOID;
_dispatchEntries.pfn = (AFX_PMSG) 0;
_dispatchEntries.pfnSet = (AFX_PMSG) 0;
_dispatchEntries.nPropOffset = (size_t)-1;
_dispatchEntries.flags = afxDispCustom;
}
if (!bWithObs)
return; // just an empty dispatch map
for (i=0; i < nSize - 1; i++)
{
_dispatchEntries.vt = VT_DISPATCH;
_dispatchEntries.nPropOffset = offsetof(CHyperRunView, m_lpDispatch);
}

m_lpDispatch[0] = GetViewOb()->GetIDispatch(FALSE);
_dispatchEntries[0].lpszName = GetViewOb()->GetCode();
if (GetFrameOb())
{
m_lpDispatch[1] = GetFrameOb()->GetIDispatch(FALSE);
_dispatchEntries[1].lpszName = GetFrameOb()->GetCode();
}
for (i=2; i < nSize - 1; i++)
{
m_lpDispatch = m_array[i-2]->GetIDispatch(FALSE);
_dispatchEntries.lpszName = m_array[i-2]->GetCode();
}
}
#endif // _WIN32
 
Joined
Dec 10, 2011
Messages
2
Reaction score
0
I added the code above as shown below. That allowed the original library to link.
Now when I try and link that library into another DLL I get the same error.

#ifdef _AFXDLL
const AFX_DISPMAP* PASCAL CHyperRunView::_GetBaseDispatchMap()
{
return CCmdTarget::GetThisDispatchMap(); }
const AFX_DISPMAP* CHyperRunView::GetDispatchMap() const
{ return CCmdTarget::GetThisDispatchMap(); }
#else
const
AFX_DISPMAP* CHyperRunView::GetDispatchMap() const
{ return &dispatchMap; }
#endif
void CHyperRunView::DispatchMakeMap(BOOL bWithObs /*=TRUE*/)
{
delete [] _dispatchEntries;
int nSize = 1;
if (bWithObs)
nSize += __min(2+m_array.GetSize(), HVW_MAX_DISPOBS);
#ifdef _AFXDLL
dispatchMap.pfnGetBaseMap = _GetBaseDispatchMap;
#else
dispatchMap.pBaseMap = &baseCHyperRunView::dispatchMap;
#endif
_dispatchEntries = new AFX_DISPMAP_ENTRY[nSize];
dispatchMap.lpEntries = _dispatchEntries;
dispatchMap.lpEntryCount = &_dispatchEntryCount;
dispatchMap.lpStockPropMask = &_dwStockPropMask;
_dispatchEntryCount = (UINT) -1;
_dwStockPropMask = (DWORD)-1;
int i=0;
for (i=0; i < nSize; i++)
{
_dispatchEntries.lpszName = VTS_NONE;
_dispatchEntries.lDispID = DISPID_UNKNOWN;
_dispatchEntries.lpszParams = VTS_NONE;
_dispatchEntries.vt = VT_VOID;
_dispatchEntries.pfn = (AFX_PMSG) 0;
_dispatchEntries.pfnSet = (AFX_PMSG) 0;
_dispatchEntries.nPropOffset = (size_t)-1;
_dispatchEntries.flags = afxDispCustom;
}
if (!bWithObs)
return; // just an empty dispatch map
for (i=0; i < nSize - 1; i++)
{
_dispatchEntries.vt = VT_DISPATCH;
_dispatchEntries.nPropOffset = offsetof(CHyperRunView, m_lpDispatch);
}

m_lpDispatch[0] = GetViewOb()->GetIDispatch(FALSE);
_dispatchEntries[0].lpszName = GetViewOb()->GetCode();
if (GetFrameOb())
{
m_lpDispatch[1] = GetFrameOb()->GetIDispatch(FALSE);
_dispatchEntries[1].lpszName = GetFrameOb()->GetCode();
}
for (i=2; i < nSize - 1; i++)
{
m_lpDispatch = m_array[i-2]->GetIDispatch(FALSE);
_dispatchEntries.lpszName = m_array[i-2]->GetCode();
}
}
#endif// _WIN32


Disregard this request. The problem is the wrong library was being linked in that did not have the solution compile into it's object code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top