Thread: how to get programs to run?

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905

    how to get programs to run?

    Ok, I am developing a scripting engine, as a lot of your probably already know (it was script-and-go, but i changed its name to OpenScript).

    What I am trying to learn how to do is get it so I can have an installer of some sorts (don't need a huge one) or maybe even a bat file that will allow people, when they click on a *.ost file, to run the interpreter program.....

    Case in point: You have a bmp file, your double click on it, most likely, Paint or some other gfx program will pop up

    this is what I want to do, but fill in bmp with ost, and paint with OpenScript

    anyone here know how to edit the registry to do that? and if you do, how?

    thanks in advance

  2. #2
    sockets mad
    Join Date
    Mar 2002
    Posts
    126
    Look in

    HKEY_LOCAL_MACHINE\SOFTWARE\Classes

    There's several keys named with the extension they refer to e.g ".txt". Each of these keys has a default value of REG_SZ type which refers to another key (within the Classes key too) which contains various information that Windows should know about the file type such as the default icon and what actions to display in the popup menu when you right click a file or left click it and the command associated with it.

    For example, a text file of .txt extension has the following keys associated with it:

    HKLM\SOFTWARE\Classes\.txt
    (Default) "txtfile"

    HKLM\SOFTWARE\Classes\txtfile
    (All the information about the file and what to do with it)

    look further down the Classes list in the same key and you will find a key named "txtfile" with all the associated information about a .txt file. the one you are looking for is txtfile\shell\open and the "command" key within it. the key name such as "open" or "print" is the context menu action and the "command" key contains a string with the action to perform. Which in this case is "%SystemRoot%\system32\NOTEPAD.EXE %1" which means call notepad.exe with the filename after it which is the significance of the "%1". Use this and others as an example to create your own. Play around with the other actions once you get it working so you can get it to do things like execute your script from a context menu or bring it up to edit it with another action.

    If you need more help then I'm happy to help.

    -Dan

  3. #3
    sockets mad
    Join Date
    Mar 2002
    Posts
    126
    That's what goes on behind the scenes but there are many other methods which are a lot simpler than editing the registry directly within commercial install software which will set up file associations that you specify at install time. If you don't want to use an installer just for that you could use the info I gave yo to write a small app to do it or even investigate using an inf install file to do it. That's a nice lightweight and efficient method of doing stuff like that.

    -Dan

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    so, how exactly do i edit the registry from a program? I have never even tried before, so you'll have to kinda walk me through best you can

    also, my scripting language runs through an openGL app.....it's not a c++ app. Therefor it uses the
    Code:
    WINAPI WinMain(	HINSTANCE	hInstance,
    					HINSTANCE	hPrevInstance,
    					LPSTR		lpCmdLine,
    					int			nCmdShow)
    code for it to run.....and I saw from sangdrax's submission to the rapid coding contest thing this in his main function:

    -EDIT-
    OK scratch the above, i just found out that lpCmdLine is the file passed to the program..........that's cool
    now i've got to make it so when you double click on a .ost file, it runs the program.....

    Code:
    int main(int argc, char* argv[])
    {
        char* filename = argv[1];
    Now, i'm assuming from that that argv[1] is the filename passed to the exe......

    so how exactly woudl i implement that in to an opengl program?

    thanks for the help
    Last edited by jverkoey; 03-20-2003 at 07:01 PM.

  5. #5
    sockets mad
    Join Date
    Mar 2002
    Posts
    126
    A great tool I found for making small install files which supports installing your own file extensions to the registry is INF-Tool

    http://inner-smile.com/dl_inf.htm

    I wouldn't worry about writing an app to edit the registry directly if you haven't used registry functions before it's not worth it really, just use some sort of install system for your app that supports installing file extensions like the one i suggested which is really light weight.

    ----

    I can see that your next problem you're talking about is how do you get your app to process the command line to find out which file has been selected. You're on exactly the right track.

    If you've got a Win32 GUI app like you have that uses a WinMain entry point function then the lpCmdLine parameter is the one you need to use. If you have Visual Studio installed then just look up the WinMain function and it'll tell you all about it and it's parameters. If you don't have Visual Studio then goto http://msdn.microsoft.com/library and it's all online MSDN is the best source of info you'll ever have. Here's the direct link to what you want

    http://msdn.microsoft.com/library/de...ns/winmain.asp

    (Pasted from MSDN)

    Code:
    int WINAPI WinMain(
      HINSTANCE hInstance,      // handle to current instance
      HINSTANCE hPrevInstance,  // handle to previous instance
      LPSTR lpCmdLine,          // command line
      int nCmdShow              // show state
    );
    lpCmdLine is a string containing the whole command line excluding the program name. So if you executed

    openscript.exe testscript.ost

    lpCmdLine would contain "testscript.ost" which is exactly what you need.

    Hope this helps.

    -Dan

  6. #6
    sockets mad
    Join Date
    Mar 2002
    Posts
    126
    Ok you found that out while I was typing that last post never mind

    If you just want to test it you can create new file associations in Windows by opening up any explorer window such as My Computer and in the Tools menu goto "Folder Options" and it's all in the "File Types" tab.

    But telling someone to add all that info into the File Types tab to make *.ost open with openscript once they've installed your app is just stupid but it's good to just create an association to test your app. That's why you'd need an install creator which supports creating file assocations at install time like the one above or most others, that's just the one i like

    -Dan
    Last edited by codec; 03-20-2003 at 07:14 PM.

  7. #7
    sockets mad
    Join Date
    Mar 2002
    Posts
    126
    Contact me on AIM if you want

    SN: pherik x

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 07-26-2007, 09:55 AM
  2. Visual c++ 2005 express edition to run .c files
    By the_fall_guy in forum C Programming
    Replies: 4
    Last Post: 04-05-2007, 12:33 PM
  3. A few questions on programs and when they can run...
    By Junior89 in forum Windows Programming
    Replies: 2
    Last Post: 04-05-2005, 07:47 PM
  4. Making standalone APP run in background
    By hart in forum Windows Programming
    Replies: 3
    Last Post: 02-27-2005, 11:20 AM
  5. Glut and Dev C++, Programs not Quitting?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-29-2004, 08:43 PM