Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win32 Exception

Status
Not open for further replies.

not24

Programmer
Feb 25, 2002
68
US
I had WindowsXP, (all other programs), LeadTools Document Imaging 13.0 installed. Then I reinstalled Windows 2000 Pro, (all other programs), LeadTools Document Imaging 13.0 same as before - just difference OS. I have a C# console application to compress image. It was work fine. When there is no image in the folder, it'd throw exception "file not found" only.

But after I was done with installation, any time I run my program to compress image, I've a pop up from LeadTools say "LEADTOOLS 13.0 Specialized Product Notice...". I assume I enter the right serial number, otherwise it wouldn't let me install, is it?

I don't think there is anything to do with Windows 2000 because my co-worker has Windows 2000 and it's work fine.

My case is this: if the image file not found, I usually have got exception says "file not found" but some time I'd get this error as well:
LEAD.Exception: Win32 Exception
at LEAD.Drawing.Imaging.ColorPalette.CreatePalette(Color[] color)
at LEAD.Drawing.Imaging.ColorPalette.set_Entries(Color[] value)
at LEAD.Drawing.Imaging.Codecs.Codecs..ctor()
at myFunction()...

I have no idea what's Win32 Exception. I tried to search in google, LeadTool document. They didn't explain much. I'm new with C# development. If anybody could give me some idea how to find out or suggest solution, I'd appreciate it.
 
Code:
at LEAD.Drawing.Imaging.Codecs.Codecs..ctor()

i think this is what causes you problems... do you need to have some sort of codecs installed for this?

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Win32Exception is one of the few ExternalException classes that deal with exception types for all COM interop exceptions and structured exception handling (SEH) exceptions.
Win32Exception class manages the exceptions that are thrown for a Win32 error code.
For example, if you try to start an .exe that doesn't exist then a Win32 native error will be thrown.
That code and message can be get using try-catch and inspecting the NativeErrorCode, Message and Source properties of the Win32Exception object.
The following (WIN32 API ::GetLastError() ) were usefull for me to manages the external exceptions:
Code:
[DllImport("kernel32.dll")]
private static extern int GetLastError();
[DllImport("kernel32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
private unsafe static extern
	int FormatMessage( 
	int     dwFlags,
	ref IntPtr  pMessageSource,
	int     dwMessageID,
	int     dwLanguageID,
	ref string  lpBuffer,
	int     nSize,
	IntPtr* pArg);
private unsafe static string GetErrorMessage(int errorCode)
{
	int FMT_ALLOCATE_BUFFER  = 0x00000100;
	int FMT_IGNORE_INSERTS   = 0x00000200;
	int FMT_FROM_SYSTEM      = 0x00001000;

	int     minBufferSize   = 0;
	string  messageBuffer   = String.Empty;
	string  message         = String.Empty;

	int dwFlags = FMT_FROM_SYSTEM | FMT_ALLOCATE_BUFFER | FMT_IGNORE_INSERTS;

	// Initialize pointers.
	IntPtr  pMessageSource  = new IntPtr();
	IntPtr  pArgs		= new IntPtr();

	int langID = 0;
	int messageSize     = 0;
	messageSize = FormatMessage(    dwFlags,
		ref pMessageSource,
		errorCode,
		langID,
		ref messageBuffer,
		minBufferSize,
		&pArg);

	message = String.Format("Error {0}: {1}",errorCode, messageBuffer);

	return message;
}

// How to use:
//...
int lastWin32Error = Marshal.GetLastWin32Error(); // same as NativeErrorCode
int lastError = GetLastError();
string errMsg = GetErrorMessage(lastError);
-obislavu-
 
Thank you, obislavu. I did used your code but it's only return "Error 0: The operation completed successfully".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top