Linking managed code with VC6 dll (IJW) - unresolved external symbol (weird bug??)

S

Sai Kit Tong

I try to utilize an old native code class library for my managed C++
application, and experience a weird problem. I used IJW approach and
included the header file for my native class definition. I compiled my
application. The compiling phase was successful but I had a linker problem
on just one of the many member functions. The member function has following
signature:

class CMyNativeClass
{
public:
....
....

int SetPort(int);

int SetMinLength(int);
....
}



The linker issues the following error message in my managed code:

error LNK2019: unresolved external symbol "__declspec(dllimport) public: int
__thiscall CMyNativeClass::SetPortA(int)"
(__imp_?SetPortA@CMyNativeClass@@QAEHH@Z) referenced in function
_myFunction.

No linker error for other member function call. I perform a dumbin on my
..lib file (included in the linker) and my .dll file. Both have the member
function name:
"?SetPort@CMyNativeClass@@QAEHH@Z"

How did the linker get confused and use the member function name with "A"
attached.

Is this a bug?
 
C

Carl Daniel [VC++ MVP]

Sai said:
I try to utilize an old native code class library for my managed C++
application, and experience a weird problem. I used IJW approach and
included the header file for my native class definition. I compiled my
application. The compiling phase was successful but I had a linker
problem on just one of the many member functions. The member function
has following signature:

class CMyNativeClass
{
public:
...
...

int SetPort(int);

int SetMinLength(int);
...
}



The linker issues the following error message in my managed code:

error LNK2019: unresolved external symbol "__declspec(dllimport)
public: int __thiscall CMyNativeClass::SetPortA(int)"
(__imp_?SetPortA@CMyNativeClass@@QAEHH@Z) referenced in function
_myFunction.

No linker error for other member function call. I perform a dumbin on
my .lib file (included in the linker) and my .dll file. Both have the
member function name:
"?SetPort@CMyNativeClass@@QAEHH@Z"

How did the linker get confused and use the member function name with
"A" attached.

Is this a bug?

Nop, actually it's not. SetPort is a macro, #defined by winspool.h (which
is included by windows.h). The macro defines SetPort as SetPortA or
SetPortW depending on whether UNICODE is defined.

You can just do a #undef SetPort after including Windows.h to suppress that
macro and then the compiler will generate the correct external symbol name
for your SetPort function.

-cd
 
S

Sai Kit Tong

It works!

Thanks.


Carl Daniel said:
Nop, actually it's not. SetPort is a macro, #defined by winspool.h (which
is included by windows.h). The macro defines SetPort as SetPortA or
SetPortW depending on whether UNICODE is defined.

You can just do a #undef SetPort after including Windows.h to suppress that
macro and then the compiler will generate the correct external symbol name
for your SetPort function.

-cd
 

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