|
-
Jun 21st, 2019, 02:02 PM
#18
Re: Has anyone had any success implementing IDispatch / IDispatchEx?
 Originally Posted by sancarn
Gotta say your vbFriendlyInterfaces dll does indeed look very nice!
That said I'm not sure if you can easily attach methods to your IDispatch implementation without implementing TypeInfo also.
(Although this is untested from me as of right now)
Since Properties are already "Methods" the Implementation of a "true Function" is of course equally possible:
Why not make a fast test with the Demo 7-Code:
At the top of vbIDispatch_GetIDForMemberName add a new, single line:
Code:
Private Function vbIDispatch_GetIDForMemberName(UserData As Long, ByVal pVTable As Long, MemberName As String) As Long
If UCase$(MemberName) = "MYFUNC" Then vbIDispatch_GetIDForMemberName = 10000: Exit Function
...
At the top of vbIDispatch_Invoke add a new, single line:
Code:
Private Function vbIDispatch_Invoke(UserData As Long, ByVal pVTable As Long, ByVal DispID As Long, ByVal CallType As VbCallType, VResult As Variant, ParamArray P() As Variant) As vbInterfaces.HRESULT
If DispID = 10000 Then VResult = Join(P, "_"): Exit Function 'MyFunc Joins all passed Params with an UnderScore-Char
...
And that's it... "MyFunc" was successfully implemented (without any extra TypeInfos).
You can test it in the Form within the With-Block by doing:
Debug.Print .MyFunc("abc", 1, 2, 3, "xyz") '<-- returns and Prints out: abc_1_2_3_xyz
 Originally Posted by sancarn
Regardless, in my particular use case, I want to (as and where possible) steer away from using any external DLLs, (easier distribution). I'm also trying to steer away from ScriptControl specifically who's VBScript evaluation is actually disabled on most computers I have used, and whos JScript is unlikely to be supported forever either.
Did you really deactivate VBScript on your Computer(s)?
If yes, how did you do that - and why did you leave JScript alone in that case? 
Im asking, because a "deactivated VBScript" usually leaves the vbscript.dll untouched in the System32 or SysWOW64 folders
(if you remove them, there's a good chance MS will re-install them on the next system-update or system-check).
And I've mentioned IActiveScript in my first post, because when you implement these Scripting-interfaces by hand,
you will not need the MS-ScriptControl - but only an installed vbsript.dll or jscript.dll in the SysFolder.
I still consider that solution the most promising one for your case, because when you think about it:
- dynamic properties are easy also with other methods (e.g. via vbFriendlyInterfaces.dll)
- but for "true dynamic functions" which do a bit more than "single-line math-ops or concats" to produce a result,
.. you'll need either a dynamic compiler, or an interpreter ... period.
- the Scripting-stuff is also interesting because it comes in both: 32Bit- and a 64Bit implementations (preinstalled on the system)
- also - you're not restricted to VBScript - the jscript.dll can provide basically the same stuff I've demonstrated with VbScript in my example
Olaf
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|