Theos PowerBasic Museum 2017

Webmaster: José Roca (PBWIN 10+/PBCC 6+) (SDK Forum) => COM Programming => Topic started by: James McCormick on August 25, 2014, 04:38:47 PM

Title: Create an Api pointer from a vbscript getref function object
Post by: James McCormick on August 25, 2014, 04:38:47 PM
From an object reference "set var=getref("Sub/Function")" from vbscript.
I want to convert this (var) to a pointer so I can use it in a call to the Api.
I know PB's OBJPTR(var) is not the pointer to the vbscript Sub/Function.
I am not sure were to go from here. If someone can direct me on how
to do this I would be greatful.

thank James
Title: Re: Create an Api pointer from a vbscript getref function object
Post by: Mike Stefanik on August 27, 2014, 08:21:24 PM
GetRef is generally used to return a callback object to an event handler within VBScript. Unless you're trying to implement Active Scripting hosting in your application, I'm not clear on what it is you're exactly trying to accomplish. That said, if you're tying to get code pointer to a VBScript sub or function that you can just call through in native code, that's not possible.

Edit: If you're wanting to execute a script function within your application, then you'd need to use the IActiveScript COM APIs to setup the scripting interface, parse the script itself and then execute it. I've seen code that does that sort of thing in Visual C++ using ATL; I suspect that implementing it in PowerBASIC would be a lot more involved.
Title: Re: Create an Api pointer from a vbscript getref function object
Post by: José Roca on August 28, 2014, 04:56:22 AM
I have an example

Hosting VBScript in your PowerBASIC application

http://www.jose.it-berater.org/smfforum/index.php?topic=4383.msg15308#msg15308

In fact, with the PowerBASIC low-level COM support, it is somewhat less involved that with C++.

But I have no idea of what James wants to do.

Title: Re: Create an Api pointer from a vbscript getref function object
Post by: James McCormick on September 01, 2014, 04:07:39 PM
The easy way to explain is I'am trying to create the same thing as "DynamicWrapperX" does in "RegisterCallback".
This is what he says about it.

Quote
This method takes a reference to a script function and transforms it into a pointer that can be passed to an API function. Then that API function can use this pointer to call the script function. EnumWindows, for example, requires such a pointer to a callback procedure for its work (see the code below). For each window that it finds, it calls the callback procedure, passing it the window handle. Then if the callback procedure returns 1, enumeration continues, and if 0, it stops.

A script function reference by itself cannot serve this purpose because functions in JScript and VBScript are objects and their references are pointers to IDispatch interfaces. So the reference is passed to RegisterCallback, and the API function receives a pointer to one of the intermediary procedures inside dynwrapx.dll, which will translate calls to the script function and transfer its return values back to the API function.

In JScript the name of a function (without parentheses) will serve as its reference, and in VBScript you will have to use GetRef beforehand. In addition to the function's reference, you may have to specify the types of its parameters (if any) and its return value — just as with the Register method (but only small letters can be used).

I hope this explains what I want to do.
And thanks for your feedback.
James