Exception from HRESULT: 0xFFFFFFF8 - c#

I keep getting this error in my controller during verification of fingerprint. And I can't seem to understand why. I'm using digitalPersona SDK Fingerprint reader, asp.netc#. I already tried googling but with no success. T_T
This is my codes in my controller
void verificationControl_OnComplete(object Control, DPFP.FeatureSet FeatureSet, ref DPFP.Gui.EventHandlerStatus EventHandlerStatus)
{
clearInfoBoxTimer.Stop();
DateTime entryTime = DateTime.Now;
DPFP.Verification.Verification ver = new DPFP.Verification.Verification();
DPFP.Verification.Verification.Result res = new DPFP.Verification.Verification.Result();
employee employees = null;
foreach (fingerprint fingerPrint in this.db.fingerprints)
{
DPFP.Template template = new DPFP.Template();
template.DeSerialize(fingerPrint.data);
ver.Verify(FeatureSet, template, ref res); //I GETTING AN ERROR HERE
if (res.Verified)
{
employees = fingerPrint.employee;
break;
}
}
}
Full Error:
System.Runtime.InteropServices.COMException (0xFFFFFFF8): Exception
from HRESULT: 0xFFFFFFF8
at DPFP.Verification.Verification.MC_verifyFeaturesEx(SafeHandle
mcContext, Int32 templateSize, Byte[] templatePt, Int32
featureSetSize, Byte[] featureSet, Int32 reserved0, IntPtr reserved1,
IntPtr reserved2, IntPtr reserved3, Double& achievedFar)
at DPFP.Verification.Verification.Verify(FeatureSet FeatureSet, Template Template, Int32 FARRequested)
at DPFP.Verification.Verification.Verify(FeatureSet FeatureSet, Template Template, Result& Result)
at Timee.BundyForm.verificationControl_OnComplete(Object Control, FeatureSet FeatureSet, EventHandlerStatus&
EventHandlerStatus) in
C:\Users\MyName\Desktop\Time\Timee\BundyForm.cs:line 79
at DPFP.Gui.Verification.VerificationControl.<>c_DisplayClass2.b_0()
Does anyone knows why I'm getting this error? or perhaps knows something about the error and share it? Thank you.

Well ... I had that problem today, but the detail was that I was comparing the features with an '' in the database, i change the '' by a null value and voilà

I'm not really sure about this but I think my error has something to do with the datatype that I use. I use previously binary(255) to insert a long binary fingerprint data in mysql. I think binary(255) is not enough to store the long binary value of fingerprint.In my previous server which is sql server, I use binary(1632) to store the fingerprint binary data. So I changed it to BLOB datatype. So now it doesn't get an error.

Related

C# LoadImage returns error 1813

