Announcement

Collapse
No announcement yet.

Very unusual problem.

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

  • #21
    Tim,

    Yes if you split up the resources into separate DLLs and load them on demand. It means using LoadLibrary(), GetProcAddress() and FreeLibrary() but it is a really efficient way to handle large amounts of data rather than just allocating very large amounts of memory in a single application. The allocation is done by the EXE you create but you get nothing for nothing, it just does it for you.

    To answer your question, FreeLibrary() releases any memory used by the DLL.
    hutch at movsd dot com
    The MASM Forum

    www.masm32.com

    Comment


    • #22
      Are there additional memory clearance statements kinda similar to RESET and ERASE which we can use so that variables used in the DLLs are cleared
      when we exit these DLLs ?
      As noted by Mr. Pringels, you do not "exit" a DLL.

      And unless you have done some fairly unusual things, any variables used by procedures in your DLL are not visible in your main program, so resetting or clearing hardly seems necessary. They really cannot be using "that much" memory.. and if they are you should probably be explicity resetting them in your using procedures prior to exiting those procedures.

      All that said, there are certain calls which produce system objects (e.g GLOBAL string variables , GDI objects created by LoadImage() and the like, COM objects (NEWCOM, ANYCOM) , some others) and unless explicitly reset or closed will remain part of your process, consuming memory until the process ends, at which time the Windows operating system will deallocate them. .
      Michael Mattias
      Tal Systems Inc. (retired)
      Racine WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #23
        To answer your question, FreeLibrary() releases any memory used by the DLL.
        It also causes notifications (DLL_THREAD_DETACH, DLL_PROCESS_DETACH) to be sent to the entry point function of the DLL ("DLLMAIN", "LIBMAIN") and you can perform any required "cleanup" at that time. .
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #24
          Something I did not take enough notice of with the comments for Tim was how you have to call a dynamically linked DLL (the reason why they are called DYNAMIC link libraries). PB does not have a tidy way of calling functions from a DLL dynamically and you are stuck with CALL DWORD notation which is really clunky to code. I personally do DLL calls of this type in assembler as its far faster to code and a lot easier to read but its not a common technique for folks who code in high level basic.

          If anyone is interested, here is how I would do it.
          Code:
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          '                                       compile with pbwin10
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          
              #compile exe "call2.exe"
              #option largemem32
              #include "\basic\include\win32api.inc"
          
              MACRO FUNCTION rvcall4(procedure,arg1,arg2,arg3,arg4)
                MACROTEMP rval
                LOCAL rval as DWORD
                ! push arg4
                ! push arg3
                ! push arg2
                ! push arg1
                ! call procedure
                ! mov rval, eax
              END MACRO = rval
          
              MACRO FUNCTION localstr(quoted_text,bytecount)
                MACROTEMP szstring
                LOCAL szstring as STRINGZ * bytecount
                szstring = quoted_text
              END MACRO = VarPtr(szstring)
          
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          
           FUNCTION PBmain as LONG
          
              LOCAL hLib as DWORD
              LOCAL MyMsgbox as DWORD
              LOCAL rval as DWORD
              LOCAL ptxt as DWORD
              LOCAL pttl as DWORD
          
              hLib = LoadLibrary("tim.dll")
              MyMsgbox = GetProcAddress(hLib,"MyMsgbox")
          
              ptxt = localstr("How D Awl",64)
              pttl = localstr("Title",64)
          
            ' |||||||||||||||||||||||||||||||||||||||||||
          
              rval = rvcall4(MyMsgbox,0,ptxt,pttl,%MB_OK)
          
            ' |||||||||||||||||||||||||||||||||||||||||||
          
              rval = FreeLibrary(hLib)
          
           End FUNCTION
          
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          This is the test DLL.
          Code:
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          '                                       compile with pbwin10
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          
              #COMPILE DLL
          
              GLOBAL DLLinstance as DWORD      ' the DLLs instance handle
          
              #INCLUDE "\basic\include\win32api.inc"
          
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          
          FUNCTION LibMain(BYVAL hInst    as LONG, _
                           BYVAL Reason   as LONG, _
                           BYVAL Reserved as LONG) as LONG
          
              LOCAL RetVal as DWORD
          
              Select Case Reason
                Case %DLL_PROCESS_ATTACH
                  DLLinstance = hInst     ' make DLL instance global
                  RetVal = 1              ' needed so DLL will start
          
              End Select
          
              FUNCTION = RetVal
          
          END FUNCTION
          
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          
          FUNCTION MyMsgbox ALIAS "MyMsgbox"( ByVal hwnd as DWORD, _
                                              ptxt as ASCIIZ, _
                                              titl as ASCIIZ, _
                                              ByVal styl as DWORD _
                                            ) EXPORT as LONG
          
              MessageBox hwnd,ptxt,titl,styl
          
              FUNCTION = 0
          
          END FUNCTION
          
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          hutch at movsd dot com
          The MASM Forum

          www.masm32.com

          Comment


          • #25
            If you have a strong enough stomach, here is how to use the CALL DWORD notation to call a function in a DLL dynamically. The help file is about as clear as mud.
            Code:
            ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            
                #include "\basic\include\win32api.inc"
            
              ' -------------------------------------
              ' Make a prototype for the DLL function
              ' -------------------------------------
                DECLARE FUNCTION MyMBox LIB "tim.dll" ALIAS "MyMsgbox" _
                                 (BYVAL hWnd AS DWORD,lpText AS ASCIIZ, _
                                 lpCaption AS ASCIIZ,BYVAL dwType AS DWORD) AS LONG
            
            ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            
            FUNCTION PBmain as LONG
            
                LOCAL rval as DWORD
                LOCAL hLib as DWORD
                LOCAL MyMsgBox as DWORD
            
                hLib = LoadLibrary("tim.dll")
                MyMsgbox = GetProcAddress(hLib,"MyMsgbox")
            
              ' ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
            
                CALL DWORD MyMsgBox USING MyMBox(0,"How D","Title",%MB_OK) TO rval
            
              ' ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
            
                FreeLibrary hLib
            
            End FUNCTION
            
            ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            hutch at movsd dot com
            The MASM Forum

            www.masm32.com

            Comment


            • #26
              Thanks Steve!

              Comment


              • #27
                Thank you Sir Hutchesson, I learn much from here. Also Thank you to Everyone here.

                Comment

                Working...
                X