调用api方式有以下两种方式:第二种方式我比较明白,第一种方式,我发现(FARPROC & )MsgBox1 = GetProcAddress(hMod, " MessageBoxA " ); 这条语句中,(FARPROC & ) 应该是隐式转换,但是为什么不能(FARPROC )MsgBox1而要
(FARPROC & )MsgBox1 ,到底多了个“&”是什么意思呢? HMODULE hMod = LoadLibrary( " user32.dll " );
  /**/ //////////// /Api调用的方法一 //////////////////////// // 
   int  (__stdcall  * MsgBox1)(HWND ,LPSTR,LPSTR, int );
 (FARPROC & )MsgBox1 = GetProcAddress(hMod, " MessageBoxA " );
  /**/ //////////// /Api调用的方法二 //////////////////////// // 
  typedef  int  (__stdcall  * MSGBOX)(HWND ,LPSTR ,LPSTR ,INT); 
 MSGBOX MsgBox2 = (MSGBOX)GetProcAddress(hMod, " MessageBoxA " );

解决方案 »

  1.   

    看一下FARPROC的定义,再看一下GetProcAddress的返回至就知道了
      

  2.   

    例如:
         int foo(int s)
        {
          cout<<"me"<<endl;
          return 0;
        }
        
        void main()
        {
         int s = 0;
         cout<<&foo<<endl;
         __asm
         {
           mov dword ptr[s],offset[foo];
           call s
         };
         return ;
        }
    就是上面那段意思。
      

  3.   

     int     (__stdcall     *   MsgBox1)(HWND   ,LPSTR,LPSTR,   int   ); 
    定义一个函数指针变量typedef     int     (__stdcall     *   MSGBOX)(HWND   ,LPSTR   ,LPSTR   ,INT);
    定义一个函数指针类型  int     (__stdcall     *   MsgBox1)(HWND   ,LPSTR,LPSTR,   int   ); 
      (FARPROC   &   )MsgBox1   =   GetProcAddress(hMod,   "   MessageBoxA   "   ); 
    第二句也可以是这样:
    MsgBox1   =( int (__stdcall * )(HWND   ,LPSTR,LPSTR,   int   )) GetProcAddress(hMod,   "   MessageBoxA   "   ); 加&是把(FARPROC   &   )MsgBox1表达式作为MsgBox1的引用,
    如果(FARPROC)MsgBox1,则生成一个临时的常量对象,不可以作为被赋值对象