I try to load an image from imgres32.dll. I'm trying to do it like this:
Load the dll:
dll_h = LoadLibrary(#"C:\Windows\System32\imgres32.dll");
Pass the handle to my function which does the ressource loading:
Bitmap b = GetImageResource(dll_h, "1002");
The function looks like this:
static Bitmap GetImageResource(IntPtr handle, string resourceId)
{
IntPtr img_ptr = NativeMethods.LoadImage(handle, resourceId, IMAGE_BITMAP, 0, 0, 0);
if (img_ptr == IntPtr.Zero)
throw new System.ComponentModel.Win32Exception((int)NativeMethods.GetLastError());
return Image.FromHbitmap(img_ptr);
}
No matter which parameters I enter, I always get error code 1813 meaning
The specified resource type cannot be found in the image file.
When I open the file in Visual Studio, I see a folder called Icon containing an Image with id 1002.
When I click it, it shows me several Bitmap images contained, in different resolutions, containing one with resolution 16 x 16. But when I call
LoadImage(handle, resourceId, IMAGE_BITMAP, 16, 16, 0);
Neither this not any other parameter combination does work, I always get error 1813.
IMAGE_BITMAP is a constant int set to 0 like documented here, same with IMAGE_ICON and IMAGE_CURSOR but none of them works.
Help is very much appreciated. Thanks.
You should prefix the resource Id with #. Call it this way:
GetImageResource(dll_h, "#1002");

How to get a list of all Windows Event Logs (Event Viewer Logs) with their hierarchy and friendly names in C#

I'm trying to replicate the following from the Event Viewer:
I'm having trouble with a few things.
Some of the names I get back are not the display names or friendly names. For example, for "Microsoft Office Alerts" I just get back "OAlerts". How can I get the full "Microsoft Office Alerts" from "OAlerts"?
Figuring out the hierarchy. It seems all I can do is parse out the dashes and do some sort of a best guess. There doesn't seem to be an easy way in the API to figure it out. The GetLogNames just gives you a flat list of all the logs
EventLogSession session = new EventLogSession();
List<string> logNames = new List<string>(session.GetLogNames());
foreach (string name in logNames)
{
//EventLogConfiguration config = new EventLogConfiguration(name); //looks useful but doesn't give me any of the info i'm looking for.
Console.WriteLine(name);
}
This blog here: The EventSource NuGet package and support for the Windows Event Log (Channel Support) has a link to a rare EventSource User's Guide document that states this:
Do use the EventSourceAttribute’s Name property to provide a
descriptive, qualified name for the ETW event provider represented by
your event source. The default is the short name of your event source
type, which can easily lead to collisions, as ETW provider names share
one machine-wide namespace. An example of a good provider name
“<CompanyName>-<Product>-<Component>”. Following this 3-element
convention will ensure Event Viewer displays your event logs in a
logical folder hierarchy: “Application and Services
Logs/<CompanyName>/<Product>/<Component>”.
Which tends to indicate the dashes are more a convention than a strict requirement (So I believe you can parse it by yourself). Note the blog is still open for comments.
As for names that don't match, there is an undocumented EvtIntGetClassicLogDisplayName function that can get you the name displayed in Event Viewer. Here is how to use it with a session and a log name:
static void Main(string[] args)
{
var session = new EventLogSession();
foreach (string name in session.GetLogNames())
{
Console.WriteLine(GetDisplayName(session, name));
}
}
And here is the support code (since it's undocumented, use at your own risks, plus it seems to be useful mostly for this 'OAlert' entry, so I'm not sure it's worth it):
public static string GetDisplayName(EventLogSession session, string logName)
{
var sb = new StringBuilder(512);
int bufferUsed = 0;
if (EvtIntGetClassicLogDisplayName(GetSessionHandle(session).DangerousGetHandle(), logName, 0, 0, sb.Capacity, sb, out bufferUsed))
return sb.ToString();
return logName;
}
private static SafeHandle GetSessionHandle(EventLogSession session)
{
return (SafeHandle)session.GetType().GetProperty("Handle", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(session);
}
[DllImport("wevtapi.dll", CharSet = CharSet.Unicode)]
private static extern bool EvtIntGetClassicLogDisplayName(IntPtr session, [MarshalAs(UnmanagedType.LPWStr)] string logName, int locale, int flags, int bufferSize, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder displayName, out int bufferUsed);

Why am I getting a Bad Data exception only 5% of the time?

I have the following code which is throwing a CryptographicException about 5% of the time and I can't figure out why a) it doesn't fail consistently and b) why it's failing at all:
// Initialize the new secure keys
var keyGenerator = KeyGenerator.Create();
var keyPair = keyGenerator.GenerateKeyPair();
this._privateKey = keyPair.ToEncryptedPrivateKeyString(privateKeySecret);
this._publicKey = keyPair.ToPublicKeyString();
// Initialize the certificate generation
var certificateGenerator = new X509V3CertificateGenerator();
var serialNo = BigInteger.ProbablePrime(128, new Random());
certificateGenerator.SetSerialNumber(serialNo);
certificateGenerator.SetSubjectDN(GetLicenseeDN());
certificateGenerator.SetIssuerDN(GetLicencerDN());
certificateGenerator.SetNotAfter(DateTime.Now.AddYears(100));
certificateGenerator.SetNotBefore(DateTime.Now.Subtract(new TimeSpan(7, 0, 0, 0)));
certificateGenerator.SetSignatureAlgorithm("SHA512withRSA");
certificateGenerator.SetPublicKey(keyPair.PublicKey);
var result = certificateGenerator.Generate(keyPair.PrivateKey);
this._clientCertificate = new X509Certificate2(DotNetUtilities.ToX509Certificate(result));
this._clientCertificate.PrivateKey = DotNetUtilities.ToRSA((RsaPrivateCrtKeyParameters)keyPair.PrivateKey);
The stack looks like:
System.Security.Cryptography.CryptographicException: Bad Data.
Result StackTrace:
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.Utils._ImportKey(SafeProvHandle hCSP, Int32 keyNumber, CspProviderFlags flags, Object cspObject, SafeKeyHandle& hKey)
at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters(RSAParameters parameters)
at Org.BouncyCastle.Security.DotNetUtilities.ToRSA(RsaPrivateCrtKeyParameters privKey) in C:\BouncyCastle\crypto\src\security\DotNetUtilities.cs:line 173
at EBSConnect.EBSClientBase.InitializeSecurity(String privateKeySecret) in c:\Projects\EBSConnect\Source\EBSConnect\EBSClientBase.cs:line 78
The rest of the time (95%), this code works as expected and I'm able to communicate with a federated service using this dynamically generated certificate. Any ideas?
Assuming you are using BouncyCastle C# 1.7, there were some problems with the conversion from BigInteger to byte[] (to do with leading zeroes). These have been fixed in the source code, but not yet released. I suggest making a local copy of the latest DotNetUtilities class and using that in your project until a new release is available.

MathType in C# (OLE)

I'm trying to run a MathType in a C# app... using OLE in forms to signify the equations/images.
This is how I started with the code.
I got the CLSID object for math type equation. I create a new instance and run a verb to start Math Type. This works good until I try to set or get data of the IDataItem attribute I have.
Code:
string progID = "Equation.DSMT4";
comRetVal= CLSIDFromProgID(progID, out eqContainerGUID);
Type t = Type.GetTypeFromProgID(progID); //ok-> MT6 Equation
Object instance = Activator.CreateInstance(t);
IDataObject oleDataObject = instance as IDataObject;
MTSDKDN.MathTypeSDK.IOleObject oleObject = instance as IDataObject;
//run verb Run For Conversion - I'm not sure what this verb does
oleObject.DoVerb(2, (IntPtr)0, activeSite, 0, (IntPtr)this.Handle, new MathTypeSDK.COMRECT());
//up to here everything is find
//Now say I want to put a MathML string into the IDataObject
//set format
formatEtc.cfFormat = (Int16)dataFormatMathMLPres.Id; //<-this overflows. I verified that the only format that works is Presentation MAthML
formatEtc.dwAspect = System.Runtime.InteropServices.ComTypes.DVASPECT.DVASPECT_CONTENT;
formatEtc.lindex = -1;
formatEtc.ptd = (IntPtr)0;
formatEtc.tymed = TYMED.TYMED_HGLOBAL;
//set medium
ConnectSTGMEDIUM stgMedium = new ConnectSTGMEDIUM();
string mathEqn = "<math><mi>x</mi></math>";
stgMedium.unionmember = Marshal.StringToHGlobalAuto(mathEqn);
stgMedium.pUnkForRelease = 0;
//if now i write the equation to console from STGMEDIUM i see that after each char there is a null. Is this normal?
//now I try to set data in IDataObject and the OLE object
//I thought this set the data of the ole object to the MathML string I put in STGMEDIUM
oleDataObject.SetData(ref formatEtc, ref stgMedium, false);
The app now crashes with this exception:
System.Runtime.InteropServices.COMException was unhandled Message="Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))" Source="System" ErrorCode=-2147221404 StackTrace: at System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& format, STGMEDIUM& medium)
I'm not sure what this means, but I think it might have to do with
formatEtc.cfFormat = (Int16)dataFormatMathMLPres.Id;
because that ID is 50000 and does not fit in a short (cfFormat is a short) so it overflows to something like -15000.
I have solved similar issue by converting it from unsigned to signed value. it means that if the value (dataFormatMathMLPres.Id) is grater than 32767. Use (dataFormatMathMLPres.Id - 65536) instead. It will fit signed short.

How to get current Windows theme name?

I am trying to get the current Windows theme name in C# but it has turned out to be a little tougher than expected. I have a code sample from MSDN:
public void Test()
{
StringBuilder themeFileName = new StringBuilder(0x200);
GetCurrentThemeName(themeFileName, themeFileName.Capacity, null, 0, null, 0);
string fileName = Path.GetFileName(VisualStyleInformation.ThemeFilename);
if (string.Equals("aero.msstyles", fileName, StringComparison.OrdinalIgnoreCase))
{
// user is using aero theme
}
}
[DllImport("uxtheme.dll", CharSet = CharSet.Auto)]
public static extern int GetCurrentThemeName(StringBuilder pszThemeFileName, int
dwMaxNameChars, StringBuilder pszColorBuff, int dwMaxColorChars,
StringBuilder pszSizeBuff, int cchMaxSizeChars);
GetCurrentTheme() does not modify the StringBuilder. I also tried looking at the
System.Windows.Forms.VisualStyles.VisualStyleInformation class, but it is full of empty values. Anyone know how to do this? I must be missing something easy, but I haven't found anything yet that works.
That article on CodeProject describes how to get "the current visual style information" (search for that string in the article).
It contains sample code how to do that.
You are not passing the string builder by reference.

Categories