CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2011
    Posts
    7

    trouble with Irfanview command line option

    I have a program that is looped, and in the loop it takes in user input to determine which image to open with Irfanview. My problem is that when I open the program with Irfanview, my program halts until I close that image that Irfanview opened up. The user input is based on facial features constantly taken in from a webcam, so it isn't a keyboard not being on the correct window issue. When the image is closed, the program starts again as usual, until another image is opened, whereupon it halts again.

    Anyone have any idea?

    Also, I should add that my program runs just fine if I exit the window of my program and open Irfanview and load an image manually. It only screws up with the command line option

    i_view32.exe c:\blarg.bmp /fs

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: trouble with Irfanview command line option

    Quote Originally Posted by Ragnarok22788 View Post
    Also, I should add that my program runs just fine if I exit the window of my program and open Irfanview and load an image manually.
    What do you mean by "manually"? Did you go to the command-line and start IrfanView with the command-line you say doesn't work in your program? Or did you just click on IrfanView and go to "File/Open" or whatever menu option is used to load a file? If you did the latter, then that is not the test you should be doing.

    Secondly, are you sure that your program doesn't, for some reason, mess up the command-line being sent to IrfanView, and you're just assuming you're sending a proper command?

    Last, what API call did you use to start IrfanView? If it's a Windows API call, then you need to redirect your question to the Windows API forum, as possibly you are not using the correct functions to start the program.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; June 19th, 2011 at 03:18 PM.

  3. #3
    Join Date
    Apr 2011
    Posts
    7

    Re: trouble with Irfanview command line option

    Quote Originally Posted by Paul McKenzie View Post
    What do you mean by "manually"? Did you go to the command-line and start IrfanView with the command-line you say doesn't work in your program? Or did you just click on IrfanView and go to "File/Open" or whatever menu option is used to load a file? If you did the latter, then that is not the test you should be doing.

    Secondly, are you sure that your program doesn't, for some reason, mess up the command-line being sent to IrfanView, and you're just assuming you're sending a proper command?

    Last, what API call did you use to start IrfanView? If it's a Windows API call, then you need to redirect your question to the Windows API forum, as possibly you are not using the correct functions to start the program.

    Regards,

    Paul McKenzie
    I'm a novice programmer, so I'll try to be as thorough as possible.

    My software allows me to open images with command line options in a separate command prompt. I cannot physically type into the command prompt associated with my program as it never gives me the option to.

    I am sure the command-line being sent to IrfanView is correct because it is a hard coded string that successfully opens an image when I use it in a system call in my program

    system("\"c:\\program files\\irfanview\\i_view32.exe\" c:\\blarg.bmp /fs")

    The IrfanView commands are documented here

    http://www.robvanderwoude.com/files/iviewcli.txt


    Also, I am not starting the program, which I never knew could be an issue. If I am in a command prompt, the command

    "c:\program files\irfanview\i_view32.exe" c:\blarg.bmp /fs

    automatically opens the image in the program, even if there is no instance of IrfanView running.


    I hope this clarifies things further. Thanks for your help!

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: trouble with Irfanview command line option

    System is a blocking call see http://msdn.microsoft.com/en-us/libr...(v=VS.71).aspx

    If you want the call to be non-blocking use for instance CreateProcess http://msdn.microsoft.com/en-us/libr...25(VS.85).aspx or ShellExecuteEx http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx
    Last edited by S_M_A; June 19th, 2011 at 03:54 PM.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: trouble with Irfanview command line option

    Quote Originally Posted by Ragnarok22788 View Post
    I'm a novice programmer, so I'll try to be as thorough as possible.

    My software allows me to open images with command line options in a separate command prompt.
    when I use it in a system call in my program
    Are you using the system() function? If you're running Windows, you should be using CreateProcess(), and not the watered down system() function call.

    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    Regards,

    Paul McKenzie

  6. #6
    Join Date
    Apr 2011
    Posts
    7

    Re: trouble with Irfanview command line option

    Thanks! I've got the windows coming up and working well now, but I've been stuck on my destroywindow() issue this morning. Though I have ShellExecute create a new process and open the image and immediately calling getConsoleWindow, destroyWindow doesn't seem to be destroying the window.

    I am sure that my getConsoleWindow is getting a window because it never comes back with null, so the HWND I pass to destroyWindow should destroy a window, but nothing is closing on my screen. Any ideas?

    My code is

    ShellExecute(NULL,"open","c:\\program files\\irfanview\\i_view32.exe","c:\\image1.bmp",NULL,SW_SHOW);
    HWND hConsoleWnd = GetConsoleWindow();
    if(hConsoleWnd == NULL)
    {printf("failed attempt.\n");}
    DestroyWindow(hConsoleWnd);



    I'll be looking into CreateProcess in the mean time, since it looks like a better option than ShellExecute, but I figured out how to use ShellExecute first, which is why I used it.

  7. #7
    Join Date
    Feb 2002
    Posts
    4,640

    Re: trouble with Irfanview command line option

    Look at CreateProcess, and the last parameter (LPPROCESS_INFORMATION). This will return you a handle you can use to interact with the newly created process. GetConsoleWindw does not return the console associated with the new process. It gets the console related to the current process.

    Viggy

  8. #8
    Join Date
    Apr 2011
    Posts
    7

    Re: trouble with Irfanview command line option

    I couldn't find a way to use LPPROCESS_INFORMATION to kill the window (CloseHandle wasn't doing the trick for some reason), so I resorted to doing a taskkill system call for Irfanview. It works well enough for my purposes, though I feel that using LPPROCESS_INFORMATION's process handle to close Irfanview's window would be a lot nicer. How is that done?

  9. #9
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: trouble with Irfanview command line option

    Quote Originally Posted by Ragnarok22788 View Post
    I couldn't find a way to use LPPROCESS_INFORMATION to kill the window (CloseHandle wasn't doing the trick for some reason)
    Did you read the documentation on CloseHandle? Where does it say that this should "kill the window"?

    The 'nice' way to close the window would be to get the main window from the process information and send a WM_CLOSE message to that window.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured