gvector 0 Newbie Poster

Hello fellow programmers,

I have a problem that I have been trying to figure out for a while now. I am trying to use the GDIPLUS library but am having troubles. To test this code as it is meant to be used, open a new solution in MSVC6.0 or 7.0. Open a Win32 project an make sure it is a hello world program. Then replace the .cpp program it creates for you with the following .cpp. Include the linker path for gdiplus.lib and gdiplus.h and you should be ready to compile. Now for the errors:

: error C2871: 'Gdiplus' : a namespace with this name does not exist
: error C2653: 'Gdiplus' : is not a class or namespace name

I am using the .NET version but have the same problem on MSVC6.0. This does not make sense because Gdiplus is a namespace. Here is the code

// Sample.cpp : Defines the entry point for the application.
//

#include <gdiplus.h>
#include <windows.h>
#include "stdafx.h"
#include "Sample.h"
#define MAX_LOADSTRING 100

//using namespace Gdiplus;  //added just to see what would happen.

ULONG_PTR gdiplusToken;
Gdiplus&#58;&#58;GdiplusStartupInput gdiplusStartupInput;

// Global Variables&#58;
HINSTANCE hInst;								// current instance
TCHAR szTitle&#91;MAX_LOADSTRING&#93;;					// The title bar text
TCHAR szWindowClass&#91;MAX_LOADSTRING&#93;;			// the main window class name

// Forward declarations of functions included in this code module&#58;
ATOM				MyRegisterClass&#40;HINSTANCE hInstance&#41;;
BOOL				InitInstance&#40;HINSTANCE, int&#41;;
LRESULT CALLBACK	WndProc&#40;HWND, UINT, WPARAM, LPARAM&#41;;
LRESULT CALLBACK	About&#40;HWND, UINT, WPARAM, LPARAM&#41;;

int APIENTRY _tWinMain&#40;HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow&#41;
&#123;
 	// TODO&#58; Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString&#40;hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING&#41;;
	LoadString&#40;hInstance, IDC_SAMPLE, szWindowClass, MAX_LOADSTRING&#41;;
	MyRegisterClass&#40;hInstance&#41;;

	// Perform application initialization&#58;
	if &#40;!InitInstance &#40;hInstance, nCmdShow&#41;&#41; 
	&#123;
		return FALSE;
	&#125;

	hAccelTable = LoadAccelerators&#40;hInstance, &#40;LPCTSTR&#41;IDC_SAMPLE&#41;;

	Gdiplus&#58;&#58;GdiplusStartup&#40;&gdiplusToken,&gdiplusStartupInput,NULL&#41;;
	// Main message loop&#58;
	while &#40;GetMessage&#40;&msg, NULL, 0, 0&#41;&#41; 
	&#123;
		if &#40;!TranslateAccelerator&#40;msg.hwnd, hAccelTable, &msg&#41;&#41; 
		&#123;
			TranslateMessage&#40;&msg&#41;;
			DispatchMessage&#40;&msg&#41;;
		&#125;
    Gdiplus&#58;&#58;GdiplusShutdown&#40;gdiplusToken&#41;;

	&#125;

	return &#40;int&#41; msg.wParam;
&#125;



//
//  FUNCTION&#58; MyRegisterClass&#40;&#41;
//
//  PURPOSE&#58; Registers the window class.
//
//  COMMENTS&#58;
//
//    This function and its usage are only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass&#40;HINSTANCE hInstance&#41;
&#123;
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof&#40;WNDCLASSEX&#41;; 

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= &#40;WNDPROC&#41;WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon&#40;hInstance, &#40;LPCTSTR&#41;IDI_SAMPLE&#41;;
	wcex.hCursor		= LoadCursor&#40;NULL, IDC_ARROW&#41;;
	wcex.hbrBackground	= &#40;HBRUSH&#41;&#40;COLOR_WINDOW+1&#41;;
	wcex.lpszMenuName	= &#40;LPCTSTR&#41;IDC_SAMPLE;
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon&#40;wcex.hInstance, &#40;LPCTSTR&#41;IDI_SMALL&#41;;

	return RegisterClassEx&#40;&wcex&#41;;
&#125;

//
//   FUNCTION&#58; InitInstance&#40;HANDLE, int&#41;
//
//   PURPOSE&#58; Saves instance handle and creates main window
//
//   COMMENTS&#58;
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance&#40;HINSTANCE hInstance, int nCmdShow&#41;
&#123;
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow&#40;szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL&#41;;

   if &#40;!hWnd&#41;
   &#123;
      return FALSE;
   &#125;

   ShowWindow&#40;hWnd, nCmdShow&#41;;
   UpdateWindow&#40;hWnd&#41;;

   return TRUE;
&#125;

//
//  FUNCTION&#58; WndProc&#40;HWND, unsigned, WORD, LONG&#41;
//
//  PURPOSE&#58;  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&#40;HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam&#41;
&#123;
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch &#40;message&#41; 
	&#123;
	case WM_COMMAND&#58;
		wmId    = LOWORD&#40;wParam&#41;; 
		wmEvent = HIWORD&#40;wParam&#41;; 
		// Parse the menu selections&#58;
		switch &#40;wmId&#41;
		&#123;
		case IDM_ABOUT&#58;
			DialogBox&#40;hInst, &#40;LPCTSTR&#41;IDD_ABOUTBOX, hWnd, &#40;DLGPROC&#41;About&#41;;
			break;
		case IDM_EXIT&#58;
			DestroyWindow&#40;hWnd&#41;;
			break;
		default&#58;
			return DefWindowProc&#40;hWnd, message, wParam, lParam&#41;;
		&#125;
		break;
	case WM_PAINT&#58;
		hdc = BeginPaint&#40;hWnd, &ps&#41;;
////////////////////THE ONLY CODE THAT I HAVE ADDED OTHER THAN HEADER INCLUDES
			Gdiplus&#58;&#58;Graphics gs&#40;hdc&#41;;
			Gdiplus&#58;&#58;Image image&#40;L"misc0001.tif"&#41;;
			gs.DrawImage&#40;&image,0,0&#41;;
			EndPaint&#40;hWnd, &ps&#41;;
//////////////////////////////////////////////////////////////////////////////		EndPaint&#40;hWnd, &ps&#41;;
		break;
	case WM_DESTROY&#58;
		PostQuitMessage&#40;0&#41;;
		break;
	default&#58;
		return DefWindowProc&#40;hWnd, message, wParam, lParam&#41;;
	&#125;
	return 0;
&#125;

// Message handler for about box.
LRESULT CALLBACK About&#40;HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam&#41;
&#123;
	switch &#40;message&#41;
	&#123;
	case WM_INITDIALOG&#58;
		return TRUE;

	case WM_COMMAND&#58;
		if &#40;LOWORD&#40;wParam&#41; == IDOK || LOWORD&#40;wParam&#41; == IDCANCEL&#41; 
		&#123;
			EndDialog&#40;hDlg, LOWORD&#40;wParam&#41;&#41;;
			return TRUE;
		&#125;
		break;
	&#125;
	return FALSE;
&#125;

If anyone could help me figure out why I am getting this error I would greatly appreciate it. There might be a bunch of other problems with the code, but it is just practice with GDI+.

Seriously thankful,
Kendal

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.