error C2106: '=' : left operand must be l-value 
Author Message
 error C2106: '=' : left operand must be l-value

Quote:

> The following code

> int (WINAPI *lpfnGetHeaders)(HWND,char*,char*,char*,int);
> HINSTANCE hLibrary;

> hLibrary=OpenServerDLL();  // My own function to open the DLL
> if(hLibrary>HINSTANCE_ERROR)
> {
>         (FARPROC)lpfnGetHeaders=GetProcAddress(hLibrary,"GetHeaders");

>  generates the compiler error

> C2106: '=' : left operand must be l-value

> on the last line using VC++1.52.  If I remove the (FARPROC) then I get
> a type conversion error.  The placing of (FARPROC) before the variable
> name is shown in the help for GetProcAddress and this type of
> instruction compiles in Borland C++ 4.5.

The cast as is is correct ;-) The context in which it used makes it
invalid...

Okay, no magic ;-)

You don't access an lvalue here. The way you should do it is:

  typedef int(*fnptr)(int);
  void *get_func(void);                 /* Whatever weird type it returns ... */

  fnptr myfunc;

  myfunc = (fnptr) get_func;            /* ... but cast it to something useful */

-- glj



Tue, 28 Mar 2000 03:00:00 GMT  
 error C2106: '=' : left operand must be l-value


Quote:

>The following code

>int (WINAPI *lpfnGetHeaders)(HWND,char*,char*,char*,int);

This is probably a syntax error, assuming that WINAPI expands to a type
specifier.

I think you should be asking this in a Windows programming newsgroup since it
doesn't look like standard C.

Quote:
>HINSTANCE hLibrary;

