Results 1 to 3 of 3

Thread: need help for compiling these calc_methods

Threaded View

Previous Post Previous Post   Next Post Next Post
  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.

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
  •