#include <windows.h>
#include <stdio.h>
#include "../../basext.h"
Go to the source code of this file.
Data Structures | |
union | T_RESULT |
struct | _DYNAPARM |
struct | _DllLoaded |
struct | _ModuleObject |
Defines | |
#define | DC_MICROSOFT 0x0000 |
#define | DC_BORLAND 0x0001 |
#define | DC_CALL_CDECL 0x0010 |
#define | DC_CALL_STD 0x0020 |
#define | DC_RETVAL_MATH4 0x0100 |
#define | DC_RETVAL_MATH8 0x0200 |
#define | DC_CALL_STD_BO (DC_CALL_STD | DC_BORLAND) |
#define | DC_CALL_STD_MS (DC_CALL_STD | DC_MICROSOFT) |
#define | DC_CALL_STD_M8 (DC_CALL_STD | DC_RETVAL_MATH8) |
#define | DC_FLAG_ARGPTR 0x00000002 |
#define | LibraryLoaded(pszName) F_LibraryLoaded(pSt,ppModuleInternal,pszName) |
Typedefs | |
typedef _DYNAPARM | DYNAPARM |
typedef _DllLoaded | DllLoaded |
typedef _DllLoaded * | pDllLoaded |
typedef _ModuleObject | ModuleObject |
typedef _ModuleObject * | pModuleObject |
Functions | |
static DWORD WINAPI | SearchProcAddress (HMODULE hInst, LPSTR szFunction) |
static T_RESULT WINAPI | DynaCall (int Flags, DWORD lpFunction, int nArgs, DYNAPARM Parm[], LPVOID pRet, int nRetSiz) |
besVERSION_NEGOTIATE | return (int) |
if (p=besMODULEPOINTER==NULL) | |
static HMODULE | F_LibraryLoaded (pSupportTable pSt, void **ppModuleInternal, char *pszName) |
besFUNCTION (dyc) | |
if (RetVal=DynaCall(lpFunction==0) | |
Variables | |
return Unknown dyc module | error |
besEND besSUB_START pModuleObject | p |
besMODULEPOINTER = besALLOC(sizeof(ModuleObject)) | |
return | |
lpFunction = (DWORD)SearchProcAddress(hDll,szFunction) | |
return | COMMAND_ERROR_SUCCESS |
besEND SLFST | DYC_SLFST [] |
|
Definition at line 30 of file interface.c. |
|
Definition at line 31 of file interface.c. |
|
Definition at line 32 of file interface.c. Referenced by besFUNCTION(). |
|
Definition at line 36 of file interface.c. |
|
Definition at line 38 of file interface.c. |
|
Definition at line 37 of file interface.c. |
|
Definition at line 40 of file interface.c. Referenced by besFUNCTION(), and DynaCall(). |
|
Definition at line 29 of file interface.c. Referenced by besFUNCTION(). |
|
Definition at line 33 of file interface.c. |
|
Definition at line 34 of file interface.c. |
|
Definition at line 247 of file interface.c. Referenced by besFUNCTION(). |
|
|
|
|
|
|
|
|
|
|
|
=section dyc =H DYC("format", arguments) =verbatim import dyc.bas print dyc::dyc("ms,i,USER32.DLL,MessageBox,PZZL",0,"test message","title",3) =noverbatim This function calls an arbitrary function from an arbitrary dll. The first argument to the function has to be a format string and the rest of the arguments are the arguments for the function to be called. The format string has to specify the calling convention of the function, the return value, the name of the DLL and the function to call and the argument types. These have to be specified one after the other separated by commas. The format string should not contain space. The format string has the following format: T<"Xc,Xr,DllName,FunctionName,Xargs"> where =itemize =item T<Xc> specifies the calling convention =item T<Xr> specifies the return value =item T<DllName> is the name of the DLL =item T<FunctionName> is the name of the function =item T<Xargs> specifies the arguments =noitemize When the function is called the arguments are converted from their BASIC value and the function is called according to the format specification. However note that a misformed format string can cause access violation in the program and thus stopping the process. Therefore it is recommended that you fully debug your code and the way you use this function. It may be a wise idea not to install this module on a server where different programmers can develop their programs and run in shared process n multiple threads. For example a hosted web server running the Eszter SB Application Engine can be stopped by a BASIC program using this external module. In the following I describe the format string specifiers. =itemize =item T<Xc> CALLING CONVENTION =noitemize The calling convention can be one, two or at most three characters. The character T<m> or T<M> means that the code was compiled using Microsoft compiler. This is the default behavour, thus there is no need to specify this. The opposite is T or T meaning that the code was compiled using Borland compiler. The difference between these two compilers is how the return value is passed back to the caller. You should not use both T and T<m> at a time. Actually T<m> will be ignored. The calling convention can also be T<s> or T<S> meaning standard callign convention or T<c> or T<C> meaning language C calling convention. Only one of them is to be used in a function call. If you are callign some function from a Windows system DLL then it is certainly T<s>. If you do not know which to use write a small test program and experiment. The difference between standard and C calling convention is the order of the arguments placed on the stack and also who the responsible is to clean the arguments from the stack (the called function or the calling code). Finally you can specify T<4> or T<8> to specify that the function is returning a four or eight-byte floating point number. Although this is a kind of return value specification, it is stated here, because this affects the calling convention. These values are returned not in a memory place from the function but rather in the co-processor register and function T<dyc> has to know to fetch them from there rather than expection the function to return a four or eight-byte memory chunk. =itemize =item T<Xr> RETURN VALUE =noitemize The return value should be specified using a single character. This can be: T or T T<int>, T<l> or T<L> T<long>, T or T pointer, T<f> or T<F> T<float>, T<d> or T<D> for T<double> or T<v> or T<V> for T<__int64>. The int and long types are converted to a BASIC integer number, which is stored as a long in ScriptBasic. float and double values are returned as real number, which is stored as double in ScriptBasic. A pointer value is converted to long and is returned in an integer value. An T<__int64> value is returned as an 8 byte string copiing the bytes of the original T<__int64> value to the bytes of the BASIC string. =itemize =item T<DllName> =noitemize This parameter has to specify the name of the DLL. This name will be used to load the DLL calling the system function T<LoadLibrary>. This means that the name can but also may not include the full path to the file. In the latter case the system function will search the path for the DLL as specified int he Microsoft provided documentation for the function T<LoadLibrary>. When a function from a certain DLL is called first the module loads the DLL and when the BASIC program finishes and the module is unloaded it unloads all DLLs it loaded. Any DLL by the module will only be loaded once. Whent he module is used in a multi-thread environment the interpreter threads load and unload the DLLs independently. If you do not understand what it means then just ignore this explanation: nothing to worry about. =itemize =item T<FunctionName> =noitemize The name of the function to be called from the certain DLL. If the function is not present in the DLL then the program tries to use the function with the original name with an 'A' appended to it. Many system functions happen to have this format in the Windows librares. =itemize =item T<Xargs> argument types =noitemize This parameter should specify the arguments. It has to have as many character as many arguments there are. Each character should specify exactly one argument and will control how the actual BASIC arguments are converted to their native format. For each argument one of the following characters can be used: =itemize =item T<1> =item T<2> =item T<4> =item T<8> specifies that the argument is an arbitrary 1-, 2-, 4- or 8-byte argument. The BASIC argument should be string value and should have at least as many characters as needed (1, 2, 4 or 8 as specified). It is possible to use undefined, integer or real value for 1-, 2- or 4-byte values. In this case the value will be converted to integer and the bytes of the value will be used as argument. In case of 8-byte argument the BASIC argument is converted to string. =item T<c> specifies that the argument is a single character. If the BASIC argument is a string then the first character of the string is used. If the argument is a real number or an integer number then the value will be used as ASCII code. If the argument is T<undef> or if the string has no characters in it then the value will be zero. =item T<s> specifies that the argument is a short(2-byte) value. The BASIC argument is converted to an integervalue if needed and truncated to two bytes if needed. =item T<f> specifies that the argument is a float value. The BASIC argument is converted to a real value and its precision is decreased from double to float. =item T<h> =item T =item T<l> specifies that the argument is a handle, pointer or long. In these cases the BASIC argument is converted to an integer value if needed. =item T<z> specifies that the argument is a pointer that should point to a zero terminated string. The BASIC argument is converted to string and a pointer to the start of the string is passed as actual argument. Note that BASIC strings are not zero terminated and the function T<dyc> does not append the terminating zero character to the string. Thus you have to append a zero character to the BASIC string before you pass it as zero terminated string. For example: =verbatim import dyc.bas a$ = "message" a$ &= " text" REM Make the string zero character terminated a$ &= chr$(0) print dyc::dyc("ms,i,USER32.DLL,MessageBox,PZZL",0,a$,"title",3) =noverbatim On the other hand you can safely use string constants as argument like in the example above T<"title"> because string constants in ScriptBasic contain an extra zero character following their normal characters. =item T<d> specifies that the argument is a double value. The BASIC argument is converted to a real value if needed, which is stored in BASIC internally as double and is passed to the function. =noitemize Note that this is a wise idea to write a wrapper function in BASIC that gets the arguments performs some checks if needed and calls the module T<dyc> instead of putting the dyc call into the main BASIC code. Definition at line 438 of file interface.c. References besCONVERT2STRING(), besDEREFERENCE(), COMMAND_ERROR_MEMORY_LOW, DC_CALL_STD, DC_FLAG_ARGPTR, DC_MICROSOFT, _DYNAPARM::dwArg, _DYNAPARM::dwFlags, LibraryLoaded, memcpy(), _DYNAPARM::nWidth, _DYNAPARM::pArg, STRINGVALUE(), and STRLEN(). |
|
Definition at line 82 of file interface.c. References DC_FLAG_ARGPTR, i, and _DYNAPARM::nWidth. |
|
Definition at line 248 of file interface.c. References besFREE(), besMODULEPOINTER, _DllLoaded::hDll, _DllLoaded::next, NULL, p, _DllLoaded::pszName, strcpy(), and stricmp(). |
|
Definition at line 667 of file interface.c. |
|
Definition at line 205 of file interface.c. References _DllLoaded::hDll, and _DllLoaded::next. |
|
Definition at line 185 of file interface.c. |
|
Definition at line 63 of file interface.c. References strcpy(). |
|
Definition at line 204 of file interface.c. |
|
Definition at line 696 of file interface.c. |
|
Initial value: { { "versmodu" , versmodu }, { "bootmodu" , bootmodu }, { "finimodu" , finimodu }, { "emsgmodu" , emsgmodu }, { "dyc" , dyc }, { NULL , NULL } } Definition at line 700 of file interface.c. |
|
Definition at line 197 of file interface.c. |
|
Definition at line 666 of file interface.c. |
|
Definition at line 202 of file interface.c. |
|
Definition at line 224 of file interface.c. |