473,320 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

c++ win32 command line

14
im using Process::start("test.exe","ture");
it start a process called test.exe and send argument ture but on text.exe i don't know how to get the argument that have been sent,test.exe is win32 window. all i need help with how to get the ture in test.exe?
Aug 9 '10 #1

✓ answered by johny10151981

follow the example if it is a console application

Expand|Select|Wrap|Line Numbers
  1. int _tmain(int argc, _TCHAR* argv[])
  2. {
  3.  int i;
  4.  for(i=0;i<argc;i++)
  5.  {
  6.   wprintf(L"%s",argv[i]);
  7.  }
  8.  return 0;
  9. }
  10.  
If this is an window application

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include "argument.h"
  3.  
  4.  
  5. int APIENTRY _tWinMain(HINSTANCE hInstance,
  6.                      HINSTANCE hPrevInstance,
  7.                      LPTSTR    lpCmdLine,
  8.                      int       nCmdShow)
  9. {
  10.     MessageBox(NULL,lpCmdLine,L"Command Line argument",MB_OK);
  11.     return 1;
  12. }
  13.  

10 6029
johny10151981
1,059 1GB
follow the example if it is a console application

Expand|Select|Wrap|Line Numbers
  1. int _tmain(int argc, _TCHAR* argv[])
  2. {
  3.  int i;
  4.  for(i=0;i<argc;i++)
  5.  {
  6.   wprintf(L"%s",argv[i]);
  7.  }
  8.  return 0;
  9. }
  10.  
If this is an window application

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include "argument.h"
  3.  
  4.  
  5. int APIENTRY _tWinMain(HINSTANCE hInstance,
  6.                      HINSTANCE hPrevInstance,
  7.                      LPTSTR    lpCmdLine,
  8.                      int       nCmdShow)
  9. {
  10.     MessageBox(NULL,lpCmdLine,L"Command Line argument",MB_OK);
  11.     return 1;
  12. }
  13.  
Aug 9 '10 #2
ramilol
14
MessageBox(NULL,lpCmdLine,L"Command Line argument",MB_OK);
will this have the ture value?
Aug 9 '10 #3
johny10151981
1,059 1GB
will this have the ture value?
why dont you try it and see for yourself?
Aug 9 '10 #4
ramilol
14
i would if i can go on my laptop my mom is using it but i will and i tell you the result thanks very much for your time
Aug 9 '10 #5
ramilol
14
i tried it and it worked just fine thanks very much
Aug 9 '10 #6
ramilol
14
can you help me with this one please. ok since the LPTSTR lpCmdLine is declared in WinMain i used this to create var to store ipcmdline value, LPTSTR args = lpCmdLine;i put it in WinMain but when i try to call it from a different function it says undifined args i know why it is saying that but if i decalre the varabile in the other function ill get a different error. so is there way i can call the varable(args) in winMain funtion ?
Aug 9 '10 #7
johny10151981
1,059 1GB
I have no clue what are you talking about. Can you please post code?
Aug 9 '10 #8
ramilol
14
ok
Expand|Select|Wrap|Line Numbers
  1. // Take and Run.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Take and Run.h"
  6. #include <string>
  7. #include <objidl.h>
  8. #include <gdiplus.h>
  9. using namespace Gdiplus;
  10. #pragma comment (lib,"Gdiplus.lib")
  11.  
  12.  
  13. #define MAX_LOADSTRING 100
  14.  
  15. // Global Variables:
  16. HINSTANCE hInst;                                // current instance
  17. TCHAR szTitle[MAX_LOADSTRING];                    // The title bar text
  18. TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
  19.  
  20. // Forward declarations of functions included in this code module:
  21. ATOM                MyRegisterClass(HINSTANCE hInstance);
  22. BOOL                InitInstance(HINSTANCE, int);
  23. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  24. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  25.  
  26. VOID onPaint(HDC hdc)
  27. {
  28.    Graphics graphics(hdc);
  29.    Pen      pen(Color(255, 0, 0, 255));
  30.    graphics.DrawLine(&pen, 0, 0, 200, 100);
  31. }
  32.  
  33. int APIENTRY _tWinMain(HINSTANCE hInstance,
  34.                      HINSTANCE hPrevInstance,
  35.                      LPTSTR    lpCmdLine,
  36.                      int       nCmdShow)
  37. {
  38.     UNREFERENCED_PARAMETER(hPrevInstance);
  39.     UNREFERENCED_PARAMETER(lpCmdLine);
  40.  
  41.      // TODO: Place code here.
  42.     // THE VARABILE THAT WILL STORE THE IPCMDLINE VALUE
  43.     LPTSTR args = lpCmdLine;
  44.  
  45.     MSG msg;
  46.     HACCEL hAccelTable;
  47.  
  48.     GdiplusStartupInput gdiplusStartupInput;
  49.     ULONG_PTR           gdiplusToken;
  50.  
  51.     // Initialize GDI+.
  52.     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  53.  
  54.     // Initialize global strings
  55.     LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  56.     LoadString(hInstance, IDC_TAKEANDRUN, szWindowClass, MAX_LOADSTRING);
  57.     MyRegisterClass(hInstance);
  58.  
  59.     // Perform application initialization:
  60.     if (!InitInstance (hInstance, nCmdShow))
  61.     {
  62.         return FALSE;
  63.     }
  64.  
  65.     hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TAKEANDRUN));
  66.  
  67.     // Main message loop:
  68.     while (GetMessage(&msg, NULL, 0, 0))
  69.     {
  70.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  71.         {
  72.             TranslateMessage(&msg);
  73.             DispatchMessage(&msg);
  74.         }
  75.     }
  76.     GdiplusShutdown(gdiplusToken);
  77.     return (int) msg.wParam;
  78. }
  79.  
  80.  
  81.  
  82. //
  83. //  FUNCTION: MyRegisterClass()
  84. //
  85. //  PURPOSE: Registers the window class.
  86. //
  87. //  COMMENTS:
  88. //
  89. //    This function and its usage are only necessary if you want this code
  90. //    to be compatible with Win32 systems prior to the 'RegisterClassEx'
  91. //    function that was added to Windows 95. It is important to call this function
  92. //    so that the application will get 'well formed' small icons associated
  93. //    with it.
  94. //
  95. ATOM MyRegisterClass(HINSTANCE hInstance)
  96. {
  97.     WNDCLASSEX wcex;
  98.  
  99.     wcex.cbSize = sizeof(WNDCLASSEX);
  100.  
  101.     wcex.style            = CS_HREDRAW | CS_VREDRAW;
  102.     wcex.lpfnWndProc    = WndProc;
  103.     wcex.cbClsExtra        = 0;
  104.     wcex.cbWndExtra        = 0;
  105.     wcex.hInstance        = hInstance;
  106.     wcex.hIcon            = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TAKEANDRUN));
  107.     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
  108.     wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
  109.     wcex.lpszMenuName    = MAKEINTRESOURCE(IDC_TAKEANDRUN);
  110.     wcex.lpszClassName    = szWindowClass;
  111.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  112.  
  113.     return RegisterClassEx(&wcex);
  114. }
  115.  
  116. //
  117. //   FUNCTION: InitInstance(HINSTANCE, int)
  118. //
  119. //   PURPOSE: Saves instance handle and creates main window
  120. //
  121. //   COMMENTS:
  122. //
  123. //        In this function, we save the instance handle in a global variable and
  124. //        create and display the main program window.
  125. //
  126. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  127. {
  128.    HWND hWnd;
  129.  
  130.    hInst = hInstance; // Store instance handle in our global variable
  131.  
  132.    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  133.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  134.  
  135.    if (!hWnd)
  136.    {
  137.       return FALSE;
  138.    }
  139.  
  140.    ShowWindow(hWnd, nCmdShow);
  141.    UpdateWindow(hWnd);
  142.  
  143.    return TRUE;
  144. }
  145.  
  146. //
  147. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  148. //
  149. //  PURPOSE:  Processes messages for the main window.
  150. //
  151. //  WM_COMMAND    - process the application menu
  152. //  WM_PAINT    - Paint the main window
  153. //  WM_DESTROY    - post a quit message and return
  154. //
  155. //
  156. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LPTSTR lpCmdLine)
  157. {
  158.     int wmId, wmEvent;
  159.     PAINTSTRUCT ps;
  160.     HDC hdc;
  161.  
  162.     switch (message)
  163.     {
  164.     case WM_COMMAND:
  165.         wmId    = LOWORD(wParam);
  166.         wmEvent = HIWORD(wParam);
  167.         // Parse the menu selections:
  168.         switch (wmId)
  169.         {
  170.         case IDM_about:
  171.             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  172.             break;
  173.         case IDM_EXIT:
  174.             DestroyWindow(hWnd);
  175.             break;
  176.         default:
  177.             return DefWindowProc(hWnd, message, wParam, lParam);
  178.         }
  179.         break;
  180.     case WM_PAINT:
  181.         hdc = BeginPaint(hWnd, &ps);
  182.         // HERE I USED THE ARGS VARABILE AND I GET A ERROR THAT SAYS ARGS UNDIFINED IF I MOVE MESSAGBOX(..); TO WINMAIN FUNCTION IT WILL WORK
  183.         MessageBox(NULL,args,L"Command Line argument",MB_OK);
  184.         EndPaint(hWnd, &ps);
  185.         break;
  186.     case WM_DESTROY:
  187.         PostQuitMessage(0);
  188.         break;
  189.     default:
  190.         return DefWindowProc(hWnd, message, wParam, lParam);
  191.     }
  192.     return 0;
  193. }
  194.  
  195. // Message handler for about box.
  196. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  197. {
  198.     UNREFERENCED_PARAMETER(lParam);
  199.     switch (message)
  200.     {
  201.     case WM_INITDIALOG:
  202.         return (INT_PTR)TRUE;
  203.  
  204.     case WM_COMMAND:
  205.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  206.         {
  207.             EndDialog(hDlg, LOWORD(wParam));
  208.             return (INT_PTR)TRUE;
  209.         }
  210.         break;
  211.     }
  212.     return (INT_PTR)FALSE;
  213. }
  214.  
i declared the varabile in line 43 and i used messagebox in line 183
Aug 9 '10 #9
johny10151981
1,059 1GB
OK,
The issue is you need to understand the grammatical rules and structure of c/c++.

You have defined args in _tWinMain. So args is a local variable to for _tWinMain

But you are trying to access this variable from your WndProc which is a different function. So an obvious compiler error is generating.

Your problems solution can be taken from your own source code. Take a look at hInstance variable in _tWinMain this is a local variable. But to access this data from WndProc, you(automated system of visual studio IDE) have defined a global variable name hInst outside main. and then hInst is being accessed from WndProc. So, you can define your args globally. and Dont create message alert from your WM_PAINT
Aug 9 '10 #10
ramilol
14
greate it worked and i was creating message because it was the simple way that it would show me if it works
Aug 9 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: d davis | last post by:
I realize that I am getting way ahead of myself. I am studying Learning Perl Win32, Programming Perl and Mastering Perl Tk. For a practical example that I can see that works doing something that I...
11
by: Andrew Warren | last post by:
When I build my winforms exe using the IDE I have a perfectly functioning exe. If I try to build the same project using the .Net Framework csc compiler I get a seemingly valid exe produced...
5
by: Lubo¹ ©lapák | last post by:
Hi, i have a Win32 application in CSharp and i have to run command "net send ....." (these is a command for windows command-line) from this application, but i don't know how can i run this...
7
by: David A. Osborn | last post by:
I am current writing a console program that takes two file paths as command line input. I get the command line input using the following code: parameter = Split(Command()) input = parameter(0)...
4
by: Bit byte | last post by:
I have a project that I normally build (without problems) from the DevStudio IDE. However, I have embarked on automating all my builds (this test project being one of several). The project...
5
by: Selva Chinnasamy | last post by:
Hi I have a Windows application written in VB which has many functions. In addition it also reads a database and generates a output file. Currently this function is called when ever user clicks...
4
by: wxforecaster | last post by:
As alluded to in my post yesterday, I'm trying to compile a common C utility in Windows. It's only reference is to zlib.h, which needs zconf.h and in turn libz.a On Unix I've compiled this with...
0
by: futnuh | last post by:
I am having exactly the same issue as this poster back in 2005. It's strange behaviour where libraries are being automatically appended to my "additional dependencies". In the following linker...
11
by: wangzq | last post by:
Hello, I'm passing command line parameters to my browser, I need to pass the complete command line as-is, for example: test.py "abc def" xyz If I use ' '.join(sys.argv), then the double...
2
by: =?Utf-8?B?UmFtb24gR2VuZQ==?= | last post by:
Hello: I am building a console application and I am having an issue with the command line arguments. A couple of my arguments are paths and they are usually enclosed in double quotes. If one of...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.