Announcement

Collapse
No announcement yet.

Declaring a DLL within a DLL

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

  • Declaring a DLL within a DLL

    What is the accepted practice for this pls?

    I assume the declaration goes in the LibMain of the 1st DLL?

    FUNCTION LibMain(BYVAL hInstance AS LONG, _
    BYVAL fwdReason AS LONG, _
    BYVAL lpvReserved AS LONG) EXPORT AS LONG
    SELECT CASE fwdReason
    CASE %DLL_PROCESS_ATTACH
    DECLARE FUNCTION Stepper LIB "Stepper.Dll" (BYVAL StopHere AS DWORD, _
    BYVAL Current AS SINGLE, _
    BYVAL LastBar AS DWORD, _
    BYVAL ToTBars AS SINGLE, _
    SendStr AS ASCIIZ PTR ) AS SINGLE
    END SELECT
    END FUNCTION

    ------------------
    Kind Regards
    Mike

  • #2
    Mike,

    there is no problem calling one DLL from another but you must not
    put the DECLARE in the executable code, put it before the LibMain
    so it is loaded as the other DLL loads.

    Regards,

    [email protected]


    ------------------
    hutch at movsd dot com
    The MASM Forum

    www.masm32.com

    Comment


    • #3
      Just to extend Steve's answer slightly... DECLARE is a scanned statement, not an executed statement.

      That is, it is used by the compiler during the compilation process, not at run-time. This is why it should be placed outside of executable code wrappers (SUB/FUNCTION/CALLBACK/etc), typically at the top of the source code before the first piece of executable code.


      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        > put it before the LibMain so it is loaded as
        > the other DLL loads.

        To clarify, the location of a DECLARE in your source code does not affect when the DLL is loaded. You could sprinkle your DECLAREs throughout your source code, and as long as you DECLARE each function before you use it, it would have exactly the same effect: when a DLL is first loaded, all other DLLs that are DECLAREd (and that contain functions that are used by the DLL) are loaded.

        I don't believe that the order in which the DECLAREs appear in the source code is important either. Windows will load them according to its own rules.

        That said, most people do put all of their DECLAREs at the top of their program, or in an #INCLUDE file at the top, because it makes them easy to find and change. It also makes sure that you won't have to move a DECLARE if you use the function "above" the declaration.

        -- Eric



        ------------------
        Perfect Sync Development Tools
        Perfect Sync Web Site
        Contact Us: mailto:[email protected][email protected]</A>
        "Not my circus, not my monkeys."

        Comment

        Working...
        X