MagneticStripeReader.GetDefaultAsync(); returns null - c#

I have a usb connected MSR reader and i am trying to get it by using the sample codes proveded in here. This works fine but the problem is when i add the same code to my app it doesn't work. GetDefaultAsync returns null.
private static MagneticStripeReader _reader = null;
public static async void StartRead()
{
if (await CreateDefaultMagneticStripeReaderObject())
{
....
}
}
private static async Task<bool> CreateDefaultMagneticStripeReaderObject()
{
if (_reader == null)
{
_reader = await MagneticStripeReader.GetDefaultAsync();
if (_reader == null)
return false;
}
return true;
}
My code is like above, very similer to sample but it doesnt work. Also i've added the device capability of pointOfService. So that is not the case.

I was in the exact same situation and I spent the last 5 hours, finally I know what was going on. You are missing a capability in the Package.appxmanifest
'pointOfService' is the capability you want to include. This capability does not show in the UI and therefore I could not find any difference between my broken project and Microsoft's sample project. You can not add that capability using the UI. You have to manually add it by modifying the XML file.
The sample project by Microsoft have it too
https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/MagneticStripeReader/cs/Package.appxmanifest#L53

Make sure the card reader is in HID mode and not Keyboard emulation mode. That was one of my problems.
To do this is really wonky. MagTek has a ActiveX control on their website to assist us... because ActiveX is awful, you can only use it with InternetExplorer (it won't even work with Edge.)
go here in IE: https://www.magtek.com/changemode/
Enable active X when it pops up, and you can change from hid to keyboard and back.

Related

Can't connect a midi output device to .net MAUI using DryWetMidi

I am using the library DryWetMIDI for .net 7 and I am trying to connect a MIDI output device to MAUI. When I connect a input device it seems to work fine but the only output from the outputdevice I could get was the following error: Internal error (OUT_SENDSHORTRESULT_INVALIDHANDLE). When I tried everything in a simple console application it works perfectly.
Also because of my lack in experience in Maui I don’t really know if I should change something in the project dependencies or in the builder. Or maybe declare the MIDI in the App or the Appshell...
So I tried to create a input device and a output device and connect them to eachother (This is what the DryWetMIDI suggested). Next I try to get the events from the input and the outup device, the input device works but the output device doesnt.
I use the following code where the ouput device doesnt work in Maui:
private InputDevice inputDevice;
private OutputDevice outputDevice;
private DevicesConnector devicesConnector;
void ConnectMidi()
{
//create input device
inputDevice = InputDevice.GetByName("Keystation Mini 32");
inputDevice.EventReceived += OnEventReceived;
//create ouput device;
outputDevice = OutputDevice.GetByName("Microsoft GS Wavetable Synth");
outputDevice.EventSent += OnEventSent;
//connect them
devicesConnector = inputDevice.Connect(outputDevice);
inputDevice.StartEventsListening();
}
public void OnEventReceived(object sender, MidiEventReceivedEventArgs e)
{
var midiDevice = (MidiDevice)sender;
Debug.WriteLine("This gets called when a key is pressed") ;
}
public void OnEventSent(object sender, MidiEventReceivedEventArgs e)
{
var midiDevice = (MidiDevice)sender;
Debug.WriteLine("This gets never called");
}
If there is anohter solution using a diffrent library or something else I would love to hear it!
Hopefully this makes my problem clear and thanks in advance.
(This is also my first post so feedback would also be nice)
I'm the author of the DryWetMIDI. I've analyzed the problem:
The bug is not with the library, it's a MAUI related one.
The error comes from midiOutOpen system Windows function which fails for Microsoft GS Wavetable Synth in a MAUI project but works for any other project types.
I've reported the bug in MAUI repo: https://github.com/dotnet/maui/issues/12368. So what we have is to wait for response from Microsoft.
Update:
The bug has been moved to WinUI repo: https://github.com/microsoft/microsoft-ui-xaml/issues/8055. Also you can mark your project as Unpackaged and the issue should go away.

KnownFolders.GetFolderAsync never returns in .NET Core 5

I am using Uno Platform to make an app which access a specific folder inside the user's Documents library from a game (BeamNG.drive). I want the app to read all the mod files inside this folder to be able to edit and display them to users on startup. I installed the Nito.Mvvm.Async Package to help me bind everything to the UI.
Here's part of the method that loads the mod files from the Documents folder:
public static async Task<List<Mod>> GetModList()
{
StorageFolder documents = await KnownFolders.DocumentsLibrary.GetFolderAsync("BeamNG.drive");
IReadOnlyList<StorageFile> fileList = await documents.GetFilesAsync();
List<Mod> foundModsList = new();
foreach (StorageFile file in fileList)
{
//...
}
return foundModsList;
}
Here's the code on MainPage.xaml.cs inside the Shared project in my solution, based on code from this answer
public NotifyTask<ObservableCollection<Mod>> ModsData { get; }
public MainPage()
{
InitializeComponent();
ModsData = NotifyTask.Create(InitModData());
}
private static async Task<ObservableCollection<Mod>> InitModData()
{
return new(await ModManager.GetModList());
}
The GetModList() method is called, but the GetFolderAsync("BeamNG.drive") method never returns, and the app keeps running normally (not UI freezes or anything). If I add a breakpoint in that line, Visual Studio stops there normally. But if I press "Step Over", instead of continuing on that method, VS jumps to this line...
return new(await ModManager.GetModList());
...then this one:
ModsData = NotifyTask.Create(InitModData());
Using ConfigureAwait(false) in any of the calls using await doesn't help anything. I'm really not sure what is going on and I suspect that Nito.Mvvm.Async might have something to do with it (considering its last update was in 2017) but I'm really not sure.
From your question it seems this problem occurs under .NET 5 - meaning targeting WebAssembly or Skia targets of Uno Platform. Under Uno, the KnownFolders type is not yet supported, so accessing DocumentLibrary is not possible. If you want to have this supported, please file an issue on Uno Platform GitHub.
In case of UWP, to access the Documents library, you need to declare a special capability in app manifest (see Docs). However, it is a restricted capability and it is quite likely that if you utilize it, the app will not pass Microsoft Store certification. Instead, it is recommended to use FolderPicker instead and let the user decide on the location when files are stored, or to use ApplicationData.Current.LocalFolder to store the data for the app privately.

Saving Modules correctly using Access-Interop

Even though my last questions weren't accepted well, I will give it another try.
I'm working on a program that is capable of controlling a lot of office-application behaviour by using the COM/Interop-Interface Microsoft provided for Word/Access/Excel. Still some functions differ from each other in the way that they are kept specific for the program that gets addressed.
My ambition is to Insert Macro-Code to an existing Access-Database and run the code while the Database is open and delete the code before the Database closes down. Partially this works as wished by using following C# code:
VBProject found = null;
Access.Application currApplication = this._currentInstance.Application;
if (target.Equals("") || scriptText.Equals(""))
return false;
foreach (VBProject vb in currApplication.VBE.VBProjects)
{
if (currApplication.CurrentDb().Name.Equals(vb.FileName))
{
found = vb;
break;
}
}
if (found != null)
{
foreach (VBComponent foundComponent in found.VBComponents)
{
if (foundComponent.Name.Equals(target))
{
return true;
}
}
VBComponent module = found.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule);
module.Name = target;
module.CodeModule.AddFromString(scriptText);
return true;
}
else
{
return false;
}
Now in particular, Access makes a diversion between VBA-Code-Modules which are visible in the Code-Editor and Modules which are loaded into the Database itself. For inserting the Module into the Database, it needs to be saved another time. When using the GUI, there's a window that popsup and asks for the Name to be used when saving it into the DB. It already takes the correct one etc. and it's fine after doing it by hand.
Besides the manual solution I found no way to do this step programatically.
Initial thoughts were:
currApplication.DoCmd.OpenModule(target, Type.Missing);
currApplication.DoCmd.Save(Access.AcObjectType.acMacro, target);
or
found.VBE.ActiveVBProject.SaveAs("");
The only two methods I could imagine would be doing the step I wanted. VBE in it's new .NET compatible form is documented very bad. Methods that would have applied to the native version are not guilty anymore. So I'm stuck with it now.
In case someone asks, why would you save the module at all, because once it's inserted in VBE it can be run like any other module listed in Access also, that's true, but for some unknown reasons this seems to be more fault-prone then to save it twice. Got runtime errors (like 2501) while launching the macro, which is not the case when it's saved properly.
Keeping it forever in the Access-Databases would be the last option but since those are many MDBs and thus they are changing frequently, I thought it would be nice to have it dynamic.
Hope somebody understands what I wrote here, (not so easy for me), and is enabled to help somehow :)
Thanks for all the reading. Looking forward for some good results, from the best community, hehe.

