Extension Modules > COM

Couple Api ideas for embedding

<< < (5/14) > >>

dzzie:
I didnt do anything with themeing, I still use classic lol. I think any theme related code would just be in the VB6 GUI portion and is independent of the COM part. I havent tried to compile or test the com.dll as x64 yet but should be ok i think. I am not sure if MS has a x64 version of SAPI.spVoice available but they probably do.

Support:
Here is some screen shots of the COM_VB6_Example.sb program running on XP using VB6 resources.

          








--- Quote ---C:\SB22\sbcom>scriba COM_VB6_Example.sb
GetString returned: Script BASIC
objForm = 1414336
Waiting until user closes form to proceede..
anndddd were done!

C:\SB22\sbcom>

--- End quote ---


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

obj = CreateObject("VB6.Sample")

'Sample function prototypes
' longTest(v As Long)
' intTest(v As Integer)
' ByteTest(v As Byte)
' GetString(prompt As String, title, def) As String
' ShowUI() As Long

if obj = 0 then
print "CreateObject failed!\n"
else
    CallByName(obj, "longTest", VbMethod, 20000)
    CallByName(obj, "intTest", VbMethod, 1000)
    CallByName(obj, "byteTest", VbMethod, 255)
   
    'this one fails silently because its invalid value for byte type..
    CallByName(obj, "byteTest", VbMethod, 256)

    retVal = CallByName(obj, "GetString", VbMethod, "Enter some Text:", "my title", "default value!")
    print "GetString returned: ", retVal, "\n"
   
    'do NOT release objects you dont own..
    objForm = CallByName(obj, "LaunchUI")
    print "objForm = ", objForm, "\n"
   
    for i=0 to 10
        CallByName(objForm, "AddItem", VbMethod, "Hello from script basic! " & i)
    next
   
    print "Waiting until user closes form to proceede..\n"
    CallByName(obj, "BlockUntilFormCloses")
   
    ReleaseObject(obj)
    print "anndddd were done!\n"
   
end if

--- End code ---

FYI The SAPI COM example works fine.

VB6 & XP Themes  - I couldn't get the manifest method to work with your example.

Support:
Dave,

I created a form with a calender control and wanted to see if I could make it work with Script BASIC. Can you post the steps needed to use VB forms with SB?


Verhas:

--- Quote from: dzzie on June 05, 2014, 06:55:35 PM ---One thing I am not sure on is if I want to give script clients live object handles for them to passback
and me use blindly. Its kind of a bad idea. try catch and is null checks can handle some ok, but a random number
passed in could easily lead to memory corruption even if try catch kept execution going for now. Safer would be to
only pass back quasi handles I suppose and then validate them from an internal hash map to real value.

--- End quote ---

You can maintain an array of pointers to objects to pass to the script and pass only the index and use the same array in the extension module. Extension modules access the extension pointer so this is possible to pass one object from the embedding application to the extension module function without any interaction in the BASIC script. Thus the array need not be "global".

Any other solution is more error prone. You could pass the actual pointer and check that the pointer is present in the pointer set, but then the pointer can also be passed to another module, or can be "poked" and memory may corrupt.

I am thrilled how deep you digged into ScriptBasic. There are only a very few men who did that in the past. If you get stuck feel free to write me mail, skype whatever.

dzzie:
I have updated the example dll with a SelectDate function which shows a GUI with the calendar control. It returns a string based date. I have included comments in the source detailing how it works as well.

I was not able to get themes to work either on quick test. I am thinking maybe the manifest must be for the scriba.exe.manifest and then have the script call InitCommonControls api before plugin launch? Not sure exactly how but it should work somehow (although maybe not from a console process?) There are also skinning solutions but they are a mountain of code.

Thanks for the offer Peter I will take you up on that when i get stumped :) C is not my strongest language, but I am finding the source quite agreeable and able to find and follow along through most things!
 
One weakness of the object handle lookup, like in these COM examples, the CallByName function is returning COM object handles themselves which would not be unusable directly without the extra step of calling an int RegisterObject(hObject) from the script after one was received. I suppose not really a weakness, just an extra step required then in name of safety

One other thing that would be nice to add is a way for the GUI to initiate call backs into script basic functions from UI events. Might look into that as well. The exports are available in scriba.exe although they are cdecl. It can be done but requires use of some tricks using asm thunks . natively vb6 only supports stdcall. Doing this from a embedded host would be easier I am sure.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version