GetProcAddress() Sample Generates C2106 Using C++Last reviewed: July 22, 1997Article ID: Q117869 |
1.00 1.50 1.51 1.52
MS-DOS
kbprg
The information in this article applies to:
Error message C2106, "left operand must be l-value", is generated when you compile a C++ application that contains the sample code provided with the printed and online documentation for the Windows API GetProcAddress(). This is to be expected in a C++ application. According to Stroustrup's "The Annotated C++ Reference Manual," section 4.0, "Standard Conversions": "The result of a conversion is an lvalue only if the result is a reference." The C2106 error message is generated on the following line of sample code:
(FARPROC) lpfnTimerCount = GetProcAddress(hinstToolHelp, "TimerCount");where lpfnTimerCount is defined as follows:
BOOL (FAR * lpfnTimerCount) (TIMERINFO FAR*);The error can be eliminated by using a typecast on the right side of the equation instead of on the left side. The following code fragment demonstrates how to cast the function pointer defined in the sample code so that the sample code compiles without error:
lpfnTimerCount = (BOOL (FAR *)(TIMERINFO FAR*))GetProcAddress(hinstToolHelp, "TimerCount"); |
Additional reference words: kbinf 1.00 1.50
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |