Microsoft KB Archive/117869

{|
 * width="100%"|

GetProcAddress Sample Generates C2106 Using C++

 * }

Q117869

-

The information in this article applies to:


 * Microsoft Visual C++, versions 1.0, 1.5, 1.51, 1.52

-

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 query words: kbinf 1.00 1.50

Keywords : kb16bitonly

Issue type :

Technology : kbVCsearch kbAudDeveloper kbvc150 kbvc100 kbVC151 kbVC152