System Error 183 from print call (ERROR_ALREADY_EXISTS) - c++

I am trying to get a test page printed from the Windows Driver Kit (WDK) 8.1 Samples (the bitmap sample). Since I did not get any print output, I placed a "GetLastError" call after each call to 'DrvWriteSpoolBuf":
dwWritten = pDevObj->pDrvProcs->DrvWriteSpoolBuf(pDevObj, (void*)&(pOemPDEV->bmFileHeader), sizeof(BITMAPFILEHEADER));
DWORD pdwReturn = GetLastError();
if (pdwReturn != ERROR_SUCCESS)
ERR("OEMEndDoc: Error printing=%ld\n", pdwReturn);
I received Error 183 !!! From System Error Codes:
ERROR_ALREADY_EXISTS
183 (0xB7)
Cannot create a file when that file already exists.
Alternate version of call above
DWORD res = pOemPDEV->pOEMHelp->DrvWriteSpoolBuf(pDevObj, &(pOemPDEV->bmFileHeader), sizeof(BITMAPFILEHEADER), &dwWritten);
I get res=E_FAIL
(apology for using bold - comments seem to overlook this result though)
How can I get such an error from printing ? (either to LPT1 or FILE: port)
I have tested the code by saving to a bitmap the exact contents I am trying to send to he spooler, the bitmap was created correctly.
...I apologize for not including more code, it is available at the link I posted above... Windows Driver Kit (WDK) 8.1 Samples
Windows Driver Kit (WDK) 8.1 Samples\OEM Printer Customization Plug-in Samples\C++\bitmap

It seems that, because of a function that was implemented and not disabled, there were two different methods to process image data... I was not aware that each sent their output to the spooler (generating the ERROR_ALREADY_EXISTS... is my guess)
(more precisely, while I did not implement FilterGraphics, but only ImageProcessing, I also should have returned S_FALSE for FilterGraphics in the GetImplementedMethod)

Related

C++ SetupApi SetupDiGetDeviceRegistryProperty SPDRP_DEVTYPE fails

I have C++ code (works well with VS6 up to VS2017) that enumerates USB devices and retrieves several properties. I recently added SPDRP_DEVTYPE:
SetupDiGetDeviceRegistryProperty(hDevInfo, &DevData, SPDRP_DEVTYPE, 0L, (BYTE*) &dwData, 4, 0);
The call returns with 'false' and GetLastError() then returns 13 ("The data is invalid"). The same happens when trying to query for SPDRP_CHARACTERISTICS.
Most other PropertyKey values I have tried work well (for example, SPDRP_CAPABILITIES, SPDRP_PHYSICAL_DEVICE_OBJECT_NAME, SPDRP_FRIENDLYNAME, and so on) but these two keep failing.
Running the EXE as administrator does not change anything. I tested on Windows 7 (32/64) and on Windows 10.
In addition, I tried to open the device with CreateFile (which succeeds) and then use DeviceIoControl(), but every call to DeviceIoControl fails with Error 50 "not supported"
Any idea why these calls are not working?

Error loading cr2 with edsdk

I am trying to read cr2 images using canon sdk (canon_edsdk-2.12).
I seem to be loading the dll correctly, but when I try to get the actual image, I get an error.
I tried to run the sample program to see how that is different than mine, but the same thing happens.
Trying to look for the issue on the web, I found the actual source code of the sample: http://read.pudn.com/downloads107/sourcecode/graph/texture_mapping/440409/RAWDevelop/RAWDevelopDlg.cpp__.htm
My error, on the given source, is in the void CRAWDevelopDlg::LoadImage() function -
err = EdsGetImage( m_ImageRef , source , kEdsTargetImageType_RGB , rect , size , DstStreamRef );
if( err == EDS_ERR_OK ) {...}
else
{
AfxMessageBox("The error occurred with the EdsGetImage function.");
}
The above (on line 481 on the page) is the same method that I use, and i get the same error - with error code 35 (instead of 0).
The error seems to be
#define EDS_ERR_FILE_OPEN_ERROR 0x00000023L
So... could there be something wrong with the files ? I experimented with files taken by different versions, including the newest cameras... The files open in Photoshop... And the demo does show header information, as it gives the error. So it can see something.
Am I missing anything ?
All the required dll's used are on the system path...
Thank you.
Old question, still, might help someone:
To open a raw file with the SDK you need to call these functions (you should check for errors, of course):
EdsStreamRef stream = NULL;
EdsImageRef imgRef = NULL;
EdsCreateFileStream("filename", kEdsFile_OpenExisting, kEdsAccess_Read, &stream);
EdsCreateImageRef(stream, &imgRef);
EdsRelease(stream);
Then you can set and get properties with the imgRef.
To save the image as jpg/tiff/RGB image use EdsSaveImage function.

