Results 1 to 3 of 3

Thread: need help for compiling these calc_methods

  1. #1

    need nor more help for compiling these calc_methods

    many thanks for trying to help eros.

    re-organized the problem and show result with solution !

    a) "calculatorDLL.bas":
    #COMPILE DLL
    #DIM ALL
    
    %USEMACROS = 1
    #INCLUDE "Win32API.inc"
    #INCLUDE "CalculatorDLL.Inc
    
    GLOBAL ghInstance AS DWORD
    
    CLASS cTestCalculator AS COM 
       INTERFACE ImyTestCalculator : INHERIT IUNKNOWN
    
          METHOD tAdd (BYVAL ta AS INTEGER, BYVAL tb AS INTEGER, BYREF tc AS LONG)
              tc = ta + tb
          END METHOD
    
          METHOD tSub (BYVAL ta AS INTEGER, BYVAL tb AS INTEGER, BYREF tc AS LONG)
              tc = ta - tb
          END METHOD
    
          METHOD tMul (BYVAL ta AS INTEGER, BYVAL tb AS INTEGER, BYREF tc AS LONG)
              tc = ta * tb
          END METHOD
    
          METHOD tDiv (BYVAL ta AS INTEGER, BYVAL tb AS INTEGER, BYREF tc AS LONG) AS LONG
             IF tb <> 0 THEN
                tc = ta / tb
                METHOD = %S_OK
             ELSE
                METHOD = %E_FAIL
             END IF
          END METHOD
    
       END INTERFACE
    END CLASS
    
    SUB CreateInstance ALIAS "CreateInstance" (myJunk AS ImyTestCalculator) EXPORT
        LOCAL obj AS ImyTestCalculator
        SET obj = CLASS "cTestCalculator"
        IF OBJPTR(obj) <> 0 THEN
            SET myJunk = obj
        END IF
    END SUB
    
    '-------------------------------------------------------------------------------
    ' Main DLL entry point called by Windows...
    '
    FUNCTION LIBMAIN (BYVAL hInstance   AS LONG, _
                      BYVAL fwdReason   AS LONG, _
                      BYVAL lpvReserved AS LONG) AS LONG
    
        SELECT CASE fwdReason
        CASE %DLL_PROCESS_ATTACH
            'Indicates that the DLL is being loaded by another process (a DLL
            'or EXE is loading the DLL).  DLLs can use this opportunity to
            'initialize any instance or global data, such as arrays.
            ghInstance = hInstance
            FUNCTION = 1   'success!
            'FUNCTION = 0   'failure!  This will prevent the EXE from running.
        CASE %DLL_PROCESS_DETACH
            'Indicates that the DLL is being unloaded or detached from the
            'calling application.  DLLs can take this opportunity to clean
            'up all resources for all threads attached and known to the DLL.
    
            FUNCTION = 1   'success!
            'FUNCTION = 0   'failure!
    
        CASE %DLL_THREAD_ATTACH
            'Indicates that the DLL is being loaded by a new thread in the
            'calling application.  DLLs can use this opportunity to
            'initialize any thread local storage (TLS).
            FUNCTION = 1   'success!
            'FUNCTION = 0   'failure!
    
        CASE %DLL_THREAD_DETACH
            'Indicates that the thread is exiting cleanly.  If the DLL has
            'allocated any thread local storage, it should be released.
            FUNCTION = 1   'success!
            'FUNCTION = 0   'failure!
        END SELECT
    END FUNCTION
    

    b) "calculatorDLL.inc":
    #IF NOT %DEF(%CalculatorDLLInc)
    %CalculatorDLLInc = 1
    
    INTERFACE ImyTestCalculator : INHERIT IUNKNOWN
        METHOD tAdd (BYVAL ta AS INTEGER, BYVAL tb AS INTEGER, BYREF tc AS LONG)
        METHOD tSub (BYVAL ta AS INTEGER, BYVAL tb AS INTEGER, BYREF tc AS LONG)
        METHOD tMul (BYVAL ta AS INTEGER, BYVAL tb AS INTEGER, BYREF tc AS LONG)
        METHOD tDiv (BYVAL ta AS INTEGER, BYVAL tb AS INTEGER, BYREF tc AS LONG) AS LONG
    END INTERFACE
    
    #ENDIF
    
    c) "test-myCalculator.bas":
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE "Win32Api.inc"
    #INCLUDE "CalculatorDLL.inc"
    
    DECLARE SUB CreateInstance LIB "CalculatorDLL.dll" ALIAS "CreateInstance" (myJunk AS ImytestCalculator)
    
    FUNCTION PBMAIN () AS LONG
       DIM testC AS ImytestCalculator
       DIM result AS LONG
       CreateInstance testC
       IF OBJPTR(testC) = 0 THEN EXIT FUNCTION
       testC.tAdd(2,3,result)   ' 5 ' result ok :)
       MSGBOX FORMAT$(result)
    END FUNCTION
    

    my uncle frank have sent to me some minutes before solution he got from josé he said there was ... "AS COM" in "cTestCalculator" missing. he tried to help from his job at school too I was very frustrated last night about that little example, but that's a problem to myself not reading enough about methods and classes theme. sorry!

    all correct examples I send as attachement.

    bye, largo
    Attached Files Attached Files
    Last edited by largo_winch; 30-12-2011 at 16:39.

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Hi largo,

    I was replying just now and you have deleted your post

    Anyway, no problem.
    I've found this interesting post at PB forum: http://www.powerbasic.com/support/pb...WCOM+CLSID+LIB
    Check it and I'm sure you will see how to implement your class/interface into a DLL.

    The trick is to use: LET objvar = NEWCOM CLSID ClassID$ LIB DLLPath$
    and use a temporary IDispatch variable as stated by José Roca

    If you will re-post your code we can try together

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Check it and I'm sure you will see how to implement your class/interface into a DLL.

    The trick is to use: LET objvar = NEWCOM CLSID ClassID$ LIB DLLPath$
    and use a temporary IDispatch variable as stated by José Roca
    thank you eros for link and help. I will check these new example too. See my first post with solution from josé's site, there was only .. "AS COM" in cTestCalculator missing.

    addendum:

    The biggest change was assigning NewCom to an IDispatch variable and then assigning it to an IInherited.
    how to use GUID's and implement for this class-method example in my first post this will be another part for next time to study!

    bye, largo
    Last edited by largo_winch; 30-12-2011 at 17:46.

Similar Threads

  1. what's compiling ???
    By Lionheart008 in forum Shout Box Area
    Replies: 11
    Last Post: 05-11-2009, 20:48
  2. XMLVM: Cross compiling byte code languages to AJAX, IPhone, etc.
    By Michael Hartlef in forum Shout Box Area
    Replies: 1
    Last Post: 13-07-2009, 22:49
  3. Compiling in Runtime ---> EVAL+++
    By Charles Pegge in forum O2h Compiler
    Replies: 5
    Last Post: 16-04-2009, 01:42
  4. Compiling
    By Anonymous in forum Shout Box Area
    Replies: 1
    Last Post: 19-01-2006, 20:36

Members who have read this thread: 1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •