Вы можете сделать Plug-in в виде динамически подгружаемой библиотеки (DLL).
helloworld.cpp
/* How to make plugin for "Advanced Script Host"?
To use:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
Compile: bcc32 -WD helloworld.cpp
Copy: helloworld.dll in your location
*/
#define NONAMELESSUNION
#include <windows.h>
typedef
HRESULT FAR (*LPFUNC)(HWND, VARIANTARG*, VARIANT FAR*, WORD, HRESULT);
BOOL WINAPI DllEntryPoint(HINSTANCE, DWORD fdwReason, LPVOID)
{ // Optionally: The DllEntryPoint function is an optional
// method of entry into a dynamic-link library (DLL).
// If the function is used, it is called by the system
// when processes and threads are initialized and terminated.
switch(fdwReason) {
case DLL_PROCESS_ATTACH:
// MessageBox(NULL, "I am plugin.", "Init", MB_OK);
break;
case DLL_PROCESS_DETACH:
// MessageBox(NULL, "I am plugin.", "Finalize", MB_OK);
break;
};
return TRUE;
};
extern "C" __declspec(dllexport) int __stdcall GetMethodsCount() {
// You must return the count items.
return 1; // One methods must be added
}
HRESULT HelloWorld(HWND, VARIANTARG*, VARIANT FAR*, WORD, HRESULT);
extern "C" __declspec(dllexport) BOOL __stdcall
GetMethod(unsigned uIndex, char FAR* FAR* ppName,
char FAR* FAR* ppMask, LPFUNC FAR* lp)
{
if (uIndex == 0) {
*ppName = "HelloWorld";
// The arguments mask (you can use 'S' - string and 'I' - integer)
// For example: "ISS"
*ppMask = "S";
*lp = HelloWorld;
return TRUE;
};
return FALSE;
};
HRESULT HelloWorld(HWND hwnd, VARIANTARG* pArg, VARIANT FAR* pRes,
WORD word, HRESULT hr) {
if (FAILED(hr)) return hr; // the check arguments mask
// You can check the types call
// DISPATCH_METHOD
// DISPATCH_PROPERTYGET
// DISPATCH_PROPERTYPUT
// DISPATCH_PROPERTYPUTREF
// if (word != DISPATCH_METHOD) return DISP_E_MEMBERNOTFOUND;
// How to get the integer value?
// int i = (int)pArg[0].n1.n2.n3.lVal;
// How to get the string value?
BSTR bstr = pArg[0].n1.n2.n3.bstrVal;
// How to convert bstr to char*?
unsigned uLength = wcslen(bstr);
char *sz = (char *)calloc(uLength + 1, sizeof(char));
WideCharToMultiByte(CP_ACP, 0, bstr, uLength,
sz, uLength, NULL, NULL);
sz[uLength] = '\0';
// How to return the integer value?
pRes->n1.n2.vt = VT_I4;
pRes->n1.n2.n3.lVal = (LONG)MessageBox(hwnd, sz, "Title", MB_OK);
free(sz);
// How to return the string value?
// pRes->n1.n2.vt = VT_BSTR;
// pRes->n1.n2.n3.bstrVal = SysAllocString(L"Hello World!!!");
// If You to use the shell event (callback function)
// You can call event (callback function with one argument)
LONG oneArg = 500;
OLECHAR FAR *pScriptFunction = L"Your_Event";
SendMessage(hwnd, WM_USER + 1, (WPARAM)pScriptFunction,
(LPARAM)oneArg);
return S_OK;
};
Пример использования такой DLL в скрипте:
// JScript syntax plugin.w_js
var id_lib = System.LoadLibrary("C:\\helloworld.dll");
var conn = Plugins.ConnectPluginsLibrary(id_lib);
var text = Window.FormatMessage(conn);
Window.TextOut(1, 50, 50, "id: " + id_lib);
Window.TextOut(1, 50, 70, "connect: " + conn);
Window.TextOut(1, 50, 90, text);
Window.UpdateWindow();
answer=Plugins.HelloWorld("The advanced script host plugin method");
Window.TextOut(1, 50, 110, "answer: " + answer);
Window.UpdateWindow();
function Event_Finalize(code) {
System.FreeLibrary(id_lib);
};
function Your_Event(param) {
Window.MessageBox("Your_Event", "param: " + param, 64);
};
'VBScript syntax plugin.w_vbs
id_lib = System.LoadLibrary("helloworld.dll")
conn = Plugins.ConnectPluginsLibrary(id_lib)
text = Window.FormatMessage(conn)
Window.TextOut 1, 50, 50, "id: " & id_lib
Window.TextOut 1, 50, 70, "connect: " & conn
Window.TextOut 1, 50, 90, text
Window.UpdateWindow
answer=Plugins.HelloWorld("The advanced script host plugin method")
Window.TextOut 1, 50, 110, "answer: " & answer
Window.UpdateWindow
Function Event_Finalize(code)
System.FreeLibrary id_lib
End Function
Function Your_Event(param)
Window.MessageBox "Your_Event", "param: " & param, 64
End Function
содержание
|