在运行时调用函数 [英] Call function at runtime

查看:87
本文介绍了在运行时调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如何在运行时调用函数,

基于包含函数调用信息的结构:

struct func_to_call {

int function_id; //要调用的函数id

unsigned int nparams; //参数数量

unsigned long *参数; //要传递的参数

}


传递给像这样的函数:


call_function(int id,unsigned int nparams,unsigned long * params)

{

// ???

}


*因为你可以看到函数有不同数量的参数(但是所有

都是ULONG类型)

*函数是从a调用的DLL。

*我应该通过序号来调用call_function吗?

-

young_leaf

Hi,

How to call function at runtime,
based on a struct that contains the information for the function call:
struct func_to_call {
int function_id; // function id to call
unsigned int nparams; // number of parameters
unsigned long* parameter; // the parameter(s) to pass
}

to be passed to some function like this one:

call_function( int id, unsigned int nparams, unsigned long* params )
{
// ???
}

*as you can see functions have different number of parameters ( but all
are of type ULONG )
* function are called from a DLL.
* should i call_function via ordinal number?
--
young_leaf

推荐答案

leaf写道:
如何在运行时调用函数,
基于包含函数调用信息的结构:
struct func_to_call {
int function_id; //要调用的函数id
unsigned int nparams; //参数个数
unsigned long *参数; //要传递的参数
}
要传递给像这样的函数:

call_function(int id,unsigned int nparams,unsigned * *

{
// ???
}
*因为你可以看到函数有不同数量的参数(但所有
都是类型为ULONG)
*函数是从DLL中调用的。
*我应该通过序号来调用call_function吗?
How to call function at runtime,
based on a struct that contains the information for the function call:
struct func_to_call {
int function_id; // function id to call
unsigned int nparams; // number of parameters
unsigned long* parameter; // the parameter(s) to pass
}

to be passed to some function like this one:

call_function( int id, unsigned int nparams, unsigned long* params )
{
// ???
}

*as you can see functions have different number of parameters ( but all
are of type ULONG )
* function are called from a DLL.
* should i call_function via ordinal number?




我认为你需要投资更多时间阅读有关这些东西的信息

被称为口译员。函数调用的机制非常实现和特定于系统,如果你想合理地使用b / b



In在大多数情况下,你创建一个你希望调用的函数地址表,然后将函数地址(指针)与你分配给它的ID分配给你。


V

-

请在邮寄回复时从我的地址中删除资金



I think you need to invest a bit more time at reading about the things
known as "interpreters". Mechanisms for function invocation are very
implementation- and system-specific, if you want to be reasonably
sophisticated.

In most simple cases you create a table of addresses of the functions you
expect to call and then match the function address (pointer) to the ID you
assigned to it.

V
--
Please remove capital As from my address when replying by mail

< br>

leaf写道:


如何在运行时调用函数,
基于包含函数调用信息的结构:
struct func_to_call {
int function_id; //要调用的函数id
unsigned int nparams; //参数个数
unsigned long *参数; //要传递的参数
}
要传递给像这样的函数:

call_function(int id,unsigned int nparams,unsigned * *

{
// ???
}
*因为你可以看到函数有不同数量的参数(但所有
都是类型为ULONG)
*函数是从DLL中调用的。
*我应该通过序号来调用call_function吗?

-
young_leaf
Hi,

How to call function at runtime,
based on a struct that contains the information for the function call:
struct func_to_call {
int function_id; // function id to call
unsigned int nparams; // number of parameters
unsigned long* parameter; // the parameter(s) to pass
}

to be passed to some function like this one:

call_function( int id, unsigned int nparams, unsigned long* params )
{
// ???
}

*as you can see functions have different number of parameters ( but all
are of type ULONG )
* function are called from a DLL.
* should i call_function via ordinal number?
--
young_leaf



为什么不使用STL向量作为参数,使用数组

或函数指针的STL映射。我已经使用过这样的方法而没有很多困难,(好吧我很讨厌C ++),所以我建议你学习一下

STL向量和函数指针。


JB



Why not just use an STL vector for the parameters and either an array
or STL map of function pointers. I''ve used methods like this without
much difficulty, (OK I''m geeky about C++), so I suggest you learn about
STL vectors and function pointers.

JB


这篇文章:
http://www.drizzle.com/~scottb/gdc/fubi-paper.htm

似乎是我的解决方案,

关于''功能绑定系统''


使用一点点汇编,它调用一个带有可变参数的函数i

想想,

这里是代码片段:


DWORD Call_cdecl (const void * args,size_t sz,DWORD func)

{

DWORD rc; //这里是我们的回报价值......

__asm

{

mov ecx,sz //得到缓冲区大小

mov esi,args // get buffer

sub esp,ecx //分配堆栈空间

mov edi,esp //目标堆栈帧的开始

shr ecx,2 // make it dwords

rep movsd //将params复制到真实堆栈

call [func] //调用功能

mov rc,eax //保存返回值

添加esp,sz //恢复堆栈指针

}

返回(rc);

}


*因为你可以看到它几乎是我想要的那个,

需要注意的行是:

调用[func] //调用函数


什么引用将确保该行调用正确的

功能?

从哪里来?


---

young_leaf
this article:
http://www.drizzle.com/~scottb/gdc/fubi-paper.htm

seems to be a solution to me,
its about ''Function Binding System''

using a bit of assembly, it calls a function with variable arguments i
think,
here''s the code snippet:

DWORD Call_cdecl( const void* args, size_t sz, DWORD func )
{
DWORD rc; // here''s our return value...
__asm
{
mov ecx, sz // get size of buffer
mov esi, args // get buffer
sub esp, ecx // allocate stack space
mov edi, esp // start of destination stack frame
shr ecx, 2 // make it dwords
rep movsd // copy params to real stack
call [func] // call the function
mov rc, eax // save the return value
add esp, sz // restore the stack pointer
}
return ( rc );
}

*as you can see its pretty much the one that i need i think,
the line that needs attention is this:
call [func] // call the function

what reference will ensure that that line would call the right
function?
from where?

---
young_leaf


这篇关于在运行时调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