largo_winch
29-12-2011, 16:22
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
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