|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
Call the COM Adapter I would like to use C + + UNIX in the Microsoft COM adapter, but there is a problem, there is no change can be solved by invoking the Senate. Rather that the definition is as follows function
Int func0 (void);
Int func1 (int arg1);
Int func2 (int arg1, int arg2);
Int func3 (int arg1, int arg2, arg3 int);
Int func4 (int arg1, int arg2, arg3 int, int arg4);
.
.
.
Int funcN (int arg1, int arg2, arg3 int, int arg4 that. . . , Int argN);
I can realize the function in a dynamic link library, then realized following a gateway function
Int Invoke (char* filename, char*funName that. . . );
Dynamic database function in the transfer function, so how should like to achieve? |
Man stdarg |
Lenovo reply to the message, 2nd Floor The question is how to achieve that part of the function call is not changed to deal with the Senate. |
Calling documents directly in front of the head.
Translation : at the time of writing should link library! |
Man dlopen
Man dlsys
Man dlclose |
I think the question now is how to solve the transfer function, the parameters of how the information is not, nor is it about how to find DLL function from the target, calling it is the first document is definitely not. If you can find this function, I am sure there are local records of the number of parameters, the key is to make procedures. Invoke I can use to achieve this compilation, but I prefer to use C and C + + methods to achieve |
-->
Frankly, I did not understand what you mean. : Oops : |
I would like to achieve is a Invoke function, the function name a successor in function library to find the corresponding function pointer, arising from the changes in the Senate tied to the corresponding function for function call. Calling a function with regard to, I do not know what it is a prototype, but I could have gained access to the transfer function will be a few parameters. Will be deployed for the function, it may be different for each number of parameters. |
-->
If you know the name of the function.
Analysis is also a function of several parameters.
Dlopen Why not? |
Reply to the message floor lenovo Dlopen use of the dynamic loading using dlsym imported under the name of a function pointer, the function will also be able to know with 0, 1 or n parameters, if I can use switch. . . Calling case for function? If significant changes, the solution to a lot of trouble, I think whether or not there is a corresponding handling C and C + +, be able to deal with this situation? |
-->
You have a function pointer.
Chuan put parameters into account, would not directly call,
Witch. . . Case doing? : Roll : |
COM model but is not very difficult, I would like to hear how the landlord intends to move to Microsoft's COM base on Unix |
Or switch case bars. What is the unity of thought Formal Methods said.
If performance allows can always call in the form of the function according to most parameters.
[code]
Struct argtype{
Int arg1;
Int arg2;
Int arg3;
Int arg4;
};
Va_start (ap, fucName);
Arg = va_arg (ap, struct argtype);
......
Func_ptr (arg);
[/code]
However, this call to ensure that those who retire from the stack, calling the function was in fact do not know how many parameters, just know that there are many parameters to be effective.
|
12th floor hellhell reply to the message If I can solve this question, I COM programming model, I can transplant the UNIX up, but I did not think of how to use the technology, the C and C + + function call, ashamed ah. |
Mingyanguo reply to the message, 13th Floor Drawing into the joints of different ways and function parameters arising from the information was not correct. I started to think about is the use int (*functype) (. . . ), I discovered Stack Implementation Guidelines wrong track, the parameters of which are inconsistent data, not the |
A simple test code looks can FreeBSD6.0 x86, if it is preaching stack parameters should be no problem.
[code]
#include "Stdarg.h>
#include "Stdio.h>
Staticint func1 (int);
Staticint func2 (int, int);
Staticint func3 (int, int, int);
Struct argtype{
Int at_arg1;
Int at_arg2;
Int at_arg3;
};
Typedef int (*func_ptr_t) (struct argtype);
Static int
Invoke (void* ptr,. . . )
{
Va_list ap;
Struct argtype at;
Va_start (ap, ptr);
At = va_arg (ap, struct argtype);
Va_end (ap);
Return ((func_ptr_t) ptr) (at);
}
Static int
Func1 (int arg)
{
Printf ( "%d\n", arg);
Return1;
}
Static int
Func2 (int arg1, int arg2)
{
Printf ( "%d %d\n", arg1, arg2);
Return2;
}
Static int
Func3 (int arg1, int arg2, arg3 int)
{
Printf ( "%d %d %d\n", arg1, arg2, arg3);
Return3;
}
Int
Main (int argc, char* argv[])
{
Printf ( "invoke func%d\n" invoke (func1, 1));
Printf ( "invoke func%d\n" invoke (func2, 1, 2));
Printf ( "invoke func%d\n" invoke (func3, 1, 2, 3));
Return0;
}
[/code]
PS. This brings 啊~~
|
16th Floor mingyanguo reply to the message Certainly not the way ah, I mean there may be more than n-ah |
Wenlek reply to the 17th floor of the message If a variable number of parameters to realize just want to transfer, then we can look at Microsoft's Creole Automation.
First, it defines a generic type of VARIANT variable types.
[code]
Typedef struct tagVARIANT
{
VARTYPE actual types vt; 4003rd
Unsigned short wReserved1; 4003rd reservations
Unsigned short wReserved2;
Unsigne short wReserved3;
4003rd actual data storage
Union
{
4003rd value types
Short iVal;
Long lVal;
Byte bVal;
....
IUnknown* punkVal;
IDispatch* pdispVal;
SAFEARRAY* parray;
4003rd quoted types
Short* piVal;
};
};
Such a definition of the parameters of a generic type of transmission. SAFEARRAY definition of which types of variable number of parameters can be used to transfer
Typedef struct tagSAFEARRAY
{
USHORT cDims;
USHORT fFeatures;
ULONG cbElements;
ULONG cLocks;
PVOID pvData;
SAFEARRAYBOUND rgsbound[]
};
Consider the creation of a preservation VARIANT data type SAFEARRAY array as a parameter transmission.
It can look at the details of the Automation Department, the book stresses com, inside Creole, I remember a few years ago, there are electronic version of msdn.
I do not know if you want to achieve is a process of communication or the communication between processes or mainframe. If the process is the only way wanted to use the program on the adapter can be, but the bottom rpc/xdr behind the need to support those efforts or the other charges.
We now have a relatively lightweight distributed middleware called ice, you can www.zeroc.com can see that there are Maweida provide a translation of the manual.
[/code] |
-->
N What is odd? N is a variable? |
Why do not you put those functions directly into a variable parameter function?
#include "Stdarg.h>
Int func (int arg1,. . . ) |
| |