Thursday, September 20, 2012

Resource file does not support multiplication and division operators

Microsoft Visual Studio 2008 - Resource Scripts support only addition '+' and subtraction '-' operators for the Numerical fields. Multiplication '*' and Division '\' operators and Parentheses '( )' are not supported.

e.g. 
Main.rc

# define WINDOW_X 0
# define WINDOW_Y 0
# define WINDOW_WIDTH 300
# define WINDOW_HEIGHT 120

# define BORDER_SIZE 2

IDD_MAINDIALOG  DIALOG  WINDOW_X, WINDOW_Y, WINDOW_WIDTH-2*BORDER_SIZE, WINDOW_HEIGHT

// Here WINDOW_WIDTH-2*BORDER_SIZE will evaluate to only: WINDOW_WIDTH

// Thus instead use:

WINDOW_WIDTH-BORDER_SIZE-BORDER_SIZE

Friday, September 07, 2012

Multiple Partitions or One?

I recommend that you have only a single drive instead of dividing your disk into multiple partitions.

It is a general belief that multiple partitions help you organize your data and protects your data - in-case you happen to have to format your disk.

Well both of these reasons are wrong.
  1. Folders themselves are the best way to separate and organize your files.
    Having to go all the way upto the list of drives then navigating to your file is very inconvenient - as it likely that you will have to do that many times in a day.

    More over you will have to remember more - first: which drive is it in.
  2. There is no reason to format only one drive - it is not required when you upgrade or re-install your operating system. Also only formatting one drive and leaving the rest offers you no advantage in eradicating a virus infection.
Dividing your drive into multiple partitions is like dividing your hall into small 'rooms' with card-board. This only constricts the available space and regularly gives you the headache of low disk space - when in-fact you are likely to have that space.

I would even recommend that if you have existing additional partitions on the same disk - you should merge it into one single drive.

Only exception that comes to my mind is when you have to have multiple operating systems. But again in many, if not most, cases you would be better off with Virtual machines and virtual hard-disks that are dynamically sized, for secondary operating systems.

Also usually laptops come with recovery partitions - If you are pro user I think its best to have that recovery transferred to an another media like a DVD and to reclaim that precious non used disk space.

Wednesday, September 05, 2012

Get Clipboard Size : Windows

The windows clipboard has a group of parallel versions of the same data.

To get clipboard data you use the function GetClipboardData with the format-ID parameter.
This gives you the handle to the Global Memory block that contains this particular version of the clipboard data.
In-order to get the size of this block in bytes use: GlobalSize on the handle got by GetClipboardData.

HGLOBAL hMem;
hMem = GetClipboardData(uformat_id);
cbSize = GlobalSize(hMem); // got the size in cbSize
pData = GlobalLock(hMem);

Sunday, August 26, 2012

WiX ICE69: Mismatched component reference Warning

When using WiX you receive the following warning:
LGHT1076:  Mismatched component reference *** however Components are in the same feature.
The important thing to understand here: is that its only a "Warning". WiX is only trying to be sure it does not let you bite your own tongue. You may or may-not be doing anything wrong here.

If you have a <condition> in one of your component which is being referenced by another component. e.g. A shortcut referring to an Executable. Then this warning is valid.

So if you are not doing any thing wrong - simply [ignore] this warning.

You may want to use the -sice:ICE69 command-line parameter to suppress this warning.
In Visual Studio you can go to the WiX Project's Property page:
> Tool Settings > ICE validation : Suppress specific ICE validation: ICE69.

I suggest you set ignore warning only for the "Release" project configuration - so that you do not risk missing new valid warnings that may come later in the development.

Sunday, June 24, 2012

Disable Sync Center from Auto Starting

In Windows 7, Once you have set up "Offline Folder" by selecting "Always available online" - the Sync Manager always starts automatically and shows up in the system tray.

This can not be reverted by removing "all" the folders previously made "Always available online"

One method is to Disable Offline files via Control Panel > Sync Center > Manage offline files > Disable offline files.

But the "correct" method would be to only deactivate the Sync Manager Handler via Registry:
@ HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\SyncMgr\
HandlerInstances\{750FDF10-2A26-11D1-A3EA-080036587F03}

revert "Active" to value '0'

This is the default state as it at before any folder where ever made "Always available online" and thus now the Sync Manger Icon will not show up in the system tray upon every start-up.

Wednesday, April 04, 2012

Google Chrome not Updating with 'Update server not available (Error: 3)'

If you are using Google Chrome and have disabled UAC (the popup with dark background that comes up every now and then; chances are your browser might be 'very' outdated. you can confirm this by clicking on the wrench on the top right,just  below the close button - then: 'About Google Chrome'.
It should say 'Google chrome is up to date' but instead if it says: 'Cannot reach update server Error 3'
- Re-enable UAC then reboot and check again.
Chrome has a standalone updater that is run by the Task-Scheduler; which if not misconfigured should have been able to update Chrome regardless.
http://support.google.com/chrome/bin/answer.py?hl=en&answer=111996

Thursday, February 23, 2012

Query directly from your Browser's Omnibar/Addressbar

We need information and we want it fast. In the Internet age when every other service is online, getting to the right information quickly depends only on your computer, internet connection, browser, your bookmarks or your proficiency at formulating the right search queries. Fortunately todays Browsers have evolved. They are much contextual, intelligent and proactive. There is no longer a need of separate forms for the URL address and the search box. The hybrid of these two and more is the Omnibar.

But with the added feature of 'Key word custom search' like "Edit search engines" in Google Chrome, this Omnibar now becomes virtually, a 'command prompt' to the Internet, saweeet :)
As an example: Imagine: you need to find the current status of your train ticket. For this you would first search for the Railway's website, then you will have to scan the whole page and travel back and forth a few links to get to the final form where you can input your ticket number. now imagine how convenient it'd be if this whole process were to be reduced to one single step.

