2

I'm using VS2010 with a managed C++ DLL calling a function in another managed C++ DLL and I'm getting many LNK2028 link errors that look like this.

1>udpPkt.obj : error LNK2028: unresolved token (0A0000AA) "unsigned short __cdecl ComputeCrc16(void const *,unsigned int)" (?ComputeCrc16@@$$FYAGPBXI@Z) referenced in function "public: short __thiscall CPrivateUdpPkt::ComputeCrc(void)const " (?ComputeCrc@CPrivateUdpPkt@@$$FQBEFXZ)

When I use dumpbin /export on the called DLL I see the unresolved function listed as:

7 6 00001040 ?ComputeCrc16@@YAGPBXI@Z = ?ComputeCrc16@@YAGPBXI@Z (  unsigned short __cdecl ComputeCrc16(void const *,unsigned int))

Comparing the functions prototype listed in the dump to the one listed in the error message the expanded prototype seems to match however the mangled names do not.

err ?ComputeCrc16@@$$FYAGPBXI@Z unsigned short __cdecl ComputeCrc16(void const *,unsigned int)
dump?ComputeCrc16@@YAGPBXI@Z    unsigned short __cdecl ComputeCrc16(void const *,unsigned int)

In the LNK2028 link it mentions problems with _cdecl being called with __clrcall but it says this occurs when calling an exported native function, however it doesn't describe how to resolve the issue. Besides I'm compiling both the called DLL and the calling DLL with /clr so neither of the calling or the called function should be native to my understanding.

The calling code looks like this

unsigned short __declspec(dllimport) ComputeCrc16(const void * i_pData, size_t i_nBytes);

short CPrivateUdpPkt::ComputeCrc() const
{
    const Byte * pByte = reinterpret_cast<const Byte *>(&m_Crc) + sizeof(m_Crc);
    size_t len = &m_aData[DataLen()] - pByte;
    return ComputeCrc16(pByte, len);
}

The called function looks like this:

unsigned short __declspec(dllexport) ComputeCrc16(const void * i_pData, size_t i_unNumBytes)
{
...
}
rene
  • 41,474
  • 78
  • 114
  • 152
JonN
  • 2,498
  • 5
  • 33
  • 49
  • At this **[LINK](http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/7e61a073-c406-43e5-92bd-f4db89a5aefb)** see post on Wednesday, March 25, 2009 8:19 PM. This post is nearly the same issue and the answer was that the General Character Set needed to be Unicode for both projects. The poster said his project wouldn't compile under Unicode but when he set both projects to Multi-Byte it worked. I have same scenario, that is I get errors compiling with Unicode, however in my case I still get the LNK2028 errors with both projects set to Multi-Byte. – JonN Jun 13 '12 at 18:11
  • Heh, that was my answer. No, that's not it. – Hans Passant Jun 13 '12 at 18:27
  • Here is another **[LINK](http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvc/thread/ed2c12b2-30fd-4a42-b86a-4ed0048a9b8b)** where the last post refers to an extra $$F in the mangled name which exactly matches the issue I am seeing. Unfortunately there is no response. – JonN Jun 13 '12 at 18:45
  • I think I understand now. What I have is an unmanaged C++ DLL with exported classes which references an unmanaged C++ static library. I have source for both and each is in its own project. If I now understand correctly I can use the static library __as-is__ compiled as native and convert the DLL that references it to mixed mode by changing the classes I wish to access from C# to managed classes via **ref class**. Is that correct? The site I looked at gave me the false impression that IJW (It Just Works) meant it was going to simply be a recompile with /clr. – JonN Jun 13 '12 at 22:37
  • 1
    StackOverflow site seems to have lost/deleted several posts from me and @Hans Passant. My preceding comment was in response to a lengthy thread with multiple post from each of us. – JonN Jun 13 '12 at 22:42

0 Answers0