March 28th, 2008
While looking for a full article about this I found out it won’t hurt to have another quick explanation about this process.
Sometimes when creating an application you want some sort of verification about which phone is accessing your service (service-client application). A good way to do this is to use the unique device id.
Now I will explain how we do it, we are going to get a 40 char string that is hashed with an AppString we will provide which will be unique to each and every device, and will be constant for this device and AppString.
First we define the P/Invoke signature:
[DllImport("coredll.dll")]
private static extern int GetDeviceUniqueID([In, Out] byte[] appdata, int cbApplictionData,
int dwDeviceIDVersion,
[In, Out] byte[] deviceIDOuput, ref uint pcbDeviceIDOutput);
Now we are going to define a private static member so we don’t go through the entire process every time we need this and then create it with a public static method:
private static string s_UniqueDeviceID;
///
/// Gets the unique device id, this is an unique id of the phone
/// which is hashed with the AppString
///
/// a 40 characters unique id
public static string GetUniqueDeviceID()
{
if (string.IsNullOrEmpty(s_UniqueDeviceID))
{
// define AppString
string AppString = "MyAppString";
// get the byte array for the string
byte[] AppData = Encoding.ASCII.GetBytes(AppString);
// some parameters for the native call
int appDataSize = AppData.Length;
uint SizeOut = 20;
// our out parameter
byte[] DeviceOutput = new byte[20];
// Call the native GetDeviceUniqueID method from coredll.dll
GetDeviceUniqueID(AppData, appDataSize, 1, DeviceOutput, ref SizeOut);
// check that we got something
if (SizeOut > 0)
{
// build text from received bytes
StringBuilder resultText = new StringBuilder();
for (int i = 0; i < DeviceOutput.Length; i++)
{
resultText.Append(string.Format("{0:x2}", DeviceOutput[i]));
}
// set up result
s_UniqueDeviceID = resultText.ToString();
}
}
return s_UniqueDeviceID;
}
As you can see the AppString can really be whatever we want it to be. the rest is a little work in order to transform it all from bytes to string but that is why we do it only once!
The only important thing I can see about the AppString is that it won’t be null\empty and that it will be constant throughout your application and usage.
Hope this was clear.
Cheers,
Nadav
Tags: c#, imei, native call, P/Invoke, udi, unique device id, WM
Posted in CF.Net, How to, WM, c# | 2 Comments »
March 27th, 2008
It had been a while now that I’m reading about how Microsoft is going down and open-source is going to rule the world. Lately I’ve been giving this issue some thought and wanted to share my conclusions, so here goes:
-
Scattered resources - Microsoft has many(many!) developers\QA\design… people working for them while open-source projects which has the advantage of being able to recruit "all" the developers in the world actually has much much less than that working for them. What happens is just another example of human nature, when people are not told what to do, they will do what ever they want. This means that we end up with many open-source projects working on the same things. The problem of open-source is not that the resources are limited but that they are unlimited and scattered.
-
Advertising - There isn’t much to say here which is not self implied, but still, remember that the power of advertisement when it comes to the general public is HUGE.
-
Where used to it - I know many people trying out Linux or other open-source platforms, but no matter what, what they are looking for is the similarity to Microsoft Windows. Microsoft has us by the *alls here and we can all say "well if we won’t change it, it won’t change" but the poor truth is that people don’t like to try new things and evolve.
-
Awesome IDE - admit or not, Visual Studio is an amazing program. I don’t think there is another IDE that will compare, that means the developers use Microsoft which means they develop for Microsoft and that means you get the old "I can’t switch to Linux, there are no programs…" argument which is not true but again, people don’t change.
-
Community - At least when it comes to the community we can say that the BIG open-source projects have a community to match or at least be at the same league of the Microsoft community(the world).
-
Evolving - We are witnessing the past few years that even a company as big as Microsoft can evolve, maybe not as fast as open-source but we are seeing the Live! Office coming to life and other new projects.
-
Force in numbers - If you think about it, they’re so big that if you piss them off they can just sit on you.
This reasons and many others bring me to the believe that even though people don’t like Vista and even though it is cool to hate Microsoft we are looking at one big company that is not going anywhere and is actually going to win.
What do you think?
Nadav
Tags: linux, open-source, thoughts, Windows
Posted in Windows, linux | 3 Comments »
March 26th, 2008
After writing a post about the best Windows setup I realized the setting up Firefox to max its potential can be just as or even more complicated. So, here I will detail what i believe to be the Ultimate Firefox setup!
Preferences:
Go to Tools->Options
- On Main tab - I would set up my download folder here so when I download files they won’t just end up on my desktop. Choose Save files to and browse to the folder of your choosing.
-
Tabs tab - We’ll use an add-on for this one.
-
Privacy tab - You might want to mark Always clear my private data when I close Firefox and choose the correct Settings for you. this is good for security reasons.
-
Security tab - I HIGHLY recommend you use a master password for all your saved passwords, it is really no hassle and adds a very important security layer. Just mark Use a master password.
I didn’t talk about any other thing in the options because the rest of the default values seem fine to me.
Add-ons:
This are add-ons I use and find helpful for fun and productivity.
For setting up specific add-on settings go to Tools->Add-ons->[add-on name]->Options
-
Download Statusbar - Gives you a small downloads status indication at the status bar.
After install and restart choose in it’s settings:
Top right Mini Mode.
-
Fasterfox - Does different optimizations to your Firefox installation so it will run much faster.
-
Firebug - This might be the best one in the list. If you are a web developer this is the extension for you, extensive all-web related features. viewing and editing in real time of DOM,CSS,HTML,JS… and a JS console and a view of all requests sent including AJAX requests.
And what I consider to be the coolest feature, live JS debug with breakpoints !
-
Flashgot - When combined with a download manager (Flashget\GetRight\DAP…) enables to send to download all links in a page, links marked, building a gallery of picture\video and many many more.
-
Forecastfox - Weather in your status bar. Personally I change the settings so it will only show icons and just when I hover above one give me more details.
-
Foxmarks Bookmark Synchronizer - Does exactly what the name says. I use this to keep a backup of bookmarks and at the same time keep my Portable Firefox synched with my standard installation.
-
IE Tab - Enables viewing of pages using IE’s engine inside Firefox. Very useful for web-developers or just people that use non-standard web sites.
-
Long Titles - Makes sure that the image tool tips will show completely.
-
Master Password Timeout - If you wish your master password will expire every so minutes than use this extension.
-
ProfileSwithcer - Firefox add-on developers or just people that want a clean\different profile for normal usage can install this for a quick and easy switch.
-
Resurrect Pages - Don’t you just hate it when you go to some site and get the 404 missing error ? Well, this extension lets you view this page from many different web cache archives, can be very useful at times.
-
Tab Mix Plus - Adds a whole lot of features for the Firefox tabs. I highly recommend going through it’s settings and setting it to your liking.
-
Update Notifier - Notifies of new updates to the main Firefox program and to add-ons.
-
Web Developer - A must have for web developers, just get it and explore all the wonderful options. this does not conflict with Firebug, they complete each other.
-
iFox Smooth - A nice theme I have been using for a while now.
-
JAJAH Click-to-call - Last but not least, our very own. - adds telephony functionality to your pages with number recognition and other cool features.
I recommend going through each new add-on you install and its various settings options and choosing what is right for you.
Tweaks:
Write at the address bar about:config and now we are going to search for values and change them, if a value does not exist, add it.
This is a little more complicated and dangerous for your Firefox installation so use at your own risk.
I found a few good articles about this specific subject so I will link to them and leave the fame to who ever deserves it.
- Link 1
- Link 2
– — – — – — – — – — – — —- —- —- —- —- —- —- —- —- –
Hope this helped you.
Tell me what is your ultimate Firefox setup in the comments.
Some credit goes to Lifehacker for ideas.
Cheers,
Nadav
Tags: about:config, addons, configuration, firefox, linux, properties, setup, system, tweaks, ultimate, Windows
Posted in How to, Windows, linux | 3 Comments »
March 19th, 2008
Sometimes you would like to know if your program was launched on the boot of the machine or activated by a user.
Here is a simple way to find just that in real-time.
What I would do to handle cases where the launch on boot is done through a shortcut is one of two options.
- If you can, add a parameter to the call of your application and check for it using the args[] in:
[MTAThread]
private static void Main(string args[])
{
- Use this post to know how long its passed since boot, check for a minimum period to know that it was started by the user, this is not bulletproof as it might take a while for boot to finish and your app to start but it is a solution when you have to do this.
Got any ideas yourself? let us know in the comments !
Good luck,
Nadav
Posted in Uncategorized | No Comments »
March 17th, 2008
I guess this is quite the easy one but the fact is that while I was searching the web for this answer it was very hard to find.
This is something I knew and forgot so it is good that I will have it here for future quick reference.
Just use:
Environment.TickCount
This will return the time in milliseconds that has passed since the last boot.
Quick Note:
I have read here that this might overflow on systems running for a few days, they also give a solution. as I am using this for a Windows Mobile device I don’t have that option. (CF.Net being deprecated and all…)
Hope you found this faster then I did.
Update:
After further looking into this I have found a nice article about how to overcome the overflow problem, here is the solution:
public static TimeSpan GetTimeSinceBoot()
{
long _newTicks = Convert.ToInt64("0x" + Environment.TickCount.ToString("X"), 16);
int days = (int) (_newTicks/(1000*60*60*24));
int hours = (int) ((_newTicks/(1000*60*60)) - (days*24));
int minutes = (int) ((_newTicks/(1000*60)) - (days*24*60) - (hours*60));
int seconds = (int) ((_newTicks/1000) - (days*24*60*60) - (hours*60*60) - (minutes*60));
int milliseconds =
(int) (_newTicks - (days*24*60*60*1000) - (hours*60*60*1000) - (minutes*60*1000) - (seconds*1000));
return new TimeSpan(days, hours, minutes, seconds, milliseconds);
}
The ticks represent milliseconds and when I just call the constructor for TimeSpan it doesn’t treats it this way, that is why i am doing all of this.
Good luck,
Nadav
Tags: .net, c#, CF.Net, system, system up time, tickcount, time, Windows, WM
Posted in CF.Net, How to, WM, Windows, c# | 1 Comment »
March 3rd, 2008
A couple of weeks ago I got a new computer and after spending quite a while setting it up and collecting all the different programs and little tweaks I like I figured it’s a good idea to make a list of it all.
at the end there’s a bonus!
Programs:
.Net Development:
-
Resourcer - Enables looking at what’s inside .Net’s binary resource files. - Link
-
Reflector - Enables looking at assemblies wether they are the .Net assemblies or your own. can be very useful - Link
-
Guidance Explorer - Contains different guidance lines in regards to .Net development. - Link
-
TailXP - this is not really geared solely on .Net, this is a tool used to watch a certain text file for changes, this is very useful when watching a text log file change in real time. - Link
General purpose:
-
Notepad++ - An excellent free text editor. - Link
-
7zip - A free zip\rar\7zip(their own) compression\decompression program. - Link
-
Paint.NET - An open-source photo editing program written in .Net - Link
-
CDBurnerXP - A very nice program for burning different CD’s\DVD’s.(FREE!) - Link
-
SharpKeys - I used this little program to change some keys behavior on my laptop’s keyboard. you can use it to change the behavior of most keys on most keyboards - Link
-
foobar2000 - A music player. The reason I use this music player and not Winamp\Windows media player\ITunes\Whatever are both that it’s FREE and that uses virtually no memory once minimized(in today’s scale). - Link
-
Firefox - Of course - Link
-
SyncBack - A very good program for synching different locations including FTP servers.(there’s a free version) - Link
-
CCleaner - Cleans all temporary locations on your computer and fixes some registry issues. free and very good. - Link
-
Daemon Tools - A free CD\DVD drive emulation, very useful when downloading an install CD you don’t want to really burn. - Link
-
WinSCP - Useful for accessing SFTP\FTP servers. - Link
-
Putty - Simple SSH client - Link
-
VLC - Good media player(I use it solely for video though it supports audio playback as well) - Link
-
Gimp - If you are looking for a more professional alternative to Paint.NET but don’t want to pay for Photoshop, The Gimp might be for you - Link
-
Windows Live Writer - The software I am using to write this posts. - Link
-
Picasa - My choice for photo organizing. -
Windows tweaks:
- You know it when some program crashes(all do eventually) and you get that annoying "Send\Don’t send" message? well, you can set it up so it just shows the error and a close button. This way you won’t click the send by accident.
Right click My Computer->Properties->Advanced->Error Reporting(at bottom)->Disable Error Reporting. Leave the mark as it is.
- Some times you have a simple file you wish to open with Notepad but Windows doesn’t recognize the file type and won’t do this by default, yes, you can fix it manually but that will only help this file type. what I like to do(or at least liked[better idea coming up]) is to add a shortcut to Notepad on the "Send To" list.
Start menu->Run-> write "sendto"->right click the empty space->new->shortcut->write "notepad.exe"->Next->write "Notepad"->Finish
And your done! now you can just right click a file and choose sendto->notepad and it will open up with notepad.
- A new way I found of doing the previous mentioned tweak is to have a "Open with Notepad" context menu item so you don’t need to go to "send to" the How to is detailed here: Link
You are probably wondering why then have I wrote here the previous one, the answer is that i think the previous tweak is quite useful for many different usages even if just to remove useless links from the sendto list.
- Most people look into choosing a nice desktop wallpaper and a nice screen saver, what they forget about is looking through the power options and setting them to they’re liking. it can be a real pain to leave your computer on at night for a big download and come back the next day to find out it turned itself off after a couple of hours.
Right click on the desktop->properties->Screen Saver->Power…(at the bottom)
Go through all the options and choose what’s best for you, if you don’t know what something means leave it as it is.
- Using hibernation - If you wish to shut-down your computer but you want it to boot back to the same exact situation that you left it in you can put your computer in hibernation. what windows does when you do this is copy all your current RAM(memory) to the hard-drive and then restore it the next time you boot. I found this most useful with laptops mainly as it shortens boot-up time quite drastically.
Go to Power as before->Hibernate(tab)->Mark Enable Hibernation(if it’s not already marked).
If you are using the old\server style of the shut down screen then you have a list view when you choose "Shut down" from the start menu. If this is the case then you will see the hibernation option at the bottom of the list. if you are using the default XP shut down view then you will need to hold down the "Shift" button while viewing the screen and then the standby button will change into hibernate.
If you are experiencing problems with the boot up after hibernation you can rapidly click a few times on the F8 key just before Windows start loading(right after the BOIS screen is gone). This will open up the boot option screen for windows, you can choose here to boot normally and not from the hibernation data created earlier.
I would also recommend rebooting the computer the old fashion way at least once every 3-5 days, this is Windows were talking about after all…
Hope you found at least one cool thing here. If there is anything you want me to try and find out for you just say so in the comments and I will give it my best.
Cheers,
Nadav
Ow right… the bonus! - just a free nice game, very cool indeed. - Link
and if you are into shooters and such look into F.E.A.R(I will leave this one for you to find, the multi-player should be free).
Tags: games, new install, productivity, programs, setup, tweaks, Windows, windows xp, xp
Posted in How to, Windows | 7 Comments »
February 16th, 2008
Here is a list of a few useful Linux commands for us newbies. =]
This are most of the commands that i have come to use in Linux, this are the ones that I think it’s worth to at least know. You never know when it will come in handy…
-
ls - Works the same as “dir” in DOS, lists all the files and folders at the current path.
-
cat filename - Pasts the contents of filename to the screen.
-
man command - Loads the manual file for the command\program.
-
wget url - I think this actually a program but it will most likely be available on every Linux system you will use. It fetches the file\page at the url.
-
mkdir name - Create a directory named name.
-
rm filename - Delete filename.
-
rmdir foldername -Delete foldername.
-
ps - Lists processes.
-
passwd - Change the password of the current user.
-
chmod - Read about this one, this is used to change the rights regarding read/write/execution of a file or folder.
-
chown - Used to change the owner of a file or folder.
-
cp filename1 filename2 - Used to copy files from filename1 to filename2.
-
df - Used to review hard-drive space, personally, I use it with “-hT”.
-
fdisk /dev/*** - Used to partition a hard-drive, usually the drives location will be /dev/hda or /dev/sda or /dev/hdb and so on…
-
find key - Find files on the file system. I am not very familiar with it but I know that sometimes you would prefer to use locate.
-
grep regularExpression- used to find lines that correspond with the regularExpression usually used in parallel to another command like ps. [ps | grep cups]
-
ifconfig -Lists the available network adapters and their status.
-
kill - Stop a process by PID[Program ID].
-
killall - Stop a process by name.
-
lsmod - Lists currently loaded modules[this is a subject of it's own].
-
rmmod mode - Unload a module from the kernel.
-
lsusb - Lists all USB devices.
-
mount - Used to mount a device/partition to a certain path.
-
umount - Used to un-mount a device/partition.
-
dig serverAddress -Used to query the DNS server.
-
sftp - ftp, but secure!.
-
ssh address - Connect to a SSH server at address.
-
su username - Start using the shell as username.
-
sudo command - Run command as if you were root. This command is currently used in many different distros to re-authenticate the user in order to make sure this is not some kind of a harmful program.
-
tar - Create or restore file from a tarball.
-
traceroute address - Shows the entire route it takes a request in order to get to address. Useful when trying to find bottle necks in networks.
For more info on any of this commands either use “man” or call the command and “–help” or “-h” after the command(or click the link…). It should list the different possibilities of usage to that command.
Hope this helps you with your Linux endeavours. BTW - most or at-least some of the commands should work on UNIX based systems as well. This is due to the fact that both Linux and UNIX adhere to POSIX.
Until next time, have a good one! =]
Nadav
Tags: command, linux, newbie
Posted in How to, linux | 3 Comments »
February 15th, 2008
Lately I stumbled upon a few cool things you can change in the Visual Studio 2005 to get some nice to have features.
Here they are:
- Change the start-up behavior:
If you’re like me and you don’t like the fact that it takes a while for VS to load, partially because of the start-up screen, while you don’t use it anyway… then this for you !
Go to: Tools->Options->Environment->Startup
And choose whatever fits you best.
- Enable line numbering:
Some times when you use a log file or you look in the windows event handler you will see certain errors you want to check in the code, but while looking for the right line you keep looking at the status bar to see in which line you are. NO MORE!
Go to: Tools->Options->Text Editor->[Choose your language or All Languages]->General
And set the check box at the bottom named “Line numbers”.
- You might want to go through the “Formatting” section and set it up to your liking.
- If you don’t like it that when you implement an Interface VS automatically wraps it with a #region than you can go to the same place but look at [Language]->Advanced
And unset the check box at the bottom under “Implement Interface”
- If like me you don’t use the WYSIWYG editor for HTML than you might want to go to:
Tools->Options->HTML Designer
And choose “Source View” at the top.
- A cool and not so known feature of VS is that you can set special keywords to show up on the Task List.
First, what you want to do is open the Task List window, you do this by View->Task List(or just Ctrl+T).
Second, go to Tools->Options->Environment->Task List. Here you can set up your own keywords or removed ones you don’t like. this can be used so when you need to do a little fix in your code at a latter time you put a little “//TODO: ….” comment there, then, when you look at the Task List not only you will see all the TODO’s[and other keywords] comments but a double click on it will bring you to the exact line. Now that’s a time saver! no more searching the entire solution for those TODO comments.
- Another very cool and probably not very known feature of VS is that you can Import and Export your settings! this means that after you go through all the settings and set everything to your liking you can save it so the next time you install VS you will easily set it up in no time.
Hope you found this informative and that it helped you a little.
Until next time, have a good one =].
Nadav
Tags: visual studio, VS, VS2005
Posted in How to, Windows | No Comments »
February 7th, 2008
Every time I have a state where I need to use switch\if-else-irritation I can’t quite figure our which is the better choice. I am pretty sure there is no one answer to this question, but i did stumble upon an interesting test:
Link
This test shows that, as i suspected all along(Mu-ha-ha), the switch is faster, and in a significant way.
I’m sure that some people will still state if-else is more readable, but personally, i do not agree with that.
What do you choose when you face this issue? if-else/switch? or an entirely different mechanism?
Have a good one, =]
Nadav
Tags: c#, coding, conventions, else, if, if-else, programming, switch
Posted in c# | 7 Comments »
February 1st, 2008
As you might have noticed, what I do here in this blog is write about the things I look for, than, when I can’t find them or I find too complicated and evasive answers I write simple ones here.
So, let’s get to the reason we’re all here.
I will give here an example on how you can change the visibility of the keyboard and you will probably be able to figure out the rest.
the steps are as follows:
- Add a reference to Microsoft.WindowsCE.Forms.dll
- Create our new class:
using Microsoft.WindowsCE.Forms;
namespace Environment.Keyboard
{
public class Keyboard
{
-
Create our private InputPanel member:
private static InputPanel m_inputPanel = new InputPanel();
-
Create the property to check if the Keyboard is open:
public static bool KeyboardOpen
{
get { return m_inputPanel.Enabled; }
set { m_inputPanel.Enabled = value; }
}
-
Were done!
It’s that simple. the Enabled property in the InputPanel signifies if the keyboard is currently open or not.
Check out this link for a more comprehensive article.
See you next time,
Nadav
Tags: c#, CF.Net, keyboard, SIP, soft input panel, windows mobile, WM
Posted in CF.Net, How to, WM, c# | No Comments »