C++ injection problems

I am having some C++ injection dificulties.
I am using Win 7 x64, VS 2010
Here is the complete code I am trying to run:
http://pastebin.com/avKS3r22
My questions:
Line 62.
dwSize = (DWORD)iCodeEnd - (DWORD)iCode; //subtract the function from the limiter to obtain the function's size
Why is dwSize equal to 4294966986 (I think it is the max value for DWORD) when it should be 224 or 0xE0 if iCodeEnd is 0x01151570 and iCode is 0x01151490? Are there any specific properties I need to set for my project (I created an empty win32 project without Unicode)?
Line 92.
if(!(hRemoteThread = CreateRemoteThread(hProcess, NULL, 0, HREAD_START_ROUTINE)lpAddr, prmAddr, 0, NULL)))
If I manualy set dwSize to 224, I get a "Couldn't create remote thread!". Am I wrong about the value of dwSize? Or is it something else?
Please note:
This is my first C++ application (please provide more detailed answers). The code is not mine, I just rewrote it to learn the basics. The original version is working fine under my platform.
Making iCodeEnd and iCode both static makes the compiler place the functions in memory one
after another. This fixes the dwSize to be just right.
On win7 injecting into processses from the \windows\system32 folder such as notepad fails with "Access denied" error (even with UAC disabled).

wglCreateContext GetLastError() 0xc007001f

I have an application that opens many windows. Sometimes, I get wglCreateContext() returns 0 and GetLastError() returns 0xc007001f.
It happens on Intel graphic cards only.
Did someone see it? Someone knows what it is?
You can decompose the error code into its parts. 0xC makes it a fatal error, 007 produces facility code 7 which is the winapi. Which makes the last four digits Windows error 31:
//
// MessageId: ERROR_GEN_FAILURE
//
// MessageText:
//
// A device attached to the system is not functioning.
//
#define ERROR_GEN_FAILURE 31L
Which makes it a pretty basic device driver kind of problem, assuming you passed a correct device context handle to wglCreateContext(). The kind that typically requires a video driver update and ensuring that the right kind of OpenGL driver is installed. Nothing you can do to fix of course, this is a problem that the user needs to tackle.
I believe error 0xc007001f is when SetPixelFormat() fails. Which means, you are trying to use some feature in the pixel format that isn't supported by that card. If I'm not mistaken, Intel graphics cards barely support OpenGL (only [EDIT: 2.1]).
Also you can use FormatMessage to get string for error description:
DWORD err = GetLastError();
char* msg;
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER, 0, err, 0, (LPCSTR)&msg, 0, 0);
MessageBoxA(0, msg, "Error", 0);
LocalFree(msg);

Failed to programmatically uninstall a font in Windows CE

I would like to programmatically uninstall and delete 'simsun.ttc' font collection from '\Hard Disk\Fonts' on WinCE 5. I try to use RemoveFontResource() function but it fails and the last error is (0x2) (The system cannot find the file specified). I definitely know that the file is present.
...
BOOL res = RemoveFontResource(L"\\Hard Disk\\Fonts\\simsun.ttc");
DWORD err = GetLastError(); // 0x2
...
What is the problem?
Did you install the font, or did it come in the OS? If it came in the OS (which is likely) then you probably can't delete it. Why would you want to? Are you trying to save space? If so, get a new OS image without the font in it.