Plz plzi need help

Started by
12 comments, last by Chrono1081 15 years, 12 months ago
i have this code for c++: typedef unsigned_int32 ULONG_PTR; //#define ULONG_PTR ULONG#define UNICODE #include <windows.h> #include <Gdiplus.h> using namespace Gdiplus; #pragma comment(lib, "gdiplus.lib") #include <math.h> #include <stdio.h> using namespace Gdiplus; VOID OnPaint(HDC hdc) { Graphics graphics(hdc); Bitmap b(L"Calvin.jpg"); Bitmap* b2; INT iWidth = b.GetWidth(); INT iHeight = b.GetHeight(); Rect rect(0,0,iWidth,iHeight); b2 = b.Clone(rect,PixelFormat24bppRGB); BitmapData bmData; BitmapData bmData2; b.LockBits(&rect,ImageLockModeRead | ImageLockModeWrite,PixelFormat24bppRGB,&bmData); b2->LockBits(&rect,ImageLockModeRead |ImageLockModeWrite,PixelFormat24bppRGB,&bmData2); int stride = bmData.Stride; unsigned char * p = (unsigned char *)bmData.Scan0; unsigned char * p2 = (unsigned char *)bmData2.Scan0; int nOffset = stride - iWidth*3; int nWidth = iWidth * 3; int nPixel = 0, nPixelMax = 0; p += stride; p2 += stride; int nThreshold = 0; for(int y=1;y<iHeight-1;++y) { p += 3; p2 += 3; for(int x=3; x < nWidth-3; ++x ) { nPixelMax = abs((p2 - stride + 3)[0] - (p2+stride-3)[0]); nPixel = abs((p2 + stride + 3)[0] - (p2 - stride - 3)[0]); if (nPixel>nPixelMax) nPixelMax = nPixel; nPixel = abs((p2 - stride)[0] - (p2 + stride)[0]); if (nPixel>nPixelMax) nPixelMax = nPixel; nPixel = abs((p2+3)[0] - (p2 - 3)[0]); if (nPixel>nPixelMax) nPixelMax = nPixel; if (nPixelMax < nThreshold) nPixelMax = 0; /*if(nPixelMax > nThreshold && nPixelMax < 35) nPixelMax = 0; if(nPixelMax > 35) nPixelMax = 255;*/ p[0] = (byte) nPixelMax; ++ p; ++ p2; } p += 3 + nOffset; p2 += 3 + nOffset; } b.UnlockBits(&bmData); b2->UnlockBits(&bmData2); graphics.DrawImage(b2,0,0,iWidth,iHeight); graphics.DrawImage(&b, iWidth+10, 0, iWidth, iHeight); } LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow) { HWND hWnd; MSG msg; WNDCLASS wndClass; GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; // Initialize GDI+. GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); wndClass.style = CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = WndProc; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hInstance = hInstance; wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = TEXT("Edge Detection"); RegisterClass(&wndClass); hWnd = CreateWindow( TEXT("Edge Detection"), // window class name TEXT("Edge Detection"), // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL); // creation parameters ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } GdiplusShutdown(gdiplusToken); return msg.wParam; } // WinMain LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; switch(message) { case WM_CREATE: //OnCreate(); return 0; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); OnPaint(hdc); EndPaint(hWnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(hWnd, message, wParam, lParam); } } // WndProc ============== but i get this errors: Compiling NONAME00.CPP: Error NONAME00.CPP 1: , expected Error NONAME00.CPP 3: Unable to open include file 'WINDOWS.H' Error NONAME00.CPP 4: Unable to open include file 'GDIPLUS.H' Error NONAME00.CPP 5: Declaration syntax error Error NONAME00.CPP 7: Unable to open include file 'MATH.H' Error NONAME00.CPP 8: Unable to open include file 'STDIO.H' Error NONAME00.CPP 10: Variable 'using' is initialized more than once Error NONAME00.CPP 10: Declaration syntax error Error NONAME00.CPP 13: Declaration syntax error Error NONAME00.CPP 100: Declaration syntax error ========= please please i need help ??? ???
Advertisement
Looks like the code's wrong.