>hLibrary=OpenServerDLL();  // My own function to open the DLL
>if(hLibrary>HINSTANCE_ERROR)
>{
>    (FARPROC)lpfnGetHeaders=GetProcAddress(hLibrary,"GetHeaders");

> generates the compiler error

>C2106: '=' : left operand must be l-value

That is correct. The result of a cast expression is not an lvalue; that is,
it is not an expression which designates an object. What you are doing is
meaningless. Perhaps there needs to be a cast one the right hand side to the
type of lpfnGetHeaders, or

   lpfnGetHeaders = (int (WINAPI *)(HWND, char *, char *, char*, int))
                        GetProcAddress(hLibrary, "GetHeaders");

    /* what a hard to read variable name, incidentally */

You should go to a Windows newsgroup since this non-standard {*filter*}is annoying
to a practitioner of standard C and is off topic for c.l.c.
--



Tue, 28 Mar 2000 03:00:00 GMT  
 error C2106: '=' : left operand must be l-value

The following code

int (WINAPI *lpfnGetHeaders)(HWND,char*,char*,char*,int);
HINSTANCE hLibrary;

hLibrary=OpenServerDLL();  // My own function to open the DLL
if(hLibrary>HINSTANCE_ERROR)
{
        (FARPROC)lpfnGetHeaders=GetProcAddress(hLibrary,"GetHeaders");

 generates the compiler error

C2106: '=' : left operand must be l-value

on the last line using VC++1.52.  If I remove the (FARPROC) then I get
a type conversion error.  The placing of (FARPROC) before the variable
name is shown in the help for GetProcAddress and this type of
instruction compiles in Borland C++ 4.5.

Is this style of casting, standard C and if not how should I cast the
result of GetProcAddess.  If it is standard C why does my VC++1.52
reject it.

Thanks in advance for any help.

--
Steven Walton
Horticulture Research International



Tue, 28 Mar 2000 03:00:00 GMT  
 error C2106: '=' : left operand must be l-value


Quote:
>The following code

>int (WINAPI *lpfnGetHeaders)(HWND,char*,char*,char*,int);
>HINSTANCE hLibrary;

>hLibrary=OpenServerDLL();  // My own function to open the DLL
>if(hLibrary>HINSTANCE_ERROR)
>{
>    (FARPROC)lpfnGetHeaders=GetProcAddress(hLibrary,"GetHeaders");

> generates the compiler error

>C2106: '=' : left operand must be l-value

>on the last line using VC++1.52.  If I remove the (FARPROC) then I get
>a type conversion error.  The placing of (FARPROC) before the variable
>name is shown in the help for GetProcAddress and this type of
>instruction compiles in Borland C++ 4.5.

>Is this style of casting, standard C

NO.  The result of a cast is NOT an lvalue in C and you can't have a
non-lvalue on the LHS of the assignment operator.

Quote:
>and if not how should I cast the result of GetProcAddess.

Cast the value returned by GetProcAddress() to the type of lpfnGetHeaders.
Since I have no clue about GetProcAddress() (it's not a function from the
standard C library) I can't tell if such a cast makes any sense or not.

The easiest way to do the casting is with an auxiliary typedef:

    typedef int (WINAPI *lpfn)(HWND,char*,char*,char*,int);
    lpfn lpfnGetHeaders;
    ...
    lpfnGetHeaders = (lpfn)GetProcAddress(hLibrary,"GetHeaders");

Quote:
>If it is standard C why does my VC++1.52 reject it.

Because a diagnostic is required.

Dan
--
Dan Pop
CERN, IT Division

Mail:  CERN - PPE, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland



Thu, 30 Mar 2000 03:00:00 GMT  
 error C2106: '=' : left operand must be l-value

Quote:

> The following code

> int (WINAPI *lpfnGetHeaders)(HWND,char*,char*,char*,int);
> HINSTANCE hLibrary;

> hLibrary=OpenServerDLL();  // My own function to open the DLL
> if(hLibrary>HINSTANCE_ERROR)
> {
>    (FARPROC)lpfnGetHeaders=GetProcAddress(hLibrary,"GetHeaders");

>  generates the compiler error

> C2106: '=' : left operand must be l-value

> on the last line using VC++1.52.  If I remove the (FARPROC) then I get
> a type conversion error.  The placing of (FARPROC) before the variable
> name is shown in the help for GetProcAddress and this type of
> instruction compiles in Borland C++ 4.5.

> Is this style of casting, standard C and if not how should I cast the
> result of GetProcAddess.  If it is standard C why does my VC++1.52
> reject it.

> Thanks in advance for any help.

> --
> Steven Walton
> Horticulture Research International

Let's follow the old KISS principle:  Keep It Simple, Stupid.

The error message says that you don't have an l-value on the left side of
an assignment.  An l-value is a reference to some actual storage
location, that is, a place in memory where one can actually PUT something.
If I got this right, the type FARPROC is some kind of function--a piece
of program code, not a place in memory where something can be put. Thus,
it's saying that you're trying to assign a value to something that is of
type "function."  That won't work.

Try making your function a pointer to a function.  Change (FARPROC) to
(FARPROC *) and see what happens.

Jeff Mullen

Check out Tsukikage Enterprises:  Computer components, alternative
religious ware and anime at reasonable rates.

http://www.cidcorp.com/~moonlight



Mon, 03 Apr 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Sorting Array Error - left operand must be L-value

2. Huh?? error C2659: '=' : overloaded function as left operand in vc7.1 beta

3. error C2659: '=' : overloaded function as left operand

4. Basic operand question - what is 'Modulus'?

5. error C2105: '++' needs l-value

6. PL/I's leave (Was: Re: Goto Pro's and Con's)

7. Don't understand why I am getting the C2236 error

8. Value, value, who's got the value?

9. gcc 2.7.2 warning: left-hand operand of comma expression has no effect

10. error PRJ0003: Error spawning 'cl.exe'.

11. error C2061: syntax error : identifier 'DBPROPSET'

12. Link error: 'Internal error during ReadSymbolTable'

 

 
Powered by phpBB® Forum Software