caseyrodman86 0 Newbie Poster

I am a noob in programming and i am writing a program in Visual C++ and i want to save a screenshot taken when the program opens to a .bmp or some type of image file.

keybd_event(0x2C, 0, 0, 0);

I am using this to call the keyboard event PRTSC, placing the screenshot in the clipboard.

I found this code somewhere in a different forum:

int Screenshotal(HDC hdc, char *pszflname)
{
	HDC memdc;
	HANDLE hfl;
	DWORD dwBytes, dwWidth, dwHeight, dwNumColors, dwBPP, ColorSize;
	void *pBits;
	HBITMAP hbmp;
	BITMAPFILEHEADER fileheader;
	BITMAPINFOHEADER infoheader;
	RGBQUAD colors[256];
	BITMAPINFO bmpinfo;
	HGDIOBJ hret;

	dwWidth = GetDeviceCaps(hdc, HORZRES);
	dwHeight = GetDeviceCaps(hdc, VERTRES);
	dwBPP = GetDeviceCaps(hdc, BITSPIXEL);
	if (dwBPP <= 8)
		dwNumColors = 256;
	else dwNumColors = 0;
	if (!(memdc = CreateCompatibleDC(hdc)))
		return (0);
	bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bmpinfo.bmiHeader.biWidth = dwWidth;
	bmpinfo.bmiHeader.biHeight = dwHeight;
	bmpinfo.bmiHeader.biPlanes = 1;
	bmpinfo.bmiHeader.biBitCount = (WORD)dwBPP;
	bmpinfo.bmiHeader.biCompression = BI_RGB;
	bmpinfo.bmiHeader.biSizeImage = 0;
	bmpinfo.bmiHeader.biXPelsPerMeter = 0;
	bmpinfo.bmiHeader.biYPelsPerMeter = 0;
	bmpinfo.bmiHeader.biClrUsed = dwNumColors;
	bmpinfo.bmiHeader.biClrImportant = dwNumColors;
	hbmp = CreateDIBSection(hdc, &bmpinfo, DIB_PAL_COLORS, &pBits, NULL, 0);
	if (!hbmp)
	{
		DeleteDC(memdc);
		return (0);
	}
		hret = SelectObject(memdc, hbmp);
	if (!hret || (hret == HGDI_ERROR))
	{
		DeleteDC(memdc);
		return (0);
	}
	if (!BitBlt(memdc, 0, 0, dwWidth, dwHeight, hdc, 0, 0, SRCCOPY))
	{
		DeleteDC(memdc);
		return (0);
	}
	if (dwNumColors)
		dwNumColors = GetDIBColorTable(memdc, 0, dwNumColors, colors);
		fileheader.bfType = 0x4D42;
		ColorSize = dwNumColors * sizeof(RGBQUAD);
		fileheader.bfSize = ((dwWidth*dwHeight*dwBPP) >> 3) + ColorSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
		fileheader.bfReserved1 = fileheader.bfReserved2 = 0;
		fileheader.bfOffBits = ColorSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
		infoheader.biSize = sizeof(BITMAPINFOHEADER);
		infoheader.biWidth = dwWidth;
		infoheader.biHeight = dwHeight;
		infoheader.biPlanes = 1;
		infoheader.biBitCount = (WORD)dwBPP;
		infoheader.biCompression = BI_RGB;
		infoheader.biSizeImage = infoheader.biClrImportant = 0;
		infoheader.biXPelsPerMeter = infoheader.biYPelsPerMeter = 0;
		infoheader.biClrUsed = dwNumColors;
		hfl = CreateFile(pszflname, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
		if (hfl == INVALID_HANDLE_VALUE)
		{
			DeleteObject(hbmp);
		{
			DeleteDC(memdc);
			return (0);
		}
		}
		WriteFile(hfl, &fileheader, sizeof(BITMAPFILEHEADER), &dwBytes, 0);
		WriteFile(hfl, &infoheader, sizeof(BITMAPINFOHEADER), &dwBytes, 0);
		if (!dwNumColors)
			WriteFile(hfl, colors, ColorSize, &dwBytes, 0);
			ColorSize = (dwWidth * dwHeight * dwBPP) >> 3;
			WriteFile(hfl, pBits, ColorSize, &dwBytes, 0);
			CloseHandle(hfl);
			DeleteObject(hbmp);
			DeleteDC(memdc);
			return (1);
}

but I getting getting the error in line 66:
error C2664: 'CreateFileW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast.


Any suggestions??? Also how would i obtain the HDC of the image from the clipboard?? basically how would i call this function if i got it working without any compile errors?