Also, moved to For Beginners.
1) Wrap your code in [ source ] tags for readability
2) What are you building this with? The errors certainly don't look like VS2005's... you may still need to install/download the platform SDK
3) There are many better alternatives to GDI+, and C++ for that matter.
4) unsigned_int32 isn't a built in type, not even as an extension on most compilers that I'm aware of. If you're expecting this to be from some other header, move it *after* that header is included
5) using namespaces before your headers are all included is bad mojo and a nono, typically. You're also using the same namespace twice.
6) More descriptive thread titles will get a better response. :)
Quote:Original post by NathanRunge
6) More descriptive thread titles will get a better response. :)


I agree. Most anything with abbreviations such as "plz" gets ignored.


Did you write this code or copy and paste it? What IDE are you using?

Also for C++ that code is pretty outdated. #include <stdio.h> is C, #include <iostream> is c++. Not to mention if this is your only code, its missing a main().
Quote:Original post by Chrono1081
Quote:Original post by NathanRunge
6) More descriptive thread titles will get a better response. :)


I agree. Most anything with abbreviations such as "plz" gets ignored.


Did you write this code or copy and paste it? What IDE are you using?

Also for C++ that code is pretty outdated. #include <stdio.h> is C, #include <iostream> is c++. Not to mention if this is your only code, its missing a main().


It has a WinMain, though.

The compiler error curiously lack line numbers, and convert file names to all caps. I wonder if the OP is using a 16-bit compiler? Either way, it does not appear as if the compiler has been properly informed of the directories to search for include directive resolution.

That and there are various bits of illegal code in there. You're going to have to provide more information, mostaqil cts, as well as more directed questions.
Quote:Original post by mostaqil cts
Error NONAME00.CPP 10: Variable 'using' is initialized more than once


That can't possibly be a C++ compiler, can it?
Isn't "NONAME00.CPP" the default filename for Borland Turbo C++ (the DOS version)? That would explain the lack of support for "using namespace", and of course the missing Win32 headers.
Ok K i didn't have a experience in C++


i will give you the main cod , which i have taken it from wab:

it is about "Edge Detection"

this is the main code, and there are an error with it:


=========




#define UNICODE
#include <windows.h>
#include <gdiplus.h>
#include <math.h>
#include <stdio.h>

using namespace Gdiplus;


VOID OnPaint(HDC hdc)
{
Graphics graphics(hdc);

Bitmap b(L"Calvin.jpg");
Bitmap* b2;

INT iWidth = b.GetWidth();
INT iHeight = b.GetHeight();

Rect rect(0,0,iWidth,iHeight);
b2 = b.Clone(rect,PixelFormat24bppRGB);


BitmapData bmData;
BitmapData bmData2;

b.LockBits(&rect,ImageLockModeRead | ImageLockModeWrite,PixelFormat24bppRGB,&bmData);
b2->LockBits(&rect,ImageLockModeRead |ImageLockModeWrite,PixelFormat24bppRGB,&bmData2);

int stride = bmData.Stride;

unsigned char * p = (unsigned char *)bmData.Scan0;
unsigned char * p2 = (unsigned char *)bmData2.Scan0;


int nOffset = stride - iWidth*3;
int nWidth = iWidth * 3;

int nPixel = 0, nPixelMax = 0;

p += stride;
p2 += stride;
int nThreshold = 0;

for(int y=1;y<iHeight-1;++y)
{
p += 3;
p2 += 3;

for(int x=3; x < nWidth-3; ++x )
{


nPixelMax = abs((p2 - stride + 3)[0] - (p2+stride-3)[0]);
nPixel = abs((p2 + stride + 3)[0] - (p2 - stride - 3)[0]);
if (nPixel>nPixelMax) nPixelMax = nPixel;

nPixel = abs((p2 - stride)[0] - (p2 + stride)[0]);
if (nPixel>nPixelMax) nPixelMax = nPixel;

nPixel = abs((p2+3)[0] - (p2 - 3)[0]);
if (nPixel>nPixelMax) nPixelMax = nPixel;

if (nPixelMax < nThreshold)
nPixelMax = 0;

/*if(nPixelMax > nThreshold && nPixelMax < 35)
nPixelMax = 0;

if(nPixelMax > 35)
nPixelMax = 255;*/

p[0] = (byte) nPixelMax;

++ p;
++ p2;

}

p += 3 + nOffset;
p2 += 3 + nOffset;
}



b.UnlockBits(&bmData);
b2->UnlockBits(&bmData2);

graphics.DrawImage(b2,0,0,iWidth,iHeight);
graphics.DrawImage(&b, iWidth+10, 0, iWidth, iHeight);

}


LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASS wndClass;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;

// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = TEXT("Edge Detection");

RegisterClass(&wndClass);

hWnd = CreateWindow(
TEXT("Edge Detection"), // window class name
TEXT("Edge Detection"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL); // creation parameters

ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);

while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

GdiplusShutdown(gdiplusToken);
return msg.wParam;
} // WinMain


LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;

switch(message)
{
case WM_CREATE:
//OnCreate();
return 0;

case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
OnPaint(hdc);
EndPaint(hWnd, &ps);
return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;

default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
} // WndProc



==============

THis are the eroor :



Compiling NONAME00.CPP:
Error NONAME00.CPP 4: Unable to open include file 'GDIPLUS.H'
Error NONAME00.CPP 5: Unable to open include file 'MATH.H'
Error NONAME00.CPP 6: Unable to open include file 'STDIO.H'
Error NONAME00.CPP 8: Declaration syntax error
Error NONAME00.CPP 13: Undefined symbol 'Graphics' in function OnPaint(unsigned int)
Error NONAME00.CPP 13: Statement missing ; in function OnPaint(unsigned int)
Error NONAME00.CPP 15: Undefined symbol 'Bitmap' in function OnPaint(unsigned int)
Error NONAME00.CPP 15: Statement missing ; in function OnPaint(unsigned int)
Error NONAME00.CPP 16: Undefined symbol 'b2' in function OnPaint(unsigned int)
Error NONAME00.CPP 18: Undefined symbol 'INT' in function OnPaint(unsigned int)
Error NONAME00.CPP 18: Statement missing ; in function OnPaint(unsigned int)
Error NONAME00.CPP 19: Statement missing ; in function OnPaint(unsigned int)
Error NONAME00.CPP 21: Undefined symbol 'Rect' in function OnPaint(unsigned int)
Error NONAME00.CPP 21: Statement missing ; in function OnPaint(unsigned int)
Error NONAME00.CPP 22: Undefined symbol 'b' in function OnPaint(unsigned int)
Error NONAME00.CPP 22: Undefined symbol 'rect' in function OnPaint(unsigned int)
Error NONAME00.CPP 22: Undefined symbol 'PixelFormat24bppRGB' in function OnPaint(unsigned int)
Error NONAME00.CPP 25: Undefined symbol 'BitmapData' in function OnPaint(unsigned int)
Error NONAME00.CPP 25: Statement missing ; in function OnPaint(unsigned int)
Error NONAME00.CPP 26: Statement missing ; in function OnPaint(unsigned int)
Error NONAME00.CPP 28: Undefined symbol 'ImageLockModeRead' in function OnPaint(unsigned int)
Error NONAME00.CPP 28: Undefined symbol 'ImageLockModeWrite' in function OnPaint(unsigned int)
Error NONAME00.CPP 28: Undefined symbol 'bmData' in function OnPaint(unsigned int)
Error NONAME00.CPP 29: Undefined symbol 'bmData2' in function OnPaint(unsigned int)
Error NONAME00.CPP 37: Undefined symbol 'iWidth' in function OnPaint(unsigned int)
Error NONAME00.CPP 37: Too many error or warning messages in function OnPaint(unsigned int)
mostaqil cts, what compiler are you using? There is simply no way you will get that code to compile on Turbo C++ for DOS. You can't expect to be able to generate 32-bit Windows object code with a 16-bit MS-DOS compiler, let alone one that was released almost 20 years ago.

This topic is closed to new replies.

Advertisement