分享

Lua直接调用Dll中的函数

 quasiceo 2014-01-13

LuaRocks is a pure Lua application with no library dependencies. Its current release depends on some helper tools, but you shouldn't worry about them, as they are shipped by default on most Unix systems: LuaRocks requires as a basic Unix toolchain, zip, unzip and either wget (default on most Linux systems) or curl (default on Mac OSX). For Windows, these helper tools are provided by the UnxUtils project; the all-in-one Windows package already includes them, as a convenience.

调用Windows API实例

  1. http://lua./blog/451757
  2. http://www./articles/20090615-459

Sample

    -- http://www./articles/20090615-459
    -- http://blog.csdn.net/kowity/article/details/7256376
    require "alien"

    MessageBox = alien.User32.MessageBoxA
    MessageBox:types{ret = 'long', abi = 'stdcall', 'long', 'string', 'string', 'long' }
    MessageBox(0, "itle for test","LUA call windows api", 0)

    ---------------------------------------------------------------

    local ExpandEnvironmentStrings = alien.Kernel32.ExpandEnvironmentStringsA
    ExpandEnvironmentStrings:types{ ret = "long", abi = 'stdcall', "string", "pointer", "long" }

    local buffer = alien.buffer(512)
    ExpandEnvironmentStrings("%USERPROFILE%", buffer, 512)
    print(tostring(buffer))

    ---------------------------------------------------------------

    EnumWindows = alien.user32.EnumWindows
    EnumWindows:types {"callback", "pointer", abi="stdcall"}

    GetClassName = alien.user32.GetClassNameA
    GetClassName:types {"long", "pointer", "int", abi="stdcall" }

    local buf = alien.buffer(512)

    local function enum_func(hwnd, p)
      GetClassName(hwnd, buf, 511)
      print (hwnd..":"..tostring(buf))
      return 1
    end

    local callback_func = alien.callback(
            enum_func,
            {"int", "pointer", abi="stdcall"})

    EnumWindows(callback_func, nil)

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多