Extension Modules > COM

Couple Api ideas for embedding

<< < (6/14) > >>

dzzie:
For reference the steps are:

1) Create  new ActiveX Dll project in VB6

2) Set project -> project properties -> project name textbox to be name you want. In example we used VB6 this will be used in program id to CreateObject

3) Add a new class and rename it to what you want. In example we used Sample. Make sure its instancing is multiuse (default). The program ID to create an instance of this class would now be CreateObject("VB6.Sample")  (format is libraryname.classname although can also be {clsid})

4) add a public function/sub/property to the class. A public variable will probably also work.

5) to show a form add a form to the project, now decide if you want it to be displayed modally or non-modally. examples for both are show in example.

Non-modal form allows you to manipulate the forms Public members from script basic, then you can use a BlockUtilFormCloses type method to pause script basic execution until the form is closed.

A modal form will block execution until the form is closed on its own, but you will have to do any initilizations of it from the initial function call arguments (such as prompts, titles, default values etc)

6) once the GUI is done it will return a value back to script basic. Callbacks from UI elements such as button clicks to script basic functions is not yet supported.

Support:
Thanks Dave for the update and Peter for helping out.

Take a look at the trial extension module and the myicall function. This shows you how to call SB script functions from the extension module. (my utopia I'm striving for in the IUP ext. module) Charles has already done this in DLLC and in fact doing it multi-threaded with a common shared event handler. IUP isn't thread safe by design but that didn't stop Charles.

I will test the calendar control and let you know how it goes. This is too cool being able to call VB forms and interact with them.

I created a Windows version of scriba called scriabw.exe and sbiup.exe which are consoleless Windows versions with themeing support enabled. Works great with IUP. When I tried them with your stuff, nothing is displayed and doesn't return to the console prompt like it should.  ??? I wonder if you disable alert dialogs the main form may theme. (noticed this problem early on with DYC)



Support:
The MS calender ActiveX example works great!



This is the added code to the above example to show the calender dialog.

--- Code: ---    sDate = CallByName(obj, "SelectDate")
    if len(sDate) = 0 then
    print "User pressed cancel for date selection\n"
    else
    print "Date: ", sDate, "\n"
    end if

--- End code ---

Console output

--- Quote ---C:\SB22\sbcom\sbvb2>scriba COM_VB6_Example.sb
GetString returned: default value!
objForm = 1414640
Waiting until user closes form to proceede..
Date: 16/6/2014
anndddd were done!

C:\SB22\sbcom\sbvb2>

--- End quote ---

dzzie:
ok got the callbacks working. but I had to cache a pSupportTable pointer when entering CallByName, the VB is single threaded and modal blocking..sooo should be safe I think. The following is about as clean as i can see it getting..


--- Code: ---import com.inc

function Button1_Click(arg)
print "Back in script basic Button1_Click arg=", arg, "\n"
Button1_Click = arg + 1
end function

function Button2_Click(arg)
print "Back in script basic Button2_Click arg=", arg, "\n"
Button2_Click = arg * 2
end function

obj = CreateObject("VB6.Sample")

if obj = 0 then
    print "CreateObject failed!\n"
else
    print "obj = ", obj, "\n"
       
    oCollection = CallByName(obj, "CallBackHandlers", VbGet)
    print "oCollection = ", oCollection, "\n"
   
    CallByName(oCollection, "Add", VbMethod, ADDRESS(Button1_Click()), "frmCallBack.cmdOp1_Click" )
    CallByName(oCollection, "Add", VbMethod, ADDRESS(Button2_Click()), "frmCallBack.cmdOp2_Click" )
   
    retVal = CallByName(obj, "LaunchCallBackForm", vbMethod, 21)
    print "LaunchCallBackForm returned ", retVal, "\n"
   
    ReleaseObject(obj)
    print "test complete!\n"
end if

--- End code ---

you will have to change the project -> properties -> C++ -> additional include directories to compile the com.dll on your system.

so the way it works is the script registers which function handler it wants to use for each button event. The event names are actually
arbitrary, its just a format that both the script and the activex control agree on. Then when the button is clicked on in the UI, it will query
the registered handlers for the nodeID for the collection key it uses. Then does the call back passing an int arg.

consider it an experimental design at this point I guess. maybe a different design would be more useful or cleaner but its what I came up with as a first take.

Support:

--- Quote ---you will have to change the project -> properties -> C++ -> additional include directories to compile the com.dll on your system.
--- End quote ---

Are you saying I need to do this to test this callback example or if I'm doing something new?

I only use the console VC compiler and Visual Studio isn't something I'm proficient with. 

Why does it have to be compiled on my XP box? I can match what directory structure you use. Having Script BASIC programmers compiling C++ DLLs to make this work may be over their heads.

Update

I'm guessing it's working (or not). It popped dialogs saying the callbacks weren't registered or something like that..

C:\SB22\sbcom\sbvb3>scriba COM_VB6_CallBack_Example.sb
obj = 1414352
currently unsupported VT return type: 9
oCollection = 0
LaunchCallBackForm returned 21
test complete!

C:\SB22\sbcom\sbvb3>

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version