Category Archives: Software Development

Anything to do with developing Apps, Desktop application, server application, API etc.

Extern “C” and Name Mangling

Name mangling is very common in C++ compilers when a function have the same name with different parameters or overloading.

As the compiler compiles your code, with a function with the same name , the compiler tries to rename the function or method so they dont clash with each other at runtime and providing different signature.

Using Extern “C” on the other hand if you are calling a C function exactly as it is from your C++ code. With a syntax of

extern “C” statement or block of code

This prevent the compiler from mangling the name at compile time otherwise getting bunch of errors and crashes.

Here are some good articles about it:
http://www.geeksforgeeks.org/extern-c-in-c/

Here some good link about Calling Convention: eg. __stdcall, __cdecl
http://blog.aaronballman.com/2011/04/the-importance-of-calling-conventions/

C & C++: Shell Extension Need to know and understand

Its been a while since I posted something here due to my lost of my  laptop. Anyways aside from that I’m now back and continue this journey of the shell extension in c and c++.

I have asked about the the fundamental of the COM in stack overflow. Follow this question on there to get more information.

http://stackoverflow.com/questions/43010172/addref-and-release-in-iunknown-what-do-they-actually-do

Follow the link for a beginner explanation as well for terms and classes, typedef, and windows.h

This is also for reference for myself.

More to come in my shell extension journey.

C++: Road Block – Renamer Tool

I was just coding away with my Renamer Tool and suddenly hit a road block. My Renamer tool is a Csharp WPF application that renames files according to Filter set by the user. It will also features a way to select multiple files from window explorer to be selected and right clicked to open up with the program.

I thought this was simple as I was googling along adding context menu feature. It led me to..

Shell Extensions.

Ugh… it is said that writing a shell extension in managed code like CSharp is discouraged. And mostly the only way is through..

C++ Active Template Library or COM…. went to have a look through how to implement this. Questions upon questions upon questions!

Apparently writing a shell extension in C++ is like diving to a different world of programming, prepare to go back to the old ways as this requires the knowledge of the old windows api calls. Which has specific OS types and classes.

My program is almost there , and knowing me, I like to use this program for my personal use and Im pretty sure others would like to use them as well.

So what now? I do have some basic knowledge of C/C++, but never ever done shell extensions before or COM which is like assembly language.

Wish me luck, cause Im about to dive in!

Helpful Links:

http://stackoverflow.com/questions/8811621/how-to-write-a-shell-extension-in-c

http://softwareengineering.stackexchange.com/questions/194764/what-is-lpctstr

Enter Git: Best way to learn git?

Hello, as a developer you need some sort of version control for your changes to your project or repository,handle them and work with colleagues as you do.

So meet Git, its a very straight forward tool I cannot give a well straight forward instruction but as a  beginner like you and me I found these video that can help us out. In summary these are the commands you will use from your day to day job using Git.

  • git config –global user.name “John Doe” and user.email “email@email” – this is for setting up an account
  • git init – starting your repository
  • git clone [url_to_the_repository] To download the repository to your current machine.
  • git reset –hard origin/master – This is to overwrite your local repository with your remote regardless, git status is up to date as this will destroy your local commits. Use it only if neccessary
  • git status – tell us that our working project are the same in the repository if not then use next command
  • git add .(all) or git add (filename) – you add the changes to the staging stage ready to be committed or made put the repository
  • git commit -m “Your message about the changes” – finally put your changes to the repository
  • git fetch – This will collect all the commits from your repository ready to be pulled.
  • git pull origin [master] – This will update your local repository from the master branch usually from the remote.
  • git add remote origin “https://repo.git” – This will add the link to your remote repository for consumption
  • git remove -v – This will display your current remote repository.
  • git checkout [branch-name] – This will set up your current branch , as Master is your main branch.
  • git log – these views any commits your team has made then add in –author “Beth” to see Beth’s commit message
  • git help – get help will show list of commands you can use and their usage
  • git diff – show the comparison , and show updates made from the old one, and remember this is before you do a commit. Otherwise there is nothing to show.
  • git diff –staged – compare your “staging” changes to your “repository” otherwise default is between “working” directory and the “repository”

