论坛首页 编程语言技术论坛

用RUBY调用DLL的方法,如何获得该方法返回的自定义结构的指针?

浏览 3033 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-01-16  
DLL的方法返回一个自定义结构的指针,用Win32API.new如何获得该方法返回结构的属性?
我写了一个描述问题的代码,比文字说得清楚,研究两天没有成功,求助 ^_^

class StructModel
include Reloadable
attr_reader :param
def initialize
@param = ''
end
end

class TestModel
include Reloadable
  require 'Win32API'
def test_fun
fun = Win32API.new('test_dll', 'fun', ['i','i'], 'p')
fun.call(0, 0) #返回字符串 test
end
end

class TestController < ApplicationController
def test
test_model = TestModel.new
test_struct = TestModel.new
test_struct = test_model.test_fun
logger.error(test_struct.param)
end
end

test_dll.dll中fun方法为
MyStruct * fun(int , int) #返回字符串 test

MyStruct结构为
typedef Struct _MyStruct
{
char *param;
} MyStruct;
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics