eMbedded C++

This is a discussion on eMbedded C++ within the C++ Programming forums, part of the General Programming Boards category; First of all, let me ask this... has anyone even used this? Secondly, I was wondering if you can just ...

  1. #1
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429

    eMbedded C++

    First of all, let me ask this... has anyone even used this? Secondly, I was wondering if you can just write C programs, instead of C++, because I don't know much about C++, but I know plenty about C.

    I was just trying to create the simple hello world deal and I'm lost already... how do you use cout and cin?
    EntropySink. You know you have to click it.

  2. #2
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    soo... I opened a new project and let it create the default Hello World application......... and this is the code it spit out to print two FREAKIN WORDS!

    Code:
    // test.cpp : Defines the entry point for the application.
    //
    
    #include "stdafx.h"
    #include "test.h"
    #include <commctrl.h>
    #include <aygshell.h>
    #include <sipapi.h>
    
    #define MAX_LOADSTRING 100
    
    // Global Variables:
    HINSTANCE			hInst;					// The current instance
    HWND				hwndCB;					// The command bar handle
    
    static SHACTIVATEINFO s_sai;
    
    // Forward declarations of functions included in this code module:
    ATOM				MyRegisterClass	(HINSTANCE, LPTSTR);
    BOOL				InitInstance	(HINSTANCE, int);
    LRESULT CALLBACK	WndProc			(HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK	About			(HWND, UINT, WPARAM, LPARAM);
    HWND				CreateRpCommandBar(HWND);
    
    
    int WINAPI WinMain(	HINSTANCE hInstance,
    					HINSTANCE hPrevInstance,
    					LPTSTR    lpCmdLine,
    					int       nCmdShow)
    {
    	MSG msg;
    	HACCEL hAccelTable;
    
    	// Perform application initialization:
    	if (!InitInstance (hInstance, nCmdShow)) 
    	{
    		return FALSE;
    	}
    
    	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TEST);
    
    	// Main message loop:
    	while (GetMessage(&msg, NULL, 0, 0)) 
    	{
    		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    	}
    
    	return msg.wParam;
    }
    
    //
    //  FUNCTION: MyRegisterClass()
    //
    //  PURPOSE: Registers the window class.
    //
    //  COMMENTS:
    //
    //    It is important to call this function so that the application 
    //    will get 'well formed' small icons associated with it.
    //
    ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
    {
    	WNDCLASS	wc;
    
        wc.style			= CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc		= (WNDPROC) WndProc;
        wc.cbClsExtra		= 0;
        wc.cbWndExtra		= 0;
        wc.hInstance		= hInstance;
        wc.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TEST));
        wc.hCursor			= 0;
        wc.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH);
        wc.lpszMenuName		= 0;
        wc.lpszClassName	= szWindowClass;
    
    	return RegisterClass(&wc);
    }
    
    //
    //  FUNCTION: InitInstance(HANDLE, int)
    //
    //  PURPOSE: Saves instance handle and creates main window
    //
    //  COMMENTS:
    //
    //    In this function, we save the instance handle in a global variable and
    //    create and display the main program window.
    //
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
    	HWND	hWnd = NULL;
    	TCHAR	szTitle[MAX_LOADSTRING];			// The title bar text
    	TCHAR	szWindowClass[MAX_LOADSTRING];		// The window class name
    
    	hInst = hInstance;		// Store instance handle in our global variable
    	// Initialize global strings
    	LoadString(hInstance, IDC_TEST, szWindowClass, MAX_LOADSTRING);
    	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    
    	//If it is already running, then focus on the window
    	hWnd = FindWindow(szWindowClass, szTitle);	
    	if (hWnd) 
    	{
    		SetForegroundWindow ((HWND) (((DWORD)hWnd) | 0x01));    
    		return 0;
    	} 
    
    	MyRegisterClass(hInstance, szWindowClass);
    	
    	RECT	rect;
    	GetClientRect(hWnd, &rect);
    	
    	hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
    		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
    	if (!hWnd)
    	{	
    		return FALSE;
    	}
    	//When the main window is created using CW_USEDEFAULT the height of the menubar (if one
    	// is created is not taken into account). So we resize the window after creating it
    	// if a menubar is present
    	{
    		RECT rc;
    		GetWindowRect(hWnd, &rc);
    		rc.bottom -= MENU_HEIGHT;
    		if (hwndCB)
    			MoveWindow(hWnd, rc.left, rc.top, rc.right, rc.bottom, FALSE);
    	}
    
    
    	ShowWindow(hWnd, nCmdShow);
    	UpdateWindow(hWnd);
    
    	return TRUE;
    }
    
    //
    //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
    //
    //  PURPOSE:  Processes messages for the main window.
    //
    //  WM_COMMAND	- process the application menu
    //  WM_PAINT	- Paint the main window
    //  WM_DESTROY	- post a quit message and return
    //
    //
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	HDC hdc;
    	int wmId, wmEvent;
    	PAINTSTRUCT ps;
    	TCHAR szHello[MAX_LOADSTRING];
    
    	switch (message) 
    	{
    		case WM_COMMAND:
    			wmId    = LOWORD(wParam); 
    			wmEvent = HIWORD(wParam); 
    			// Parse the menu selections:
    			switch (wmId)
    			{	
    				case IDM_HELP_ABOUT:
    					DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
    				    break;
    				case IDOK:
    					SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd);
    					SendMessage (hWnd, WM_CLOSE, 0, 0);
    					break;
    				default:
    				   return DefWindowProc(hWnd, message, wParam, lParam);
    			}
    			break;
    		case WM_CREATE:
    			hwndCB = CreateRpCommandBar(hWnd);
    			break;
    		case WM_PAINT:
    			RECT rt;
    			hdc = BeginPaint(hWnd, &ps);
    			GetClientRect(hWnd, &rt);
    			LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
    			DrawText(hdc, szHello, _tcslen(szHello), &rt, 
    				DT_SINGLELINE | DT_VCENTER | DT_CENTER);
    			EndPaint(hWnd, &ps);
    			break; 
    		case WM_DESTROY:
    			CommandBar_Destroy(hwndCB);
    			PostQuitMessage(0);
    			break;
    		case WM_SETTINGCHANGE:
    			SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
         		break;
    		default:
    			return DefWindowProc(hWnd, message, wParam, lParam);
       }
       return 0;
    }
    
    HWND CreateRpCommandBar(HWND hwnd)
    {
    	SHMENUBARINFO mbi;
    
    	memset(&mbi, 0, sizeof(SHMENUBARINFO));
    	mbi.cbSize     = sizeof(SHMENUBARINFO);
    	mbi.hwndParent = hwnd;
    	mbi.nToolBarId = IDM_MENU;
    	mbi.hInstRes   = hInst;
    	mbi.nBmpId     = 0;
    	mbi.cBmpImages = 0;
    
    	if (!SHCreateMenuBar(&mbi)) 
    		return NULL;
    
    	return mbi.hwndMB;
    }
    
    // Mesage handler for the About box.
    LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	SHINITDLGINFO shidi;
    
    	switch (message)
    	{
    		case WM_INITDIALOG:
    			// Create a Done button and size it.  
    			shidi.dwMask = SHIDIM_FLAGS;
    			 shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
    			shidi.hDlg = hDlg;
    			SHInitDialog(&shidi);
    			return TRUE; 
    
    		case WM_COMMAND:
    			if (LOWORD(wParam) == IDOK) {
    				EndDialog(hDlg, LOWORD(wParam));
    				return TRUE;
    			}
    			break;
    	}
        return FALSE;
    }
    EntropySink. You know you have to click it.

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    LOL!
    ober, the wizard is not a good representation of what a program should be.

    Code:
    #include <iostream>
    
    int main(void)
       {
       std::cout << "Hello World" << std::endl;
       return 0;
       }
    that's a better example
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    plus it looks like you did a windows app and not a console app. First time with VC++? You want a "Win32 Console App"
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297

    Re: eMbedded C++

    Originally posted by ober5861
    ... how do you use cout and cin?
    Code:
    char str[256];
    int num;
    
    cin >> str;
    cin >> num;
    cout << str << " a const char string " << num << endl;
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #6
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    yo... FYB... maybe you didn't read the title, or maybe understand it. I'm talking about eVC++ here... C++ for Windows CE. Part of the eMbedded Visual Studio.

    It's a tad different than normal C++, hence my questions about the need for all that extra garbage.
    EntropySink. You know you have to click it.

  7. #7
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    ah yes. No offense. I know you aren't some newbie. But that IS a windows program. Do they not have console apps on there? if not then I assume cout/cin wouldn't do anything for you.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  8. #8
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    Technically, yes, it IS a windows program. And no, there is no such thing as a "console app" when it comes to Windows CE.

    I'm guessing that's where the whole "DispatchMessage(&msg)" stuff comes in huh? ahh... I think I'll just stick to eVB.
    EntropySink. You know you have to click it.

  9. #9
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    well even if you were doing a windows program you could do it with a lot less code than the wizard spits out. If you want the world's simplest windows program it's this:
    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
         {
         MessageBox(NULL,"Hello World", "",MB_OK);
         return TRUE;
         }
    which is obviously a lot less code than the example. In fact, it's not really any more than a console one. But let's face it, if you're going to create a window you're going to get a lot more code.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading and writing to an embedded file
    By HLMetroid in forum C# Programming
    Replies: 4
    Last Post: 01-01-2009, 11:03 PM
  2. Embedded system board
    By ssharish2005 in forum Tech Board
    Replies: 1
    Last Post: 08-12-2007, 03:03 PM
  3. Question on embedded systems
    By ssharish2005 in forum C Programming
    Replies: 3
    Last Post: 08-12-2007, 02:28 PM
  4. embedded c++
    By fizz_uk83 in forum C++ Programming
    Replies: 4
    Last Post: 08-13-2003, 08:09 AM
  5. Embedded C
    By Sheep in forum C Programming
    Replies: 3
    Last Post: 03-27-2002, 05:37 PM

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