动态调用MessageBoxA的源代码

'嘿,够简单吧!下面是动态调用MessageBoxA的源代码,上面的步骤被封装到RunDll32函数中,可放到模块(CallAPIbyName.bas)中:  
Sub   t2()
     Dim   s1()   As   Byte,   s2()   As   Byte  
        Const   hWnd   =   0  
        Dim   ret   As   Long  
        s1   =   StrConv("Hello~World",   vbFromUnicode)  
        s2   =   StrConv("VBNote",   vbFromUnicode)  
        ret   =   RunDll32("user32",   "MessageBoxA",   hWnd,   VarPtr(s1(0)),   VarPtr(s2(0)),   0&)
  End   Sub

  Public   Function   RunDll32(LibFileName   As   String,   ProcName   As   String,   ParamArray   Params())   As   Long  
          Dim   hProc   As   Long  
          Dim   hModule   As   Long  
          
          ReDim   m_OpCode(400   +   6   *   UBound(Params))   '保留用来写m_OpCode  
          '读取API库  
          hModule   =   LoadLibrary(ByVal   LibFileName)  
          If   hModule   =   0   Then  
                  MsgBox   "Library读取失败!"  
                  Exit   Function  
          End   If  
          
          '取得函数地址  
          hProc   =   GetProcAddress(hModule,   ByVal   ProcName)  
          If   hProc   =   0   Then  
                MsgBox   "函数读取失败!",   vbCritical  
                FreeLibrary   hModule  
                Exit   Function  
          End   If  
          
          
          '执行Assembly   Code部分  
          RunDll32   =   CallWindowProc(GetCodeStart(hProc,   Params),   0,   1,   2,   3)  
          
          FreeLibrary   hModule   '释放空间  
  End   Function  



文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: VB
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.