Results 1 to 6 of 6

Thread: Call DWord... etc

  1. #1
    Junior Member David's Avatar
    Join Date
    Sep 2013
    Location
    Buenos Aires, Argentina
    Posts
    17
    Rep Power
    9

    Call DWord... etc

    Hi all,

    This code works like a charm into PowerBasic

    #COMPILE DLL "ThinBasic_NeoSDK"
    #INCLUDE "Win32Api.inc"
    #INCLUDE "ThinCore.inc"
    '---------------------------------------------------
    
    GLOBAL nbGetVar     AS DWORD
    GLOBAL nbSetVar     AS DWORD
    GLOBAL nbPlayAction AS DWORD
    GLOBAL nbInterface  AS DWORD
    GLOBAL nbWinHandle  AS DWORD
    GLOBAL zData        AS ASCIIZ * 64
    GLOBAL zz           AS ASCIIZ PTR
    GLOBAL dwData       AS DWORD
    
    '---------------------------------------------------
    
    DECLARE SUB GetVarProcType(BYREF VarName AS ASCIIZ, BYREF Value AS ASCIIZ)
    DECLARE SUB SetVarProcType(BYREF VarName AS ASCIIZ, BYREF Value AS ASCIIZ)
    DECLARE SUB PlayActionProcType(BYREF s AS ASCIIZ)
    DECLARE FUNCTION InterfaceProcType(BYVAL InterfaceID AS LONG, BYREF zData AS ASCIIZ) AS LONG
    DECLARE SUB dllHandlerProcType(BYVAL Reason AS LONG)
    
    '---------------------------------------------------
    
    SUB Exec_NeoSDK_SetVariable(BYVAL Variable$,BYVAL vuelta$)
       CALL DWORD nbSetVar USING SetVarProcType(BYCOPY variable$, BYCOPY vuelta$)
    END SUB
    
    '---------------------------------------------------
    
    SUB Exec_NeoSDK_PlayScript(BYVAL Script$)
        CALL DWORD nbPlayAction USING PlayActionProcType(BYCOPY Script$)
    END SUB
    
    '---------------------------------------------------
    
    FUNCTION Exec_NeoSDK_GetVariable (VarName AS STRING) AS STRING
    LOCAL sName AS ASCIIZ * 40
    LOCAL sptr AS ASCIIZ PTR
    zData = ""
    sName = VarName
    CALL DWORD nbGetVar USING GetVarProcType(BYREF sName, BYREF zData)
    sPtr = VARPTR(zData)
    sName = @@sptr
    FUNCTION = Sname
    END FUNCTION
    
    '---------------------------------------------------
    
    FUNCTION Exec_NeoSDK_GetObjectHandle (sname AS STRING) AS LONG
    LOCAL sptr AS ASCIIZ PTR
    sPtr = VARPTR(sname)
    zData = @sptr
    CALL DWORD nbInterface USING InterfaceProcType (BYVAL 7, BYREF zData)
    zz = VARPTR(zData)
    FUNCTION = VAL(@@zz)
    END FUNCTION
    
    '---------------------------------------------------
    
    FUNCTION Exec_NeoSDK_Get_nbInterface (ID AS LONG, texto AS STRING) AS STRING
    LOCAL sptr AS ASCIIZ PTR
    sPtr = VARPTR(texto)
    zData = @sptr
    CALL DWORD nbInterface USING InterfaceProcType (BYVAL ID, BYREF zData)
    zz = VARPTR(zData)
    FUNCTION = @@zz
    END FUNCTION
    
    '*********************************************************
    ' *****  Following function may not be modificate ********
    '*********************************************************
    SUB nbRegisterScriptProcessor ALIAS "_nbRegisterScriptProcessor@4" (BYVAL PlayActionProc AS DWORD) EXPORT
      '***************************** Do Not MODIFY ********************************
      nbPlayAction = PlayActionProc
      '****************************************************************************
    END SUB
    
    '*********************************************************
    ' *****  Following function may not be modificate ********
    '*********************************************************
    SUB nbRegisterInterfaceAccess ALIAS "_nbRegisterInterfaceAccess@4" (BYVAL InterfaceProc AS DWORD) EXPORT
      '***************************** Do Not MODIFY ********************************
      nbInterface = InterfaceProc
      '****************************************************************************
    END SUB
    
    '----------------------------------------------------------------------------
    FUNCTION LoadLocalSymbols ALIAS "LoadLocalSymbols" (OPTIONAL BYVAL sPath AS STRING) EXPORT AS LONG
    ' This function is automatically called by thinCore whenever this DLL is loaded.
    ' This function MUST be present in every external DLL you want to use
    ' with thinBasic
    ' Use this function to initialize every variable you need and for loading the
    ' new symbol (read Keyword) you have created.
    '----------------------------------------------------------------------------
    thinBasic_LoadSymbol "NeoSDK_PlayScript" ,  %thinBasic_ReturnNone  , CODEPTR(Exec_NeoSDK_PlayScript) , %thinBasic_ForceOverWrite
    thinBasic_LoadSymbol "NeoSDK_SetVariable",  %thinBasic_ReturnNone  , CODEPTR(Exec_NeoSDK_SetVariable), %thinBasic_ForceOverWrite
    thinBasic_LoadSymbol "NeoSDK_GetVariable",  %thinBasic_ReturnString, CODEPTR(Exec_NeoSDK_GetVariable), %thinBasic_ForceOverWrite
    END FUNCTION
    
    '----------------------------------------------------------------------------
    FUNCTION UnLoadLocalSymbols ALIAS "UnLoadLocalSymbols" () EXPORT AS LONG
    ' This function is automatically called by thinCore whenever this DLL is unloaded.
    ' This function CAN be present but it is not necessary. If present, this function
    ' will be executed by thinBasic core when module will be released.
    ' Use this function to perform uninitialize process, if needed.
    '----------------------------------------------------------------------------
       FUNCTION = 0&
    END FUNCTION
    
    
    '*********************************************************
    ' *****  Following function may not be modificate ********
    '*********************************************************
    FUNCTION LIBMAIN(BYVAL hInstance AS DWORD, _
                     BYVAL Reason    AS LONG, _
                     BYVAL Reserved  AS LONG) AS LONG
       SELECT CASE Reason
          CASE %DLL_PROCESS_ATTACH
            FUNCTION = %True
            EXIT FUNCTION
          CASE %DLL_PROCESS_DETACH
            FUNCTION = %True
            EXIT FUNCTION
          CASE %DLL_THREAD_ATTACH
            FUNCTION = %True
            EXIT FUNCTION
          CASE %DLL_THREAD_DETACH
            FUNCTION = %True
            EXIT FUNCTION
        END SELECT 			  
    END FUNCTION
    
    I know the syntax is not thinBasic friendly...

    But problem is in this line:

    CALL DWORD nbPlayAction USING PlayActionProcType(BYCOPY Script$)
    
    Are there any way to migrate this code to thinBasic style ?

    Thanks in advance,
    David

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,083
    Blog Entries
    5
    Rep Power
    725
    Hi David,

    ThinBASIC does have some form of CALL DWORD syntax, but it has one better approach. Let's have a look:

    Step 1: Define the function prototype
    In your case it would be something like this, the same as in PB:
    DECLARE SUB GetVarProcType(BYREF VarName AS ASCIIZ, BYREF Value AS ASCIIZ)
    ...
    
    Step 2: Retrieve the procedure address
    Using GetProcAddress, LoadLibrary, as in PB...

    Step 3: Assign the address to the function prototypes
    The DECLARE SET ADDRESS can do it for you:
    DECLARE SET ADDRESS GetVarProcType, nbGetVar
    
    Step 4: Call that function as any other
    Yes, it is just as simple as:
    GetVarProcType(sName, zData)
    
    Petr
    Last edited by Petr Schreiber; 21-10-2013 at 13:30.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Junior Member David's Avatar
    Join Date
    Sep 2013
    Location
    Buenos Aires, Argentina
    Posts
    17
    Rep Power
    9
    Thanks a bunch Petr,

    After a couple of days plenty of attempts, your suggestions does not work for me...

    But, i found the way to put in work the functions i need use.
    Solution is very simple... now...

    Declare SUB PlayScript Lib "NeoThinBasic.nbp" (BYVAL Script as string)
    Declare SUB SetVariable Lib "NeoThinBasic.nbp" (BYVAL Variable as String, BYVAL sValue as String)
    Declare FUNCTION GetVariable Lib "NeoThinBasic.nbp" (ByRef VarName AS STRING) as String
    Declare FUNCTION GetObjectHandle Lib "NeoThinBasic.nbp" (ByRef sname AS STRING) AS LONG
    
    NeoThinBasic.nbp is the name of the (PowerBasic) plugin that interacts between NeoBook & thinBasic.
    Listed functions are used from NeoBook compatibility.

    Now, the plugin is almost complete.
    Thanks again,

    David

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,083
    Blog Entries
    5
    Rep Power
    725
    Hi David,

    I am happy you find a way around the issue, do you think you have somewhere the code with my suggestion not working? I would like to check - maybe it could indicate I explained it wrong, maybe it could indicate problem in SET ADDRESS.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    Junior Member David's Avatar
    Join Date
    Sep 2013
    Location
    Buenos Aires, Argentina
    Posts
    17
    Rep Power
    9
    Hi Petr,

    Problem was i did a false start, going to a wrong way...
    I suposed If i call the NeoBook connection from thinBasic, i can do the job...
    But, the only way to do the job, is calling the plugin that communicates with neobook.
    Plugin is called from the Neobook program like LoadLibrary does, and preserve the connection while the program is executed.
    Is possible your function and my edited version works, but as the "call dword... etc" are trying to connect directly from a service outside de "bubble" that the plugin creates, obviously never will work really.

    Is pretty confusing, isn't it ?

    Thanks again,
    David

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,083
    Blog Entries
    5
    Rep Power
    725
    Hehe,

    thanks for the explanation


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. call statement
    By TomLebowski in forum thinBasic General
    Replies: 7
    Last Post: 17-08-2010, 21:39
  2. call dll
    By Lionheart008 in forum thinBasic General
    Replies: 6
    Last Post: 30-11-2009, 16:07

Posting Permissions

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