Running an application

This is a discussion on Running an application within the C++ Programming forums, part of the General Programming Boards category; Greetings! I keep trying running Excel without success. I tried the ShellExecute, and it didn't run my Excel sheet when ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    105

    Running an application

    Greetings!

    I keep trying running Excel without success.
    I tried the ShellExecute, and it didn't run my Excel sheet when I made my app to an exe file.

    So now I decided to try spawnle. I used the appropriate parameters, and as error checking I use the errno global register.

    My error is: Exec format error
    What does this mean?

    Code:
    int result=spawnle(P_WAIT,fileBuffer,paramBuffer,NULL,NULL);
    FileBuffer contains the path and the name of my excel sheet. I assume that excel is run when running a sheet by default. ParamBuffer contains /p + the path of my app.

    What's the problem? How can I solve it? Maybe any other suggestions?

    Could any of you send me an exe file which DOES run and excel sheet?

    Thanks a lot.

    ByZ
    Han

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    Does this command use the windows defined path?
    I mean I used the syntax you've mentioned, and it still odes not run excel, the file not found error is given.

    I used this syntax:
    Code:
    spawnle(P_WAIT,"excel.exe","excel.exe","mybook.xls","/p",paramBuffer,NULL,NULL);
    Is this okay?

    Han

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>>
    I tried the ShellExecute, and it didn't run my Excel sheet when I made my app to an exe file.
    <<<

    I would investigate this further. You had that working. If it runs in the IDE, there is no real reason why it should not run as an .exe, you give up to quick. You may be seeing an artifact of the location of the various files...

    >>>
    you should put the absolute path to the executable you expect to run
    <<<

    ... for example.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    I would investigate this further. You had that working. If it runs in the IDE, there is no real reason why it should not run as an .exe, you give up to quick. You may be seeing an artifact of the location of the various files...
    Yeah, I've been trying this ShellExecute for a while. But it just simply wasn't running in the exe. The other bad thing is that I cannot find a help to it. I press the F1 on it and I cannot find it. I used it as it was used on this page's FAQ. I use Borland C++ Builder 5.0.

    What does your last sentence mean ?
    "an artifact of the location of the various files" What does this mean?

    ByZ
    Han

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    As I said, when you run something in the IDE, you are running it with a series of directory mappings that you inherit from the IDE. Compile to an .exe and run that, those inherited mappings are no longer there.

    If you still have your working ShellExecute() source, post it, (if it is several files or long files, zip them together and post the .zip. This is the correct way to proceed.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    Okay, I'll post it soon. Till then can you please tell me what global register does the error of ShellExecute change? Because I might try to write an error checking to it and using taht in the exe. Just to see what the problem may be.

    ByZ
    Han

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    See the documentation of GetLastError() and FormatMessage() in the Windows SDK docs. There is source code that creates a message box with the exact error message.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    Where can I access windows SDK documentation?

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    adrianxw:

    Here's the code section. The project is quite big, but I think it's well enough to see the errors, should there be any.

    Code:
    AnsiString tempstring;
     tempstring=frmMunkadir->txtMunkadir->Text + "\\MotiFeldolgozó.xls" ;
     tempint=tempstring.Length();
     fileBuffer=new char[tempint];
     for (int i=0;i<tempint; i++)
         {
          fileBuffer[i]=tempstring[i+1];
         }
     tempstring=frmMunkadir->txtMunkadir->Text;
     tempint=tempstring.Length();
     pathBuffer=new char[tempint];
     for (int i=0;i<tempint; i++)
         {
          pathBuffer[i]=tempstring[i+1];
         }
     tempstring="/p " + frmMunkadir->txtMunkadir->Text;
     tempint=tempstring.Length();
     paramBuffer=new char[tempint];
     for (int i=0;i<tempint; i++)
         {
          paramBuffer[i]=tempstring[i+1];
         }
    
    try
        {  ShellExecute(
            Handle,//HWND_DESKTOP, //Parent window
            "open",       //Operation to perform
            fileBuffer,       //Path to program
            paramBuffer,         //Parameters
            NULL,//pathBuffer,         //Default directory
            SW_MAXIMIZE);     //How to open
        }
     catch(...)
        {
        ShowMessage("Unable to open Excel!");
        }
    This is it. As you see there are some forms, and textboxes. Their path is absolutely okay.

    Please take a look at it.

    Thanks
    Han

  10. #10
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Since I don't have all the files, I cannot compile and run your code in the debugger. You seem to be wanting to open a document file. Your "parameters" is, possibly non NULL, I can't see what is actually in there, but from the help...

    >>> If lpFile specifies a document file, lpParameters should be NULL.

    ... ultimately, this opens the excel sheet from the IDE and by running the .exe, and returns "a number greater than 32" from the help...

    >>> Returns a value greater than 32 if successful

    Code:
    #include <windows.h>
    
    int main()
    {
    
        int Error;
    
        Error = (int) ShellExecute(NULL,
                                   "open",
                                   "C:/adrian/spreadsheets/graph/graph2002.xls",
                                   NULL,
                                   NULL,
                                   SW_SHOWNORMAL);
    
        return 0;
    }
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 09-18-2005, 10:06 PM
  2. Changing focus in an MFC Application
    By rangalo in forum Windows Programming
    Replies: 2
    Last Post: 06-20-2005, 07:21 AM
  3. MFC run application by clicking on file...
    By dug in forum Windows Programming
    Replies: 4
    Last Post: 12-02-2004, 04:33 AM
  4. Windows Application Handles
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 06-15-2002, 06:09 PM
  5. Application running as a process in Win2k?????
    By J_Bravo in forum Windows Programming
    Replies: 8
    Last Post: 05-07-2002, 05:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21