Here is now the video you are waiting for, a very informative  tutorial that can get you started from beginner to advanced.

Credit to the video uploader. I learned alot from this tutorial. And I am sure you will too.

In another note, once you got a good grasp on Git. You might want to put your repository/project online then you know whats coming , GitHub! There’s other repo container out there but GitHub is like the standard. Anyways  thats it for now 🙂

Enter C# Unity Container, Inversion of Control

Coding in C# is pretty straight forward although sometimes you see errors every now and then. Working with WPF(Window Presentation Foundation) and MVVM can get really complex with large projects you can get lost in the sea of codes.

One thing Im going to talk about is Dependency, we use it all the time. Sometimes we need an model object that represent the data in our class and consume it, sometimes we need a database layer class to every object that will communicate with our server.

Inversion of Control is a pattern on how to pass dependency object through constructor. Enter Unity Container, its a Microsoft object that handles dependencies through the use of IoC.

We create the instance of the UnityContainer object and register types so unity will construct our dependency for us. You then resolve the classes that are involved in the dependency by calling obj.Resolve<typeof>(). This will chain up the classes with their dependency object injected.

Check links below for a simple explanation of the architecture.

https://www.youtube.com/watch?v=CWwe9Z0Gyew PART 1
https://www.youtube.com/watch?v=PsIbevgzQQE PART 2

Credit to the author

C#: WPF DependencyObject; What is it exactly?

Been developing a Rename Tool in C# using WPF as my window form, and data binding is giving me a bit of trouble understanding. There are other ways to make data binding in WPF, and Dependency Property is the one that boggles the mind.

Alas I have found an article that led me to a more thorough explanation to why you would use it.

http://www.pinfaq.com/32/what-is-dependency-object-in-wpf-where-should-i-use-it

In short Dependency Object is the object where WPF controls derive from and it provides all the validation, notification, updating , callbacks otherwise you would implement yourself which is possible but just time consuming.

This comes down to using Dependency Property  on your own class.

Adding Custom Context menu in Windows and my Rename Tool

I have been thinking of putting a custom context menu entry in my program, and this is the registry place to put your values into.

How to Add Any Application Shortcut to Windows Explorer’s Context Menu

And all you need to do is code your application to add them in your Visual Studio set up install function using the RegistryKey class in C# (at least), or use Inno Installer program to add a section as [Registry], the Inno Setup help is available if you need a reference.

I am thinking of creating a program that lets you rename all the filenames in a folder by adding a prefix or suffix or using regular expressions by right clicking the folder and call upon the program and a windows pops-up confirming your intention to rename.

Its very handy little tool , Im just in the process of putting them together. So the step would be:

  • Make the program
  • Create an installer for the program most likely use Inno Installer
  • Let the installer create the registry entry for you using { yourprogram.exe 1% } where the 1% is the folder path.
  • And run your program base on the folder path otherwise the user can select the folder to rename files.

 

Creating a C# application set up project with custom action

I have been looking to get  my C# application in Visual Studio to be packaged for easy installation.

I found a really good article that explains the steps and other custom action to be included in the installation set up as well.

It also bundles up the .NET Framework of your choosing as you install the program. Mainly Im trying to run a code that injects registry entry to the register while install is in process. As there are tons you can do to added functionality to your application using the registry in Windows.

Check this link out: http://www.c-sharpcorner.com/UploadFile/1492b1/creating-an-msi-package-for-C-Sharp-windows-application-using-a-v/

Credit to the Author of course I will look into this article for reference whenever I need to bundle up my application.

Important note: The Visual Studio Set up project isnt included in VS2012 and up, as they have a different installer used, you might need to download the old installer project at this location:

https://marketplace.visualstudio.com/items?itemName=UnniRavindranathan-MSFT.MicrosoftVisualStudio2013InstallerProjects