Simulating purchase in Windows Store

I have a strange problem with in-app purchase in Windows Store App.
When I upload app to the Store I see a pop-up like this:
But when I run in on my local machine, from release mode and using CurrentApp
everything seems to be OK, I see checking price in Store:
Also the funny thing is that there is no difference when I am using CurrentApp or CurrentAppSimulator.
Please tell me what am I doing wrong?
Code for checking is commonly known:
public async Task<bool> IsPurchased(string featureName)
{
var applicationInformation = CurrentApp.LicenseInformation;
if (applicationInformation.ProductLicenses[featureName].IsActive)
{
return true;
}
else
{
await CurrentApp.RequestProductPurchaseAsync(featureName);
return applicationInformation.ProductLicenses[featureName].IsActive;
}
}
I had to delete all content from bin folder, clean solution and rebuild it.
Aftere these operation everything works OK.

Vista TaskDialog Wrapper: Unable to find an entry point named 'TaskDialogIndirect' in DLL 'ComCtl32'

I'm try to use Vista TaskDialog Wrapper and Emulator and I'm getting the following exception:
"Unable to find an entry point named 'TaskDialogIndirect' in DLL 'ComCtl32'."
...in a simple Console application:
class Program
{
[STAThread]
static void Main(string[] args)
{
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
PSTaskDialog.cTaskDialog.MessageBox(
"MessageBox Title",
"The main instruction text for the message box is shown here.",
"The content text for the message box is shown here and the text willautomatically wrap as needed.",
PSTaskDialog.eTaskDialogButtons.YesNo,
PSTaskDialog.eSysIcons.Information
);
}
}
What am I doing wrong?
UPDATE:
Actually, I'm working on an Excel plugin using excel-dna. How can I control what dll Excel loads?
http://exceldna.codeplex.com/discussions/286990#post728888
I haven't been at Office programming in a while, but my guess is that Excel loads both versions of comctl32, so you may need to use the Activation Context API to direct your code to the version that includes TaskDialog. Some ideas for fixing the problem (not solutions as such):
For test purposes, make a temporary enumeration of all modules in the active process - just to check if 6.10 is actually loaded (see below for a simple example of such an enumeration, albeit with a different intent).
Use the Activation Context API to get to the right version. Example of use from C# (for enabling themes by way of comctl32 6.0) here.
Alternatively (I never actually got this to work reliably in a WPF application I worked on), make a dialog abstraction class, which falls back to MessageDlg depending on the version available to you. There may be better ways of doing the check, but...:
FileVersionInfo version = ProcessUtils.GetLoadedModuleVersion("comctl32.dll");
if (version != null && version.FileMajorPart >= 6 && version.FileMinorPart >= 1)
{
// We can use TaskDialog...
}
else
{
// Use old style MessageBox
}
The enumeration of modules:
internal static FileVersionInfo GetLoadedModuleVersion(string name)
{
Process process = Process.GetCurrentProcess();
foreach (ProcessModule module in process.Modules)
{
if (module.ModuleName.ToLower() == name)
{
return module.FileVersionInfo;
}
return null;
}
}
In addition to what all the others are saying: This error will disappear if you set the ForceEmulationMode on PSTaskDialog to true.

Categories

Resources