Announcement

Collapse
No announcement yet.

First Real Code Example??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • First Real Code Example??

    http://www.powerbasic.com/support/pb...078#post293078

    James

  • #2
    Thanks for the code,

    would it be possible to add EXE of Server as well, ZIP contains just Client executable and I have no PB9 yet ( hopefully this state wont take long ).


    Petr
    [email protected]

    Comment


    • #3
      Sorry about that. Should all be there now.

      James

      Comment


      • #4
        Thank you,

        worked well for me.


        Petr
        [email protected]

        Comment


        • #5
          Good example... and the beggining of MANY more!!!.

          Comment


          • #6
            A good thing is that you can wrap up your dll into an easier to use (dispatch based) com server.
            As long you are using automation, annoying declarations are bye bye.
            The common API code Bob Zale showed us a week ago makes it also easy to load the ocx with the registering.

            So far speculation, i don't have this compiler yet.
            hellobasic

            Comment


            • #7
              I am confused about the word automation but i mean:
              INHERIT IDispatch

              hellobasic

              Comment


              • #8
                Edwin
                Yes you can do that but it will run much slower than a DLL if you use the dispatch interface.
                John

                Comment


                • #9
                  That depends if you call a dispatch member multiple times or have extensive code in the method.

                  For 99% you'll have lengthy task over repeatedly calling a function/method
                  hellobasic

                  Comment


                  • #10
                    True it all depends how much you use classes and the dispatch interface. I have to deal with MS awarded programs where even the simplest function in the program is in a class and called via the dispatch interface. Could do some of the calculations quicker with pen and paper , though they don’t work too bad on dual quad core processors with 16 GB RAM.
                    Really a matter of common sense and a trade off in programming time versus uses speed.

                    Comment


                    • #11
                      Imo one of the biggest mistakes programmers make (assumption due the fact their software is slow) is they tend not to understand commands like for/each.

                      If you have an collection (~array) of objects often a simple for next loop is used.
                      I see my colleagues still do that.
                      On every loop it needs to create or obtain that object.
                      In practise by making use of the IEnumerator interface and write the correct code you'll create all objects at once.
                      The loop itself is then very fast.

                      This can be a 1000 times faster.. really!
                      So if i call a dispatch object and 'pop-eye' keeps creating objects on objects internally i am sure it get's slow.

                      Calling a dispatch once and do the heavy stuff inside a method is equally fast as an ordinary call.
                      If you call via a dispatch a 1000th times like in a loop.. yes, not recommended.
                      Only direct vtable access (direct interface) will help you here.

                      To be clear.. for/each suppose to call the IEnumerator interface.. if present.
                      Hopefully the PB interface stuff will let us do that.
                      Maybe not the for/each but at least this IEnumerator interface.
                      Oh well. if not you can still do that with an ordinary method.
                      But then compatibility is gone somewhat.
                      hellobasic

                      Comment


                      • #12
                        To be clear.. for/each suppose to call the IEnumerator interface.. if present.
                        Hopefully the PB interface stuff will let us do that.
                        Maybe not the for/each but at least this IEnumerator interface.
                        There is not For...Each, but it is quite simple to emulate it:

                        Code:
                        DIM pEnum AS IEnumVARIANT
                        DIM oItem AS DISPATCH   ' or pItem AS <interface name>
                        DIM vItem AS VARIANT
                        
                        ' Get a reference to the enumeator
                        pEnum = <pCollection>.NewEnum_
                        ' Where <pCollection> will be an object variable holding a reference to the collection to enumerate
                        
                        DO
                           ' Retrieve a reference to the next object in the collection
                           hr = pEnum.Next(1, vItem, BYVAL %NULL)
                           IF hr <> %S_OK THEN EXIT DO
                           ' Assign the VT_DISPATCH variant to the object variable
                           oItem = vItem   ' or pItem = vItem
                           ' Do some calls
                           OBJECT CALL oItem.<wathever>   ' or pItem.<whatever>
                        LOOP
                        The first parameter of pEnum.Next can be higher, and the second parameter can be an array.

                        And instead of wrapper functions for the IEnumVARIANT interface, youn only need the following interface declaration:

                        Code:
                        ' ########################################################################################
                        ' IEnumVARIANT interface
                        ' IID = 00000002-0000-0000-C000-000000000046
                        ' Inherited interface = IUnknown
                        ' ########################################################################################
                        
                        #IF NOT %DEF(%IEnumVARIANT_INTERFACE_DEFINED)
                            %IEnumVARIANT_INTERFACE_DEFINED = 1
                        
                        $IID_IEnumVARIANT = GUID$("{00020404-0000-0000-C000-000000000046}")
                        
                        INTERFACE IEnumVARIANT $IID_IEnumVARIANT
                        
                           INHERIT IUnknown
                        
                           ' =====================================================================================
                           METHOD Next ( _                            ' VTable offset = 12
                             BYVAL DWORD _                            ' /* [in] */ unsigned long celt
                           , BYREF VARIANT _                          ' /* [out] */ VARIANT FAR* rgVar
                           , BYREF DWORD _                            ' /* [out] */ unsigned long FAR* pCeltFetched
                           ) AS LONG                                  ' HRESULT
                           ' =====================================================================================
                           METHOD Skip ( _                            ' VTable offset = 16
                             BYVAL DWORD _                            ' /* [in] */ unsigned long celt
                           ) AS LONG                                  ' HRESULT
                           ' =====================================================================================
                           METHOD Reset ( _                           ' VTable offset = 20
                           ) AS LONG                                  ' HRESULT
                           ' =====================================================================================
                           METHOD Clone ( _                           ' VTable offset = 24
                             BYREF IEnumVARIANT _                     ' /* [out] */ IEnumVARIANT** ppenum
                           ) AS LONG                                  ' HRESULT
                           ' =====================================================================================
                        
                        END INTERFACE
                        
                        #ENDIF   ' /* __IEnumVARIANT_INTERFACE_DEFINED__ */
                        Last edited by José Roca; 13 Aug 2008, 10:03 PM.
                        Forum: http://www.jose.it-berater.org/smfforum/index.php

                        Comment

                        Working...
                        X