Re: exe error, works on some pcs but doesnt on others
The error message you got absolutely sucks, unfortunately. Most likely, what it really means is that you did not install all the
DLLs upon which your application depends, or that a manifest was not found in the file for the CRT. Most likely, you didn't install
the version of the VC redistributable files (like the CRT, MFC, etc.).
Aegis Delacour wrote:
Hi..i have a problem where my code when compiled works only on some
PCs for a reason i dont really know. it gives me this error.
this application has failed to start because the application
configuration is incorrect. reinstalling the application may fix the
problem..
here is my code, if it is a compiler error on my part..could someone
compile it and send me the exe please
as i dont have access to visual studio anymore and i need to get this
fixed.
thank you
#include <windows.h>
#include <stdio.h>
#include <fstream>
#include <GdiPlus.h>
using namespace Gdiplus;
using namespace std;
int GetEncoderClsid(WCHAR *format, CLSID *pClsid)
{
unsigned int num = 0, size = 0;
GetImageEncodersSize(&num, &size);
if(size == 0) return -1;
ImageCodecInfo *pImageCodecInfo = (ImageCodecInfo *)(malloc(size));
if(pImageCodecInfo == NULL) return -1;
GetImageEncoders(num, size, pImageCodecInfo);
for(unsigned int j = 0; j < num; ++j){
if(wcscmp(pImageCodecInfo[j].MimeType, format) == 0){
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j;
}
}
free(pImageCodecInfo);
return -1;
}
int GetScreeny(LPWSTR lpszFilename, ULONG uQuality)
{
ULONG_PTR gdiplusToken;
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
HDC hdcCapture = CreateCompatibleDC(hdcScreen);
int nWidth = GetDeviceCaps(hdcScreen, HORZRES),
nHeight = GetDeviceCaps(hdcScreen, VERTRES),
nBPP = GetDeviceCaps(hdcScreen, BITSPIXEL);
LPBYTE lpCapture;
BITMAPINFO bmiCapture = { {
sizeof(BITMAPINFOHEADER), nWidth, -nHeight, 1, nBPP, BI_RGB, 0, 0,
0, 0, 0,
} };
HBITMAP hbmCapture = CreateDIBSection(hdcScreen, &bmiCapture,
DIB_PAL_COLORS, (LPVOID *)&lpCapture, NULL, 0);
if(!hbmCapture){
DeleteDC(hdcCapture);
DeleteDC(hdcScreen);
GdiplusShutdown(gdiplusToken);
return 1;
}
int nCapture = SaveDC(hdcCapture);
SelectObject(hdcCapture, hbmCapture);
BitBlt(hdcCapture, 0, 0, nWidth, nHeight, hdcScreen, 0, 0, SRCCOPY);
RestoreDC(hdcCapture, nCapture);
DeleteDC(hdcCapture);
DeleteDC(hdcScreen);
CLSID imageCLSID;
Bitmap *pScreenShot = new Bitmap(hbmCapture, (HPALETTE)NULL);
EncoderParameters encoderParams;
encoderParams.Count = 1;
encoderParams.Parameter[0].NumberOfValues = 1;
encoderParams.Parameter[0].Guid = EncoderQuality;
encoderParams.Parameter[0].Type = EncoderParameterValueTypeLong;
encoderParams.Parameter[0].Value = &uQuality;
GetEncoderClsid(L"image/jpeg", &imageCLSID);
int result = (pScreenShot->Save(lpszFilename, &imageCLSID,
&encoderParams) == Ok);
delete pScreenShot;
DeleteObject(hbmCapture);
GdiplusShutdown(gdiplusToken);
return result;
}
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR
lpCmdLine, int nShowCmd)
{
int status;
ifstream ifile;
ifile.open("screeny1.jpg");
if( ifile.is_open() == false)
{
status = GetScreeny(L"screeny1.jpg", 75); //get the screenshot
}
else //1 exist
{
ifile.close();
ifile.clear();
ifile.open("screeny2.jpg");
if( ifile.is_open() == false)
{
status = rename("screeny1.jpg", "screeny2.jpg");
status = GetScreeny(L"screeny1.jpg", 75);
}
else //2 exist
{
ifile.close();
ifile.clear();
ifile.open("screeny3.jpg");
if( ifile.is_open() == false)
{
status = rename("screeny2.jpg", "screeny3.jpg");
status = remove("screeny2.jpg");
status = rename("screeny1.jpg", "screeny2.jpg");
status = GetScreeny(L"screeny1.jpg", 75);
}
else //3 exist
{
ifile.close();
ifile.clear();
ifile.open("screeny4.jpg");
if( ifile.is_open() == false)
{
status = rename("screeny3.jpg", "screeny4.jpg");
status = remove("screeny3.jpg");
status = rename("screeny2.jpg", "screeny3.jpg");
status = remove("screeny2.jpg");
status = rename("screeny1.jpg", "screeny2.jpg");
status = GetScreeny(L"screeny1.jpg", 75);
}
else //4 exist, meaning 5 must be deleted no matter what
{
ifile.close();
ifile.clear();
status = remove("screeny5.jpg");
status = rename("screeny4.jpg", "screeny5.jpg");
status = remove("screeny4.jpg");
status = rename("screeny3.jpg", "screeny4.jpg");
status = remove("screeny3.jpg");
status = rename("screeny2.jpg", "screeny3.jpg");
status = remove("screeny2.jpg");
status = rename("screeny1.jpg", "screeny2.jpg");
status = GetScreeny(L"screeny1.jpg", 75);
}
}
}
}
// return 0; //return 0 to Windows
}