Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 7th, 2010, 07:51 AM
Registered User
 
Join Date: Mar 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy passing arguments with shellexecute

-excuse me for my english -

i want to execute a program from an other with shellexecute and with passing multiple arguments, the problem is just the first argument is passed to the other ... what can i do ?

the frist
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{

    FILE * f;
    if(argc>1){


        f = fopen(strcat(argv[1],".txt"), "a");

        if (f != NULL)
        {
            printf("%s",argv[2]);
           fprintf(f, "%s^%s\n",argv[2],argv[3]);
            printf("qsdfs");
        }
        fclose(f);
        }
    else
        perror(argv[1]);
getch();
    return 0;
}
the second

Code:
#include <windows.h>
#include <shellapi.h>


int main ()
{

char **tab;
tab=(char**)malloc(3*sizeof(char*));
tab[0]=(char*)malloc(10*sizeof(char));
tab[1]=(char*)malloc(10*sizeof(char));
tab[2]=(char*)malloc(sizeof(char));

strcpy(tab[0],"films");
strcpy(tab[1],"the titanic");
strcpy(tab[2],"1h 45min");


ShellExecute(NULL,"open","insert.exe",tab,NULL,SW_SHOWDEFAULT);
  return 0;
}
Reply With Quote
  #2 (permalink)  
Old March 7th, 2010, 11:43 AM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

The question is a bit vague.

One thing is obviously wrong: what you assigned to tab[1] contained more characters than what was allocated to tab[1].

Last edited by PeterPeiGuo; March 7th, 2010 at 11:48 AM..
Reply With Quote
  #3 (permalink)  
Old March 7th, 2010, 11:50 AM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

I looked one line further, and tab[2] had the same problem.
Reply With Quote
  #4 (permalink)  
Old March 9th, 2010, 07:24 PM
Authorized User
 
Join Date: Jan 2010
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Arrow

Try this.

#include <windows.h>
#include <shellapi.h>


int main ()
{
char szParameters[64];
strcpy(szParameters, "films \"the titanic\" \"1h 45min\"");
ShellExecute(NULL, "open", "insert.exe", szParameters, NULL, SW_SHOWDEFAULT);
return 0;
}
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Declarative arguments passing between DetailsViews andremi Classic ASP Basics 1 May 10th, 2007 09:24 PM
Passing multiple arguments to function zarikiane XSLT 2 July 18th, 2006 09:35 AM
passing arguments to executables DaveG BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 0 May 30th, 2006 03:26 PM
Passing arguments to contructor of dynamically... jacob ASP.NET 1.0 and 1.1 Professional 3 December 2nd, 2005 02:43 PM
passing/getting arguments from ShellExecute TazMania23 Visual C++ 0 May 21st, 2004 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.