Loading ...
Sorry, an error occurred while loading the content.

Re: dll call

Expand Messages
  • green8819
    Thanks to whoever wrote this useful code FileDialog Select a file , *.* , FileName$ Print Print Path of file is: ;GetPath$(FileName$) Print Filename is
    Message 1 of 12 , Jun 20, 2013
    • 0 Attachment
      'Thanks to whoever wrote this useful code
      FileDialog "Select a file", "*.*", FileName$
      Print
      Print "Path of file is: ";GetPath$(FileName$)
      Print "Filename is : ";GetFile$(FileName$)
      END
      '-----------------------------------------------
      Function GetFile$(f$)
      fileindex = Len(f$)
      filelength = Len(f$)
      While Mid$(f$, fileindex,1) <> "\"
      fileindex = fileindex-1
      Wend
      GetFile$ = Right$(f$, filelength - fileindex)
      End Function

      Function GetPath$(f$)
      fileindex = Len(f$)
      While Mid$(f$, fileindex,1) <> "\"
      fileindex = fileindex-1
      Wend
      GetPath$ = Left$(f$, fileindex)
      End Function


      --- In libertybasic@yahoogroups.com, "Marc" <mrossi8888@...> wrote:
      >
      > Good Morning,
      > I have been working on this for 2 days now. If anyone can help me I would appreciate it. I can't get the path to the file I am looing for.
      > Marc
      > ' code startNOMAINWIN
      > WindowHeight = 300
      > WindowWidth = 500
      > open "text" for text as #1
      > print #1, "!trapclose [quit]"
      >
      > r = GetModuleHandle(var) ' get module task and filename
      > print#1, "r=";r
      > print #1, "GetModuleHandle=";GetModuleHandle
      > print #1, "var=";var
      > print #1, "File$=";File$
      > print #1, "r=";r
      >
      > z$ = GetModuleFileName$(var, File$)
      > print #1, "z$=";z$
      > print #1, "Task= ";r
      > print #1, "Process= " ; " ";File$
      >
      > wait
      > [quit]
      > close #1
      > end
      >
      >
      >
      >
      >
      >
      >
      > function GetModuleHandle(byref result) ' the numerical task of the process
      >
      > File2$ = "kernel32"
      > calldll #kernel32, "GetModuleHandleA",_
      > File2$ as ptr,_
      > result as ulong
      > GetModuleHandle = result
      > 'print#1, "task=";result
      > end function
      >
      >
      >
      > function GetModuleFileName$(byref result2,byref File2$) ' pass the task and filename
      > File2$ = space$(255) + chr$(0) ' buffer to receive file name
      > Length = len(File2$) ' length of buffer
      > calldll #kernel32, "GetModuleFileNameA",_
      > task as ulong,_
      > File2$ as ptr,_
      > Length as ulong,_
      > result2 as ulong
      >
      >
      > GetModuleFileName$ = File2$
      > end function
      >
      > ' code end
      > Thanks,
      > Marc
      >
    • Stefan Pendl
      ... Here is the not complicated solution. ---code start (watch for line wraps) print ModuleHandle = GetModuleHandle( kernel32.dll ) print ModuleHandle = ;
      Message 2 of 12 , Jun 20, 2013
      • 0 Attachment
        Am 20.06.2013 07:35, schrieb Marc:
        > Good Morning,
        > I have been working on this for 2 days now. If anyone can help me I would appreciate it. I can't get the path to the file I am looing for.

        Here is the not complicated solution.


        '---code start (watch for line wraps)

        print

        ModuleHandle = GetModuleHandle("kernel32.dll")
        print "ModuleHandle = "; ModuleHandle

        print

        FileName$ = GetModuleFileName$(ModuleHandle)
        print "FileName$ = " ; FileName$

        print
        end

        function GetModuleHandle(ModuleName$)
        calldll #kernel32, "GetModuleHandleA" , _
        ModuleName$ as ptr, _
        GetModuleHandle as ulong
        end function

        function GetModuleFileName$(hModule)
        nSize = _MAX_PATH + 1
        lpFilename$ = space$(nSize); CHR$(0)

        calldll #kernel32, "GetModuleFileNameA",_
        hModule as uLong,_
        lpFilename$ as ptr,_
        nSize as uLong,_
        result as uLong

        if result > 0 then GetModuleFileName$ = trim$(lpFilename$)
        end function

        '---code end

        --
        Stefan Pendl
        http://stefanpendl.runbasichosting.com/

        LB 4.04 Pro ... http://www.libertybasic.com/assist.html
        LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe

        LB Community Wiki .............. http://basic.wikispaces.com/
        LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
        LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/

        Books at http://www.lulu.com/ and http://www.amazon.com/
        Alyce Watson ... APIs for Liberty BASIC
        Carl Gundel .... Beginning Programming with Liberty BASIC

        Windows 7 Home Premium 64-bit SP1
        AMD Turion X2 RM-70 2GHz, 4GB RAM
      • Stefan Pendl
        ... Here is the not complicated solution. ---code start (watch for line wraps) print ModuleHandle = GetModuleHandle( kernel32.dll ) print ModuleHandle = ;
        Message 3 of 12 , Jun 20, 2013
        • 0 Attachment
          Am 20.06.2013 07:35, schrieb Marc:
          > Good Morning,
          > I have been working on this for 2 days now. If anyone can help me I would appreciate it. I can't get the path to the file I am looing for.

          Here is the not complicated solution.


          '---code start (watch for line wraps)

          print

          ModuleHandle = GetModuleHandle("kernel32.dll")
          print "ModuleHandle = "; ModuleHandle

          print

          FileName$ = GetModuleFileName$(ModuleHandle)
          print "FileName$ = " ; FileName$

          print
          end

          function GetModuleHandle(ModuleName$)
          calldll #kernel32, "GetModuleHandleA" , _
          ModuleName$ as ptr, _
          GetModuleHandle as ulong
          end function

          function GetModuleFileName$(hModule)
          nSize = _MAX_PATH + 1
          lpFilename$ = space$(nSize); CHR$(0)

          calldll #kernel32, "GetModuleFileNameA",_
          hModule as uLong,_
          lpFilename$ as ptr,_
          nSize as uLong,_
          result as uLong

          if result > 0 then GetModuleFileName$ = trim$(lpFilename$)
          end function

          '---code end

          --
          Stefan Pendl
          http://stefanpendl.runbasichosting.com/

          LB 4.04 Pro ... http://www.libertybasic.com/assist.html
          LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe

          LB Community Wiki .............. http://basic.wikispaces.com/
          LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
          LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/

          Books at http://www.lulu.com/ and http://www.amazon.com/
          Alyce Watson ... APIs for Liberty BASIC
          Carl Gundel .... Beginning Programming with Liberty BASIC

          Windows 7 Home Premium 64-bit SP1
          AMD Turion X2 RM-70 2GHz, 4GB RAM
        • Marc Rossi
          Thanks.  I got it from you before but saved it accidentally to my   USB drive and that erased what you had already done. Thanks again and thanks to Richard
          Message 4 of 12 , Jun 20, 2013
          • 0 Attachment
            Thanks.  I got it from you before but saved it accidentally to my   USB drive and that erased what you had already done.
            Thanks again and thanks to Richard too.
            Marc


            ________________________________
            From: Stefan Pendl <pendl2megabit@...>
            To: libertybasic@yahoogroups.com
            Sent: Thursday, June 20, 2013 2:59 PM
            Subject: Re: [libertybasic] dll call

             

            Am 20.06.2013 07:35, schrieb Marc:
            > Good Morning,
            > I have been working on this for 2 days now. If anyone can help me I would appreciate it. I can't get the path to the file I am looing for.

            Here is the not complicated solution.

            '---code start (watch for line wraps)

            print

            ModuleHandle = GetModuleHandle("kernel32.dll")
            print "ModuleHandle = "; ModuleHandle

            print

            FileName$ = GetModuleFileName$(ModuleHandle)
            print "FileName$ = " ; FileName$

            print
            end

            function GetModuleHandle(ModuleName$)
            calldll #kernel32, "GetModuleHandleA" , _
            ModuleName$ as ptr, _
            GetModuleHandle as ulong
            end function

            function GetModuleFileName$(hModule)
            nSize = _MAX_PATH + 1
            lpFilename$ = space$(nSize); CHR$(0)

            calldll #kernel32, "GetModuleFileNameA",_
            hModule as uLong,_
            lpFilename$ as ptr,_
            nSize as uLong,_
            result as uLong

            if result > 0 then GetModuleFileName$ = trim$(lpFilename$)
            end function

            '---code end

            --
            Stefan Pendl
            http://stefanpendl.runbasichosting.com/

            LB 4.04 Pro ... http://www.libertybasic.com/assist.html
            LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe

            LB Community Wiki .............. http://basic.wikispaces.com/
            LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
            LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/

            Books at http://www.lulu.com/ and http://www.amazon.com/
            Alyce Watson ... APIs for Liberty BASIC
            Carl Gundel .... Beginning Programming with Liberty BASIC

            Windows 7 Home Premium 64-bit SP1
            AMD Turion X2 RM-70 2GHz, 4GB RAM




            [Non-text portions of this message have been removed]
          • Marc Rossi
            Hi, Stefan, I also used the LoadLibay function to find Windows exe s and dll s Thanks, Marc        function LoadLibrary$(byref File$, byref hLib) File$ =
            Message 5 of 12 , Jun 21, 2013
            • 0 Attachment
              Hi, Stefan,
              I also used the LoadLibay function to find Windows exe's and dll's
              Thanks,
              Marc
               
               
                
              function LoadLibrary$(byref File$, byref hLib)
              File$ = "notepad.exe"
              calldll #kernel32, "LoadLibraryA",_
              File$ as ptr,_
              hLib as ulong
              LoadLibrary$ = File$
              end function

              t1$ = LoadLibrary$(z$, 0)
               t$ = LoadLibrary$(z$, r)



              ________________________________
              From: Stefan Pendl <pendl2megabit@...>
              To: libertybasic@yahoogroups.com
              Sent: Thursday, June 20, 2013 2:49 PM
              Subject: Re: [libertybasic] dll call


               

              Am 20.06.2013 07:35, schrieb Marc:
              > Good Morning,
              > I have been working on this for 2 days now. If anyone can help me I would appreciate it. I can't get the path to the file I am looing for.

              Here is the not complicated solution.

              '---code start (watch for line wraps)

              print

              ModuleHandle = GetModuleHandle("kernel32.dll")
              print "ModuleHandle = "; ModuleHandle

              print

              FileName$ = GetModuleFileName$(ModuleHandle)
              print "FileName$ = " ; FileName$

              print
              end

              function GetModuleHandle(ModuleName$)
              calldll #kernel32, "GetModuleHandleA" , _
              ModuleName$ as ptr, _
              GetModuleHandle as ulong
              end function

              function GetModuleFileName$(hModule)
              nSize = _MAX_PATH + 1
              lpFilename$ = space$(nSize); CHR$(0)

              calldll #kernel32, "GetModuleFileNameA",_
              hModule as uLong,_
              lpFilename$ as ptr,_
              nSize as uLong,_
              result as uLong

              if result > 0 then GetModuleFileName$ = trim$(lpFilename$)
              end function

              '---code end

              --
              Stefan Pendl
              http://stefanpendl.runbasichosting.com/

              LB 4.04 Pro ... http://www.libertybasic.com/assist.html
              LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe

              LB Community Wiki .............. http://basic.wikispaces.com/
              LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
              LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/

              Books at http://www.lulu.com/ and http://www.amazon.com/
              Alyce Watson ... APIs for Liberty BASIC
              Carl Gundel .... Beginning Programming with Liberty BASIC

              Windows 7 Home Premium 64-bit SP1
              AMD Turion X2 RM-70 2GHz, 4GB RAM



              [Non-text portions of this message have been removed]
            • Stefan Pendl
              ... Hi Marc, is there any reason, why you are making the wrapper functions so complicated? ---code start (watch for line wraps) hNotepad =
              Message 6 of 12 , Jun 22, 2013
              • 0 Attachment
                Am 22.06.2013 05:51, schrieb Marc Rossi:
                > Hi, Stefan,
                > I also used the LoadLibay function to find Windows exe's and dll's

                Hi Marc,

                is there any reason, why you are making the wrapper functions so
                complicated?

                '---code start (watch for line wraps)

                hNotepad = LoadLibrary("notepad.exe")
                hKernel32 = LoadLibrary("kernerl32.dll")
                end

                FUNCTION LoadLibrary(file$)
                calldll #kernel32, "LoadLibraryA", _
                file$ as ptr, _
                LoadLibrary as long
                END FUNCTION

                '---code end

                --
                Stefan Pendl
                http://stefanpendl.runbasichosting.com/

                LB 4.04 Pro ... http://www.libertybasic.com/assist.html
                LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe

                LB Community Wiki .............. http://basic.wikispaces.com/
                LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
                LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/

                Books at http://www.lulu.com/ and http://www.amazon.com/
                Alyce Watson ... APIs for Liberty BASIC
                Carl Gundel .... Beginning Programming with Liberty BASIC

                Windows 7 Home Premium 64-bit SP1
                AMD Turion X2 RM-70 2GHz, 4GB RAM
              • Marc Rossi
                Stefan, I am just learning the API calls.  I am a beginner to this.  As I get more experienced I will learn to write them easier. Thanks for checking it out,
                Message 7 of 12 , Jun 22, 2013
                • 0 Attachment
                  Stefan,
                  I am just learning the API calls.  I am a beginner to this.  As I get more experienced I will learn to write them easier.
                  Thanks for checking it out,
                  Mar


                  ________________________________
                  From: Stefan Pendl <pendl2megabit@...>
                  To: libertybasic@yahoogroups.com
                  Sent: Saturday, June 22, 2013 10:17 AM
                  Subject: Re: [libertybasic] dll call

                   

                  Am 22.06.2013 05:51, schrieb Marc Rossi:
                  > Hi, Stefan,
                  > I also used the LoadLibay function to find Windows exe's and dll's

                  Hi Marc,

                  is there any reason, why you are making the wrapper functions so
                  complicated?

                  '---code start (watch for line wraps)

                  hNotepad = LoadLibrary("notepad.exe")
                  hKernel32 = LoadLibrary("kernerl32.dll")
                  end

                  FUNCTION LoadLibrary(file$)
                  calldll #kernel32, "LoadLibraryA", _
                  file$ as ptr, _
                  LoadLibrary as long
                  END FUNCTION

                  '---code end

                  --
                  Stefan Pendl
                  http://stefanpendl.runbasichosting.com/

                  LB 4.04 Pro ... http://www.libertybasic.com/assist.html
                  LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe

                  LB Community Wiki .............. http://basic.wikispaces.com/
                  LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
                  LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/

                  Books at http://www.lulu.com/ and http://www.amazon.com/
                  Alyce Watson ... APIs for Liberty BASIC
                  Carl Gundel .... Beginning Programming with Liberty BASIC

                  Windows 7 Home Premium 64-bit SP1
                  AMD Turion X2 RM-70 2GHz, 4GB RAM



                  [Non-text portions of this message have been removed]
                • Stefan Pendl
                  ... 1) start simple no need to use ByRef, since seldom API functions return multiple values that we are interested in 2) determine what needs to be provided as
                  Message 8 of 12 , Jun 22, 2013
                  • 0 Attachment
                    Am 22.06.2013 17:41, schrieb Marc Rossi:
                    > Stefan,
                    > I am just learning the API calls. I am a beginner to this. As I get more experienced I will learn to write them easier.

                    1) start simple
                    no need to use ByRef, since seldom API functions return multiple
                    values that we are interested in

                    2) determine what needs to be provided as a parameter to the wrapper
                    function and what can be hard coded inside the wrapper

                    3) check the examples provided at MSDN, they should give you a good
                    view about what is really needed


                    --
                    Stefan Pendl
                    http://stefanpendl.runbasichosting.com/

                    LB 4.04 Pro ... http://www.libertybasic.com/assist.html
                    LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe

                    LB Community Wiki .............. http://basic.wikispaces.com/
                    LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
                    LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/

                    Books at http://www.lulu.com/ and http://www.amazon.com/
                    Alyce Watson ... APIs for Liberty BASIC
                    Carl Gundel .... Beginning Programming with Liberty BASIC

                    Windows 7 Home Premium 64-bit SP1
                    AMD Turion X2 RM-70 2GHz, 4GB RAM
                  Your message has been successfully submitted and would be delivered to recipients shortly.