Announcement

Collapse
No announcement yet.

Can't get this code run under WinNT

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

  • Can't get this code run under WinNT

    Hi all,
    I've written a little PowerBASIC (I'm using PB5) Program for an Autostart Function on a CD with a Microsoft PowerPoint Presentation. Because of "relative Links" in this Presentation, I must start the PowerPoint Viewer with the full path in the command line.
    My code works fine under Win9x/ME but I can't get it work under WinNT ?!?
    Where's my mistake? (the Visual Basic Code works fine under NT, but not erveryone hast VB Runtime Files)

    Regards,
    Sven
    Code:
    $compile exe "start.exe"
    
    FUNCTION WinMain (BYVAL hInstance AS LONG, BYVAL hPrevInstance AS LONG, lpCmdLine AS ASCIIZ PTR, BYVAL iCmdShow AS LONG) AS LONG
    if len(curdir$) = 3 then
    path$ = curdir$ 
    else
    path$ = curdir$ + "\"
    end if
    x& = shell(path$ & "ppview32.exe " & Chr$(34) & path$ & "salestag 2000.ppt" & Chr$(34))
    END FUNCTION
    
    'This is the Visual BASIC Code:
    '------------------------------
    'Attribute VB_Name = "Module1"
    'Sub Main()
    'Dim apppath As String
    'If Len(App.Path) = 3 Then
    'apppath = App.Path
    'Else
    'apppath = App.Path & "\"
    'End If
    'Dim x As Long
    'x = Shell(apppath & "ppview32.exe " & Chr(34) & apppath & "salestag 2000.ppt" & Chr(34))
    'End Sub
    ------------------


    [This message has been edited by Sven Blumenstein (edited November 30, 2000).]

  • #2
    Since you did not say what happens when you run this under NT, are you sure that the default (current) directory is where PPVIEW32.EXE the file exists?

    ie, you may want to add a DIR$() test to confirm the path.

    Add the following lines before the SHELL call, and see what is happening:

    MSGBOX path$
    MSGBOX DIR$(path$ & "salestag 2000.ppt")

    If this does not help, be sure to tell us *exactly* what fails.

    One last point (and it is a long shot), but Windows itself provides a file called START.EXE so you *may* encounter a conflict caused by your AUTORUN.INF file launching the wrong START.EXE file...?!

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

    Comment


    • #3
      Lance,
      the Problem is that this Prog doesn't start the ppview32.exe. It runs until the shell statment and then -> ERROR. But without any error message. If I implemt an "on error goto errhand" then this catches the error.
      And yes, the ppview32.exe and the ppt file are in the same directory. And, as I already sayed, with the Visual Basic Version it runs fine?!?




      ------------------

      Comment


      • #4
        Hi again,
        I've found a solution :-)

        Here's my new code:

        Code:
        $compile exe "start.exe"
        $include "win32api.inc"
        FUNCTION WinMain (BYVAL hInstance AS LONG, BYVAL hPrevInstance AS LONG, lpCmdLine AS ASCIIZ PTR, BYVAL iCmdShow AS LONG) AS LONG
        if len(curdir$) = 3 then
        path$ = curdir$ 
        else
        path$ = curdir$ + "\"
        end if 
        'old:
        'x& = shell(chr$(34) + path$ + "ppview32.exe" + Chr$(34) + " " + chr$(34) + path$ + "salestag 2000.ppt" + Chr$(34))
        '--------
        'new:
        retval& = ShellExecute(%null, "open", path$ + "ppview32.exe ", chr$(34) + path$ + "salestag 2000.ppt" + Chr$(34), "c:\", %SW_MAXIMIZE)
        END FUNCTION
        The old code couldn't run under WinNT, 'cause the "SHELL" statement calls a DOS Function (I think) and this doesn't work under WinNT/2k.
        With the ShellExecute API you can solve this Problem

        Regards,
        Sven

        ------------------

        Comment


        • #5
          It cannot call a DOS function, since there is no DOS subsystem underneath a Win32 application.

          Internally, SHELL uses ShellExecute()!

          So, what was the actual error code you received? (You can test ERR after the SHELL statement, or use an ON ERROR GOTO trap)

          The difference I see is that your call to ShellExecute() changes the path to a writable drive (default directory parameter is C:\ in your code), whereas your plain SHELL() code leaves the app running from in the CDROM directory. I don't know if this is contributary or not, but may be worth investigating. I don't have NT4 here to test with, sorry.




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

          Comment


          • #6
            I tested both codes on a local folder (c:\temp\autostart\) on a NT Computer. So you can't say, it depends on the "c:\".
            I did some tests and find out, that the Shell() statement doesn't work on NT at all :-(
            You must always use ShellExecute "manually".



            ------------------

            Comment


            • #7
              I recall seeing that a long time ago too, hence I went to ShellExecute to do most of my shelling out...

              I have two functions for doing shell, one waits until completion of the shell the other does shell execute:


              Code:
              Function WaitShell(ByVal CmdLine$, ByVal ShowWind&, ByVal TimeLimit&) Export As Long
                  Local Si As STARTUPINFO
                  Local Pi As PROCESS_INFORMATION
              
                  Si.cb = SizeOf(Si)
                  Si.dwFlags = %STARTF_USESHOWWINDOW
                  Si.wShowWindow = ShowWind&
              
                  If CreateProcess("", _
                                   ByVal StrPtr(CmdLine$), _
                                   ByVal %NULL, _
                                   ByVal %NULL, _
                                   0, _
                                   %NORMAL_PRIORITY_CLASS, _
                                   ByVal %NULL, _
                                   ByVal %NULL, _
                                   Si, _
                                   Pi) Then
              
              
                     Call WaitForInputIdle(pi.hProcess, %INFINITE)
                     If TimeLimit& Then
                        Call WaitForSingleObject(pi.hProcess, TimeLimit&)
                        Call CloseHandle(pi.hProcess)
                        Call CloseHandle(pi.hThread)
                     End If
              
                  End If
              Function = 1
              End Function
              
              '------------------------------------------------------------------------------------------
              Function NoWaitShell(FileSpec As String,wWindowStyle As Long) Export As Long
              '%SW_SHOWNORMAL
              Function = ShellExecute(ByVal %NULL, "open", FileSpec + Chr$(0), ByVal %NULL, ByVal %NULL,wWindowStyle)
              End Function
              ------------------
              Scott
              mailto:[email protected][email protected]</A>
              Scott Turchin
              MCSE, MCP+I
              http://www.tngbbs.com
              ----------------------
              True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

              Comment


              • #8
                SHELL works fine in tests under Windows 98, 2000, and NT4 SP6a, here,
                with the obsolete PB/DLL 5.0 compiler as well as current versions.
                If you can find a case where SHELL fails, please send a brief source
                code example to [email protected]


                ------------------
                Tom Hanlin
                PowerBASIC Staff

                Comment

                Working...
                X