C++/Database in C++ w/ Little Experience
Expert: Ralph McArdell - 5/22/2007
QuestionI have a little experience in C++ (I've taken the beginning course in the language offered at my school). I'm trying to write a program for work (I'm not employed as a programmer, it would just make my job easier) and I'm hoping you can point me in the right direction.
I have an excel spreadsheet with over 900 rows of information spread over 8 or 9 columns. I would like to write a program in C++ (because I'm a little familiar with that language) that will allow me to read and write to the spreadsheet, filter data and run reports, which I would write the algorithms for. I would like this program to have a gui.
Basically, in my programming classes, we never talked about or got to reading and writing to an excel spreadsheet, or gui and I was hoping you could tell me which topics within C++ I would need to learn about in order to have the knowledge to write this program (by topic, I mean something that would be easy to search for in a book or online, such as "arrays", "recursive functions" etc).
I realize this is a pretty open question, but if you can point me in the right direction, I'm pretty motivated to learn it. Any free resources online that might deal with this subject that you know about would also be greatly appreciated.
Thank you in advance for your time.
AnswerWhen writing programs that communicate and control with Excel or other applications, you will need to use the facilities provided for you to do so by those who created the application. This has little to do with C++ - you could use C or Visual Basic or some other language providing it can use the provided facilities. The ability to communicate and control one application from another is the job of the Microsoft COM (Common Object Model) and OLE (Object Linking and Embedding) technologies. The specific part of these of interest here is called OLE Automation. OLE/COM uses UNICODE strings, so some understanding UNICODE will be useful (note: the NT based MS Windows operating systems, including Windows 2000 and Windows XP use 16-bit UNICODE character encoding internally).
Likewise when writing GUIs you will need to understand the way MS Windows windows programs work.
The raw MS Windows system APIs (application programming interface) are C APIs, that is they are designed to be callable from C. Hence there are no classes, class or function templates, no function or operator overloading and no class hierarchies to make life easier for the developer. You will therefore need to have a good grasp of the C parts of C++ and the limitations of C with respect to C++. You will need to understand arrays and pointers, and pointers to pointers. C struct and union user defined data types will also feature heavily in the raw C Win32 platform SDK (software development kit) (Win32 is the name for the collection of 32-bit MS Windows operating systems).
As you are planning on using C++ then you can use C++ libraries to help make developing using these Microsoft technologies easier. Two such libraries supplied by Microsoft with their Visual C++ product are the MFC (Microsoft Foundation Classes) and the ATL (Active Template Library). To use these of course you will require a grounding in C++ programming concepts such as classes and objects, class hierarchies, virtual functions, templates (especially where the ATL is concerned), construction a destruction, objects, operator overloading. Note that the MFC and ATL are not the only choices, especially in the area of GUI development.
So in short you are going to require a good understanding of C/C++ to start with and then a lot of specific information on Windows programming and COM/OLE/OLE automation programming, and then specific information on the COM/OLE/OLE automation interfaces defined for Excel and their usage. You will also require a Windows based C++ development tool set (compiler, linker etc.) and the Win32 platform SDK or equivalent header files and libraries to allow the use of Windows system facilities from your application, and of course the similar development resources for Excel.
None of these are small or easy topics and so you are likely to be overwhelmed with all the things you need to know before making a start. On the other hand you might be able to locate some simple examples of doing these sorts of things with Excel to get you started and work up and out from those. If you can then you do not need to know everything all at once, you can progress one piece at a time, learning what you require for each step. I suggest that the more examples you can find to help with understanding the things you need to do the better. You can then lookup anything in examples you do not understand. This will get you a more targeted set of knowledge. What you learn is exactly what you require to complete your task! You can fill in the blanks later if you feel the need. Here is one article on the Microsoft site that might be an interesting starting point. It mainly uses a C subset of C++ as far as I can tell:
http://support.microsoft.com/kb/216686 This also might be of interest but it looks to be somewhat out of date:
http://xlw.sourceforge.net/
A good place to start for Microsoft development information is the MSDN (Microsoft Developer Network) web site at
http://msdn2.microsoft.com/
You can of course easily find many online resources – the two I noted above came from a Google search of:
Excel C++
Hope this is of some help.