The information in this article applies to:
SUMMARYWhen porting code that uses GetProcAddress() from C to C++, the C++ compiler for MS-DOS can return the following error message: The error message that is returned with the 32-bit compiler is:
MORE INFORMATIONIn a traditional C application, use GetProcAddress() to obtain the address of a function to be called. Declare a variable of type FARPROC, initialize the pointer with the value returned from GetProcAddress(), and then call the function through a pointer as shown:
When not compiling with STRICT, FARPROC is defined in the WINDOWS.H
file as follows:
When the sample code above is converted to C++, a type-mismatch error
occurs because C and C++ have a fundamental difference in the way they
interpret empty parentheses in function declarations. In C, a function
declared as follows:
declares a function that accepts an unknown number of arguments. In
C++, the same declaration represents a function that accepts no
arguments. In other words, in C++, the statement is equivalent to:
Because of this difference, when a pointer of type FARPROC is used to
call a function with parameters in C, no error occurs. In C++, when
the function being passed to GetProcAddress() has parameters, the
formal/actual-parameter-mismatch error occurs because the function of
type FARPROC is defined as a function that has void parameters rather
than as a function that accepts parameters.
To eliminate the error, define the function pointer as a pointer to a function with the correct number of parameters and then typecast the return value from GetProcAddress() to the appropriate type:
Additional query words: 8.00 8.00c 9.00 9.10
Keywords : kbLangCPP kbVC100 kbVC150 kbVC151 kbVC152 kbVC200 kbVC210 kbVC400 kbVC500 kbVC600 |
Last Reviewed: August 8, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |