RoxxSoft Development Blog
Posts tagged Programming
Agile development not
Aug 24th
About two years ago, while still working on a cubicle for some crappy very big company, i was asked to implement a windows file system filter driver, the project leader, as usual, knew zero about windows drivers or what is required to build them.
So i was asked to take care of everything, from gathering the requirements, creating the work environment, documenting, downloading SDKs, and finally, implementing the driver.
The time allocated for all these tasks, including the driver design, development, testing and bug fixing?
Two weeks.
It appears someone up there in management who liked to read blogs and wikipedia entries as if they were highly technical documents, actually believed Agile development meant 15 days deliveries, not of product features or fixes, but of complete products, fully tested software releases, all features included and without any bugs left, starting on day zero with no code at all, then 15 days later, a full solution was to be delivered, no bugs, one week development, one week testing, no more, second week Friday didn’t count, as we had a demo with the clients early in the morning.
So, after barely getting some sleep for two weeks, i finally managed to include most of the required features, although the code was not really release quality, it actually worked, and finally, with a lot of pressure, i managed to release it after three weeks.
Two weeks later, when some obscure bug came up and XP machines were crashing randomly, he asked what was up, how could this be if we had time for testing and bug fixing? when confronted with the truth that a Windows driver can’t and won’t be implemented in two weeks even if you have 20 developers, and when asked for more time for debugging and testing, his answer was a simple one, “this development ended two weeks ago, we can’t use more time for that task”
A few more weeks went by, i was asked to continue working on other projects and features, and at the same time, to work on the driver on extra time or free time, or at home, when things didn’t improve and the crashes were still happening, the big boss canceled the driver project (actually the entire main project was canned, but that’s a very big and different story for a future post), we couldn’t deliver the promised results, of course it was not to blame on bad Agile development understanding or extremely delusional leaders, but in the developers and their lack of skills, we had a good laugh at all these ‘facts’ as we got the honor of hearing them directly from the big boss.
Priceless
COM Basics Tutorial Part 1 – C++ function pointers
Nov 9th
In these series, i will try to show how COM works at a very low level, which some may read as in a very complex level, which fortunately for us all, is not as true as you may have heard before, the only requirement for this tutorial is to have a basic understanding of the C and C++ languages, everything else will come with time.
But first, let’s get a quick look at a little app, we are going to be using this code to show how and why things are like they are with COM, but first we will start with a very simple application that shows what function pointers are and how a class is actually made, this of course mean we will be working with C++, COM can be used from C as well, but i tend to use more C++ so that’s what we are going to be using here.
You can download the code here: ComTutorialApp.zip
Once you have the code, open it with Visual Studio 2008, you can use the Express edition if you don’t have anything else, this is a win32 application so you won’t need anything else like MFC/ATL or stuff like that, for the time being, you can get away with the Express edition.
OK, so you have the project open, if you go and open COMTutorialApp.cpp, you will find it has only the WinMain method, which has been cleaned up so no actual windows application is created, we don’t have a window or anything else but the code related to our basic COM tutorial.
Now i will explain what this code does, first you can see we have defined some types at the start of the file:
typedef VOID (*PROCADDR)(); typedef int (*INTPROCADDR)(); typedef int (*INTPROCADDRPARAM)(int);
This is our way to define the signature of our methods, as you can see, we defined a type for a method with a signature similar to:
void SomeMethod();
Which is a C method, for now that will be enough for our purposes, next we define two more methods, one that returns an int, and one that returns an int, and receives an int as unique parameter.
Next, we find a new definition, this time the type we are defining is that of a structure:
typedef struct _object
{
PROCADDR Method;
INTPROCADDR MethodInt;
INTPROCADDRPARAM MethodIntParam;
}Object;
I have named the structure “Object”, just because i like to steal the names from C# :), so you can see that inside the structure we have three members, one for every type declared at the top of the file, if you look closely at the definition of the types you will see that these are pointers, think of them as templates that define how each pointer is formed:
typedef VOID (*PROCADDR)();
So you can see this type has the form of
void (pointer-to-something)(emptiness);
OK, so now we have a structure which contains three member variables, each of a different type, we could also add another variable like an int or char or whatever we want, this is a regular structure remember?
Now we define three standard methods:
void MethodImpl(); int IntMethodImpl(); int IntMethodImplParam(int i);
If you look at the signatures, these threee methods are exactly the same as the types defined at the top of the file, you can see we have the void method, the int method, and the int that accepts an int as parameter, so we have a method for each of the types we created first, these methods are going to be called later on.
Also, we have a different method, this one accepts a parameter of type Object*, as you will see, this method can use the object as if it was a C++ class object, no difference here.
But let’s get to what this post is all about, on the winmain, we create an object using our structure as type:
Object* obj = new Object();
Then, as we have already declared three methods, and since we know the compiler already has assigned addresses to those methods, we can do something like this:
obj->Method = &MethodImpl; obj->MethodInt = &IntMethodImpl; obj->MethodIntParam = &IntMethodImplParam;
And now the member variables in the structure point to the address in memory of the methods declared before, this works because the types used to declare the member variables are equal to the signatures of the methods we are using.
So now that we have the structure members pointing to some method addresses what can we do? well we can call those methods like this:
obj->Method(); obj->MethodInt(); obj->MethodIntParam(1);
See what happens here? so now we have created a simple C++ class, of course it is actually a structure, but that’s exactly what a class is, at least at a basic level that is.
Now we can pass our obj object to another method as a parameter:
ObjectCaller(obj);
And from inside this method, let’s call again the three C methods:
void ObjectCaller(Object* obj)
{
// Calls the methods
obj->Method();
obj->MethodInt();
obj->MethodIntParam(1);
}
And that’s it, basically, this is a C++ class, created by using a structure and some pointers to methods or pointers to functions, whatever sounds better to you, how is this useful for COM do you say? well, for a start, COM objects relay on something called the dispatch table or vtable, which is very similar to what we have here, using this table is that you are able to call C++ methods for each object you create.
On our second part, we will look at how the “this” pointer is created, by updating our Object structure to support the “this” pointer, we will be able to accomplish the same results that a C++ compiler gets, but we could even be using simple C functions instead of classes, and a C compiler which doesn’t understand anything about C++.
Once we have seen how to implement the “this” pointer, we will be ready to start learning how COM is implemented and the logic behind, which at first can be very simple to understand, until we get to the tricky parts of threading models and some more complex things, but remember, this is a basic COM tutorial, not a COM bible.
Well, we are at the end of the first part of our COM series, hope you have learned something today, and of course you are free to ask any questions and comment.
Next part coming soon…
COM without MFC/ATL/Whatever
Nov 6th
I’ve seen a lot of programmers lately that write COM as one of the things they are experts at, but, once you actually put them to the test, they turn out to know the bare minimum of what COM is and how to use it, and why is this? most of them turn out to be Visual Studio programmers, not actually C/C++/C#, etc programmers.
By Visual Studio programmers i mean, those who can only code with VS, take them out of the environment and they are completely lost, ask them to create a windows application without the application wizards and it’s a no go.
Of course most of the people would say, it doesn’t matter, what are the chances that you end up having to work without VS?, yeah i know, if you know where to look for work, you will never find yourself under those circumstances, but how sad that is for anyone who sells himself as a true professional?
Anyway, i had a rather funny situation in which i wrote a c# com object and loaded it from c++, one of the programmers was very impressed, because as far as he knew, you could use c++ from inside a c# application, but not the other way around, so i explained that the c# object was a COM object so there was no problem loading it from c++, but he could not really get it, and why? because funnily enough, he thinks COM is a c-only technology, well now he knows better, but wait, why was this guy hired in the first place? as a windows programmer, to lead the development of a windows application that uses COM as one of the principal technologies with an Office add-on and IE plug-ins and a lot of COM related programming, but he doesn’t really understand anything that is happening, VS does all the heavy work.
So i though about it and decided to write a very simple IE plug-in using the Visual C++ Express edition as with all the code on this site, by reading the code of this plug-in you will be able to see how a COM object actually works without wizard generated code or anything else but what you will find on the source files of our project.
When i say, COM without MFC/ATL, what i mean is, most of the people i know that use COM think it is somehow heavily related to using MFC or ATL, when in fact it is not, there are even those who for some reason believe COM == OLE, how can this happen, for one i think Microsoft’s documentation about COM is very hard to understand for beginners, and second, by using tools like VS most of the knowledge developers could get is taken away from them by the wizards that write all the code and just leave the developer to fill in the methods, which leads to developers who depend on the generated code since they just know that by filling those methods things will work out ok, without having to understand how or why.
So, for those who really want to learn the how and why, I’ll be posting a simple tutorial on the very basics of COM, and i mean really very basics, starting from how a class is made and virtual tables and pointers to methods, interfaces, etc.
Now i would like to ask all windows programmers out there, how much do you really think a software developer needs to understand about windows technologies to describe that person as an “expert” ?
Visual resource editor for Visual C++ Express
Sep 26th
As mentioned in a previous post, after installing the Express edition of Visual C++ 2008, i found out it didn’t had a visual resource editor, while the c# express compiler does include one, so i started to look for an alternative and after looking at various commercial apps i found some free ones:
Very cool resource editor, free, not open source though:
ResEdit
This one includes the complete IDE, it is open source and seems to work with several compilers:
http://www.ultimatepp.org/
Here is another one, seems ok, not tested:
http://www.wilsonc.demon.co.uk/d10resourceeditor.htm
And of course there are a couple commercial ones, i found this one to be good:
http://www.resource-builder.com/download.html
But i did not use it so much to have a real world opinion so…
While the Visual c++ 2008 express edition seems to be targeted to students or beginners, i found that very hard to believe, without the resource editor, how are they supposed to get up to speed?, by programming like 25 years ago? I guess it is in microsoft’s best interest to move everyone into using c# as soon as possible.
Win32 and Visual C++ Express Edition
Sep 15th
I’ve been working with the Win32 api for a very long time, even for my client’s apps i tend to use Win32, i don’t like MFC, i have made several applications with MFC and Windows Forms, but i still keep working with Win32 whenever i have a chance. In fact i usually work with STL instead of any other c++ library, why? well for a start, it is easier to port the code to another operating system, and second, i don’t like to bloat the app just because i don’t want to leave the comfort of the new “modern” APIs.
Yeah, i know that’s not the best API, or the coolest one, or anything fancy at all, but i like the speed and the small size i get with applications made using just Win32.
A few days ago i decided to try Visual C++ 2008 Express Edition, and i realized that it only supports Win32 applications, and to my surprise, no resource editor, so how new programmers who are interested in learning to program C++ applications will do without the resource editor? is this version of Visual Studio for students and beginners? or for hard core programmers who can really understand the Win32 API inner workings as they have spent several years learning every function, message, parameter and structure supported by this api?
I’ve tried Visual C# 2008 Express, and of course this one does have the resource editor, you can add controls, forms, format and set properties all using visual controls, i guess Microsoft doesn’t want people to actually keep using C++ and instead they want them to go to C#.
Otherwise, i don’t see a reason to remove the resource editor from Visual C++.
Anyway, i have decided to keep the Express edition installed and implement some free apps using this compiler just because well, it is free, it seems fast enough, and i don’t care about the resource editor or any other stuff like that, i like to program like in the old days, if anything just to complicate my life and spend two hours building a user interface that i could get done in 10 minutes using the professional edition, or Visual C# Express.
Life goes on..

Recent Comments