This is what I mean by the Command Prompt to the internet: Ideally you could come to this command prompt: the omnibar of your browser, and just type: "Ticket-Status xxxnnnxxx" and Voila!! your browser would take you to the final page of Railways website which shows the status of your ticket; all in but just one step.

and here's the great news this can be done and you don't really have to be a programmer to accomplish this.

Here's how:
When we browse the internet we access a URL. e.g. google.com
When we search or query by clicking a button like 'Submit' after filling a form we also send that URL a bunch of variables/parameters.

there are two methods of sending information to a web server.

  1. Get: information is sent in plain text appended to the the Query String beginning with a Question Mark '?'
    e.g. www.google.com?q=hi
  2. Post: Most of the forms are submitted by this method. the Query string is sent in binary format and thus does not require appending of any text to any url.

So the idea is: If you know the right method - your information server is to be queried by, you could formulate the right 'request' that contains the information which you'd normally enter and then click, say 'submit', to get to the final information directly.

While all browsers support Direct Search,
Google Chrome lets you perform search queries only by Get method uptil v7.0.
Opera allows you to send requests by Post method also but unfortunately there is no way to pass more than one parameter.

Though there is a JavaScript hack to make use of multiple parameters in Get method, both in Chrome and Opera:
following line must be placed in the URL field of the "Add Seach engine" reference

javascript:url='lccp_pnrno1=%0s&lccp_pnrno2=%1s&submitpnr=Get+Status'; parts='%s'.split('qzq'); for(var i=0; i < parts.length; i++) url=url.replace(new RegExp('%'+i+'s', 'g'),parts[i]); location=url;


  • u may replace 'qzq' in the above with any thing that does not collide with the expected parameter values.
  • u may use an empty space ' ' instead of 'qzq' if you do not expect to have any space in any of the parameters.

    eg. keyword XqzqY => xyz.com?param1=X&param2=Y

I have not been able to find out a similar solution for the 'Query String' viz the parameter list in Opera for Post method.

thus Here I present to you an ingenious solution:

  1. the Browser forwards your query to a local file;
  2. a JavaScript in this local file then converts the Get query into the required Post query and
  3. then forwards it to the final Search/Query engine.


the Catch is: you will have to do a little bit of digging to find out the specific variable: the form name and parameter list then customize the HTML re-director accordingly.

Procedure:
To identify the information being sent to the web server: the easiest method is to convert your form into type 'Get' from 'Post'. This way when you click 'Submit' your form you are likely to see your form name and parameter list along with corresponding values in plain text right in the address bar. (Unless its a AJAX form)

Add the following Bookmarklet:

Make sure that u can see the BookMarks bar.
if its not visible press Ctrl + G
Drag this bookmarklet to the Bookmarks bar Or Add a new BookMark with name: "Post2Get" & url: as the following:

javascript:(function(){var x,i; x = document.forms; for (i = 0; i < x.length; ++i) x[i].method="get"; alert("Changed " + x.length + " forms to use the GET method.  After submitting a form from this page, you should be able to bookmark the result."); })();

Download the following redirector XHTML file into ProgramFiles\Tools Folder

  1. SingleParam
  2. MultiParam
Edit the parameters according to your specific case:

Add an entry to this redirector file into the Browser
Right Click on the Omnibar
Edit search engines... > Add... > Name: [SERVICE_NAME] > Keyword: [SN] > URL: [file:///C:/Program%20Files/Tools/Redirect.html?query=%s] > OK

Go to the Query/Search Engines particular page that contains the particular query form.
Click on the Post2Get Bookmarklet
 It will then tell you how many forms it has converted from 'Post' to 'Get'
Now after filling in the form when you click on the submit button -

  • Case I: if the query works:
    u can directly use this URL for adding the search reference
  • Case II: if the query fails:
    u will still see the query string in the address bar, copy this

 identify the two parts of this string:

  1. static location of the URL
  2. identify the static variables and their values
  3. identify the dynamic variables


 Optionally and as a good practice you may add validation checking for these variables.
 Rename the redirector file to ur particular query
 copy this address to the Redirector HTML file and save

Now just type the Keyword in the omnibar <space> followed by the query term.

[Work in progress...]

Run VBA Macro from another file via Command Line.

Microsoft Office Macro in a file other than the "Normal" template.

VBA Macro can be run from Command line using the following syntax:
WinWord {Path\to\Macro\File} /mMacroName

This will not work if you have set your Macro Security to any thing other than "Allow all macros"

To fix this:
I suggest you select: "Allow only signed Macros"
Now Sign your Macro Project using a Self Certificate from "Office Tools" > "Digital Signatures"
You will have to Place a copy of the Certificate in "Root Authority"

Still - No effect on calling from the command line. This is because even though the Macro Project is Digitally Signed - it is only self-signed; thus you will have to explicitly authorize this macro project's publisher - which is: you.
For that open the macro project document/Template - and you will be prompted to allow the "Self Publisher".

Once this is done - the macro can be run directly from the command line.