Главная страница | назад





Article #21494: How do I get rid of the unresolved external to SetPortA when using Socket components?

Question:

How do I work around the linker error I sometimes get when using TClientSocket or TServerSocket and try to set the port at runtime?
Answer:

This error comes up because in the file winspool.h (automatically included by windows.h), there is an identical function called SetPortA relating to the printer port. This function is compiled before the socket function, so you get the error.

Possible Fix:
In winspool.h, the following appears:
BOOL WINAPI SetPortA(
IN LPSTR pName,
IN LPSTR pPortName,
IN DWORD dwLevel,
IN LPBYTE pPortInfo
);
BOOL WINAPI SetPortW(
IN LPWSTR pName,
IN LPWSTR pPortName,
IN DWORD dwLevel,
IN LPBYTE pPortInfo
);
#ifdef UNICODE
#define SetPort SetPortW
#else
#define SetPort SetPortA
#endif // !UNICODE
In order to remove the unresolved external, add the following:
#ifndef DONT_USE_WINSPOOL_SETPORTA
BOOL WINAPI SetPortA(
IN LPSTR pName,
IN LPSTR pPortName,
IN DWORD dwLevel,
IN LPBYTE pPortInfo
);
BOOL WINAPI SetPortW(
IN LPWSTR pName,
IN LPWSTR pPortName,
IN DWORD dwLevel,
IN LPBYTE pPortInfo
);
#ifdef UNICODE
#define SetPort SetPortW
#else
#define SetPort SetPortA
#endif // !UNICODE
#endif //!DONT_USE_WINSPOOL_SETPORTA
And be sure to add the following to your conditional defines in your project options: DONT_USE_WINSPOOL_SETPORTA

Last Modified: 28-MAR-00