realbasic-nug
[Top] [All Lists]

Re: Launching a Program And Passing Parameters

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Launching a Program And Passing Parameters
From: Brian Rathbone <brianrathbone at bellsouth dot net>
Date: Wed, 01 Feb 2006 00:37:06 -0500
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <20060131220844 dot D19C110A6CAA at lists dot realsoftware dot com> <F5B672C8-2E9C-423C-9370-1C9B5012469C at elfdata dot com> <43DFFD0E dot 1020505 at utoronto dot ca> <43E007C0 dot 4000809 at ix dot netcom dot com> <43E0196E dot 7090600 at bellsouth dot net> <43E027A8 dot 4050604 at ix dot netcom dot com>


Barry Traver wrote:

Aha! So you don't make "goodnews.txt" the target file, but "RBNotepad.exe" (or whatever) and then pass along the "goodnews.txt" as a parameter?

Correct

I don't know why, but I somehow was looking at ShellExecute the other way around, but ShellExecute indeed can be used either way. You can use either a document or an application as the target file:

Correct. It *can* work the other way around, but it doesn't *have* to.

 > DIFFERENT QUESTION:  If I wanted to publish a "CD eZine" for the Mac,
how would I approach that? (Of course, there would be no Windows API calls to work with. Are there equivalents on the Mac? I don't yet own a Mac, but I hope that someday....)

Not sure about this one, but on Mac there are toolbox calls and the Carbon Declare Library. Perhaps you should ask this question in a seperate thread, since I doubt it has caught the notice of the Mac saavy list members.


P.S. Do you know of any other sample code available other than what is in Aaron's Windows Functionality Suite?

I have bunches of examples in my personal collection. I usually clean them up and send them to Aaron for inclusion in the Windows Functionality Suite. Since it is open source and free, I figure it's a good central repository for and Win32 API based contributions I want to make to the community.

Here is a specific example of how to open a file with notepad using shellexecute vs createprocess: (Watch out for line wrap)



  #if TargetWin32
    Const SW_SHOWNORMAL = 1
    Const SW_HIDE = 0
    Const SW_MAXIMIZE = 3
    Const SW_MINIMIZED = 6
Declare Sub ShellExecuteA Lib "Shell32" ( hwnd as Integer, operation as CString, file as CString, params as CString, directory as CString, show as Integer )

    dim params as String
    dim f as folderitem
    f = getopenFolderItem("special/any")
    if f <> nil and f.exists then
      ///target path enclosed in qoutes so paths with spaces in name are ok
ShellExecuteA( 0, "open", "notepad.exe", """" + f.absolutePath + """", "", SW_MAXIMIZE )
    end
  #endif



/////////////////////////////////////////////////////////////////////////////////////////


  #if targetWin32 then
Declare Function CreateProcessA Lib "kernel32" (lpApplicationName As integer, lpCommandLine As cString, lpProcessAttributes As integer, lpThreadAttributes As integer, bInheritHandles As integer, dwCreationFlags As integer, lpEnvironment As integer, lpCurrentDirectory As integer, lpStartupInfo As ptr, lpProcessInformation As ptr) As integer

    Const SW_SHOWNORMAL = 1
    Const SW_HIDE = 0
    Const SW_MAXIMIZE = 3
    Const SW_MINIMIZED = 6

    Const NORMAL_PRIORITY_CLASS = &H20

    Dim Ret As integer
    Dim StartInf As memoryblock
    Dim Proc as MemoryBlock
    Dim f as folderitem

    f = getopenFolderItem("special/any")

    if f <> nil and f.exists then

      Startinf = newmemoryBlock(76)
      Startinf.long(44) = 1 /// set flags to use showwindow
      Startinf.long(48) = SW_SHOWNORMAL
      StartInf.long(0) = StartInf.size

      Proc = newmemoryBlock(16)

Ret = CreateProcessA(0,"notepad.exe" + " " + """" + f.absolutePath + """", 0, 0, 1,NORMAL_PRIORITY_CLASS, 0, 0, StartInf, Proc)

    end
  #endif


As you can see, the tricky part is the memoryblocks, which are being used to simulate VB Types. You can look up each type on MSDN, figure out their contents, and then determine the size of the memoryblock needed and the offsets for each member. Not fun stuff, but it gets easier once you get the hang of it.

If you need something more specific, let me know. I also have more heavily documented examples that show the breakdown of the memoryblocks.

hth,

Brian

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>