|
Personally i avoid the use of the tag property at all costs.
Many people seem to disagree with me on that one but unless you have complete control over your controls (and a bloody good memory)there is always the risk that some wee-beastie is going to swap out your expected data with their own.
Not to mention its an object type and my general rule of thumb is 'if you find yourself declaring something as object, take a step back and check if you designed it right'
A better solution can usually be found through subclassing or extension methods at the very least (although, ofc, never quite as quick to write :P)
|
|
|
|
|
I mostly agree with your point in general, however there is nothing I would do (or not do) at all costs, every decision is based on a balance of costs vs benefits (both current and foreseeable).
I don't mind subclassing when I need added or altered behavior. For a single parameter, I do use the Tag, as that has been its purpose all along (and I often regret other built-in classes don't offer a similar feature). Furthermore, the degree of sophistication in my answers depends on the style of the original question.
Now if all people were like you, me using the Tag property would be quite safe.
|
|
|
|
|
cycle(f); <-- Here it is!
|
|
|
|
|
But f will change during if block and when become 0 ,cycle(0)run return;
|
|
|
|
|
Hi there
I am currently looking for help in writing a C# application that would 'trick' the OS into thinking there is a USB device connected. I would like to know if this is even possible and whether it is even possible in C#.
Well, I'll explain in greater detail what I am trying to do. The company I work for has bought software that interfaces with USB devices (Smart card readers), we develop smart cards, and we also have several applications that simulate smart cards to test with. It would help us a lot if it was possible to let the software we bought interface with our simulators instead of the smart card readers. This is unfortunately not possible, their software can't be configured to communicate with anything other than smart card readers.
I am hoping it is possible to create an application that is a virtual smart card reader, and this application would relay all the data their software sends to the virtual card reader to our simulator. (is this possible or am I living in a dream world?? which I tend to do a lot ). If this is possible, can it be done in C# or will I have to use WIN API calls?
I have found many C# projects that have classes to communicate with USB devices, but I have not found any that emulates a USB device. Any help will be greatly appreciated or if you can point me to reading material regarding the matter, that will also help me a lot.
Regards
Riaan
KOM UIT DAAAAA!!!
|
|
|
|
|
I am not sure but this[^] might be useful. (I think it's the reverse way...)
|
|
|
|
|
Hi, thanks for the reply. That project looks very interesting, however it seems like they use a cellphone or some other mobile device that runs the emulation software, it seems like it is only a replacement for an actual smart card reader, so this is not exactly what I am looking for.
thanks for the reply though.
KOM UIT DAAAAA!!!
|
|
|
|
|
There exist some virtualization softwares which let you access USB devices connected to a different computer as if they were connected to your local computer, e.g. http://www.fabulatech.com/usb-over-network.html[^]. Hence I think that your emulator should be possible, as the virtualization software somehow pretends the presence of a local USB device. But I do not know how to write it.
|
|
|
|
|
Thanks for the Reply.
I actually stumbled onto the same program, so I am also convinced it must be possible, but how remains the big question
KOM UIT DAAAAA!!!
|
|
|
|
|
I had a similar problem a few years back.
The solution I came up with was to access the card reader through a DLL. For automated testing the DLL was replaced with a test version that allowed virtual smart card "images" to be inserted/removed (data stored in files one per virtual card). This also allowed testing without someone physically swapping cards.
Of course you need to ensure that the release code can't be duped into accepting a test DLL+virtual card.
|
|
|
|
|
This is an interesting approach to the problem I am having. I found C# libraries to interact with existing devices, I could try to forward all the Data that is sent to a card reader to our simulator. It's kind of a hack but it could work!
Thanks for the reply!
KOM UIT DAAAAA!!!
|
|
|
|
|
Good Morning,
The reason I have prefaced this with "again" is that although I have found numerous articles on this in Code Project, I have yet to see this problem resolved with a clear answer or a suggestion as to what the problem might be (or I cannot find it). So, it's my turn in the barrel...I am trying to add an Excel reference (seems simple enough) to my application (VS 2010), and I have tried to add it from both the .NET (Microsoft.Office.Excel) and COM tabs (Microsoft.Office.Interop.Excel) under Add Reference. I have also added the Microsoft.Office.Core Excel Object (12.0). I have tried each individually and all simultaneously and each time I get the familiar error (Error 1 The type or namespace name 'Excel' could not be found (are you missing a using directive or an assembly reference?). This was done as per the instructions of a great article on Code Project by Geek13 that begins with the code
Excel.ApplicationClass ExcelApp = new Excel.ApplicationClass();
The article heading is as follows:
Exporting a DataGridView to Excel in .NET 2.0 (C# code)
Author: Geek13
If there is some other prerequisite that I need or (???), please let me know. Thank you for your attention....Pat
|
|
|
|
|
You should always add from the .NET tab. Also, you probably need to add a using Microsoft.Office.Core or something of that sort to bring the Excel namespace into scope.
|
|
|
|
|
Hammer,
Thank you for your reply. FYI...I did delete all COM references to Excel and I had already added the MSFT Core, but it still did not work. Apparently, there was a problem with different versions that were added for each reference to Interop (V11.0 vs v14.0), and this was due to the fact that the article was based on VS2.0. So I needed to change the references, make them the same, and then find the new path to the application (old was ApplicationClass and new was just .Application). However, the problem was definitely found in the area that you suggested I look. Thanks for the help....much appreciation. I have marked your answer as correct. Best Regards, Pat
|
|
|
|
|
How do I know which files on the system have different level of privileges. For example, if the 'at.exe' runs from the command prompt to open cmd.exe then the new cmd.exe has been given system privilages
Is there any way to dump the level of privileges to a text file. I managed to get the application descriptions to a listview, now just trying to get their security levels.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace FileDescription
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
GetFileDescription();
}
private void GetFileDescription()
{
string[] fileInfo = Directory.GetFiles(Environment.SystemDirectory);
foreach (string str in fileInfo)
{
if (str.ToString().Contains(".exe"))
{
ListViewItem lvi = new ListViewItem();
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(str);
lvi = lv.Items.Add(str);
lvi.SubItems.Add(myFileVersionInfo.FileDescription);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
lv.Columns.Add("File",200,HorizontalAlignment.Left);
lv.Columns.Add("Description",400,HorizontalAlignment.Left);
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start(lv.SelectedItems[0].ToString());
}
}
}
Thats what I turned out with.
|
|
|
|
|
Files don't have privileges, users have privileges.
A standard user and an admin could both start instances of the same program file, but the admin instance will have all the admin privileges, and the other will have only standard user privileges.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi.
First, how would I create a random number, and then add the last digit, so that it is divisable by 5?
the number should always be 5 digits long.
Second, how do I check it, I think I need to do something like...
if (int x MOD 5 ==0)
Or something like that.
The first step is the most important though.
Thank you,
Steve
|
|
|
|
|
a random multiple of five is bound to be five times some other random number.
|
|
|
|
|
Luc Pattyn wrote: a random multiple of five is bound to be five times some other random number.
?
What do you mean?
Regards,
Stephen
|
|
|
|
|
What Luc meant was that you should just create a random integer number and the go and multiply it by five. This will always give you a number which is divisible by 5, to state the obvious.
The only thing I would add is if you are given a range in which the numbers should lie you'd need some adjustment.
Random rnd = new Random();
int lowerBound = 2001;
lowerBound = lowerBound + ( 5 - lowerBound % 5 );
int upperBound = 10023;
upperBound = upperBound - ( upperBound % 5 );
int range = (upperBound - lowerBound) / 5;
int number = lowerBound + rnd.Next( range ) * 5;
Cheers!
—MRB
"With sufficient thrust, pigs fly just fine."
Ross Callon, The Twelve Networking Truths, RFC1925
|
|
|
|
|
surely the generated number would exceed the upper bounds:
upper bound = 10023
modded down to 10020
random number generated between lower bound and modded upper bound = anything upto 10020
10020 * 5 = 50100
50100 > 10023
perhaps divide the bounds by 5 first
|
|
|
|
|
Stating the obvious! 5+
"With sufficient thrust, pigs fly just fine."
Ross Callon, The Twelve Networking Truths, RFC1925
|
|
|
|
|
I'd say you're stating the obvious, but then, I remember when I was very young and inexperienced and I couldn't see stuff like this. So, it's not always obvious as one might think.
You got my five.
"To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson
|
|
|
|
|
I tend to state facts, even obvious ones, especially when it seems to OP is missing them somehow. Rather than spoon feeding, I prefer to give a gentle push in the right direction...
|
|
|
|
|
Completely agree, I'm totally against the "gimme codezzzz plz" culture.
"To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson
|
|
|
|