Category — Windows Development
This is my take on choosing between Java and .NET for writing client applications.Â I’m writing off the top of my head, since if I start doing research, I’ll up with a 10-post series that will be done next year or so…
Although both Java and .NET are good programming platforms, I think .NET is the default choice for industrial automation programmers writing Windows desktop apps because it’s a good choice, Microsoft is dominant in the industrial sector, and Microsoft typically has the best GUI designers.
Both Java and .NET are mature and extensive development platforms, with many choices of target devices, programming languages, IDEs, and libraries.
Java doesn’t quite run everywhere, but it’s available on a wide variety of platforms, such as Windows PCs, Linux, MacOS X and many embedded systems.Â Android is closely modeled after Java, although I’m not sure how close the libraries are.
.NET’s full runtime is available on standard Windows; subsets are available for Windows 8 RT, Windows Phone, Windows CE, and via the independent Mono project, Linux, Android, iOS, and MacOS X.
The most popular Java IDEs are Eclipse, NetBeans, and IntelliJ.Â Eclipse and NetBeans are both open source.Â Eclipse has a lot of add-ins, and is also widely used in non-Java applications such as embedded development.Â NetBeans is supposed to have a good GUI designer.
Visual Studio is by far the dominant .NET IDE; it is an excellent IDE, but there are also two good open source IDE’s, SharpDevelop (aka #develop) and MonoDevelop.Â The Visual Studio Express editions are free and quite powerful, although if you’re doing a lot of development I’d recommend paying for the professional version.Â The last version that can run on Windows XP systems is 2010; VS 2012 can compile code for XP, but won’t run on XP.
The main .NET libraries are WinForms and WPF (based on XAML). I’ve heard good things about Microsoft’s Expression GUI designer (used for WPF); I’ve just checked and Microsoft is integrating Expression Blend into Visual Studio, while Expression Designer 4 is now a free download without tech support.
My impression is that .NET has better GUI designers, but Java’s libraries have better layout managers (for creating a GUI in code).Â There are definitely many more graphical components available for .NET (spreadsheets, charts, reporting, etc).
Both Java and .NET have a lot of good libraries available.Â In fact, there is a lot of cross-p0llination: good libraries on one side are often ported to other side or inspire projects on the other side.
Books and Resources
Unlike in the PLC world, there are a lot of excellent books available for both Java and .NET, including programming, development techniques, and advanced topics.Â Plus, there are tremendous resources available via the internet including blogs and Q&A sites such as StackOverflow.
Amazon and its multitude of reviews are a great place to find good programming books, new or used, but if you’re looking for eBooks, remember to check out the publisher, too.Â For example, if you buy an eBook from Manning, you get the book in three formats (PDF, ePub, Kindle).Â Also, many Manning books include a downloadable PDF of the book if you register it.
I typically buy used books from Amazon because I still prefer real books, and they’re much cheaper than most eBooks.
Other Programming Languages
One of the best features of both .NET and Java are the many programming languages available that are pretty (but not perfectly) compatible with the other languages in that ecosystem.Â This makes multi-language programming eaiser; for example, you can use C# for the foundation and IronPython to add interactive scripting to a .NET application.
July 3, 2013 6 Comments
I recently came across this problem: The application failed to start because the application configuration is incorrect.
I searched for answers, but none of them (such as looking for missing runtime DLLs) fixed my problem.Â So I looked at the System Log using the Windows XP Event Viewer, and found this SideBySide error: Syntax Error in policy file “program_path\program.exe.config” on line 1
Well, there’s not much on line 1 (the first line of the XML config file) so I thought about it and changed the encoding from encoding=”Windows-1252″ to encoding=”UTF-8“.Â Voila!Â Problem solved!
I’m sure it’s not the solution to many application configuration errors, but it’s another possibility to check out — although what you need to change encoding to will probably vary depending on the computer.
July 1, 2013 No Comments
I have a substantial amount of Python code that needs to talk to the Microsoft world using COM (both as a client and as a server).Â Parts of the Python COM server are pretty slick, such as dynamic dispatch (I use dynamic dispatch to automatically make Python methods whose name match a specific pattern available via COM).
However, it’s much harder to debug a Python COM server.Â In VB6, I can start an out of process COM server from the IDE, wait for clients to connect, and easily use all the VB debugging goodness….
But I can’t do that in Python.Â Most of the time I’ve managed OK by either testing the code via a different non-COM interface or using logging.Â However, I did find a better solution for when I just have to see what’s going on: Winpdb.
Winpdb is a cross-platform (Windows, Linux, and possibly more – not just Windows) remote debugger with a graphical interface.Â I installed it without problems (basically, installed wxPython then Winpdb), and used the embedded debugging feature.Â Just remember to remove the debugging code when you’re done.
May 15, 2013 No Comments
I’m running the 64-bit version of Windows.Â Overall, Microsoft has done a good job of handling 32-bit programs, but occasionally the differences can still cause problems.
For example, recently I decide to use Copley’s CMO V2.18 COM library from Python.Â When I tried to create the CANOpen object, I get this error:
“The Application failed to initialize properly” with an error number of 0xC000007B
The problem?Â I had installed the 64-bit version of Python 2.7, and COM calls from 64-bit applications (e.g. Python) to 32-bit applications (e.g. CMO) do not work.Â So I un-installed the 64-bit version and installed the 32-bit version.
September 29, 2012 No Comments
I just bought a lot of software development books, mostly centered on Microsoft’s .NET Framework.Â I have a code base that is getting old and creaky (for example, parts are written in VB6) and it’s time to look at re-doing it, using Visual Studio 2010.
I’m tempted to write everything in a mix of F# and Boo, but I won’t, because it would be hard for almost anyone else to maintain it.Â Instead, I’m planning on mostly C#, with maybe some IronPython thrown in (for rapid customization).
I’m reading each book quickly first to get an idea of what I can learn, then I will go back in depth for the techniques that I will use.
So what is on my list?
- C# In Depth, Second Edition — to make sure I’m up to speed with all the latest changes to C#.Â I haven’t read it yet.
- Functional Programming in C# — highly recommended; it’s well written and shows how to use a lot of the functional techniques I’ve come to love from using Python; in short, it makes C# much more usable.Â However, if you aren’t already familiar with concepts such as closures, first class functions, and lambdas, it’s going to be slow going for a while — and consider learning them in another language first (such as Lua using Programming in Lua).
- The Art of Unit Testing: With Examples in .NET — highly recommended; it provides lots of practical advice and best practices for creating unit tests that work well.
- IronPython In Action — I haven’t read it yet, but it looks good, with a lot of best practices advice.
- Practical Statecharts in C/C++, First Edition — I haven’t read it yet.Â This book is really aimed at embedded developers, and although I don’t plan on using the author’s Quantum Programming framework, I think I will get some good ideas from it.
The Manning books all include a free PDF of the book when you register your book.Â I haven’t done this yet, but I will soon.
All my books are real, not e-books, because I prefer real books when learning a new topic, the paper books were cheaper or about the same price, and I won’t buy ebooks that require a proprietary reader (such as Kindle or Apple books).
September 12, 2011 No Comments
OK, this isn’t just for VB6, but I needed to call a function in a C DLL from VB6, and VB6 can only call functions that use the stdcall calling convention.
A properly written C DLL is easy to use from VB6, but a C DLL not written with VB6 in mind may require an adapter layer. C++ DLLs are typically very difficult to use from another compiler (or VB), due to incompatibilities in areas such as name mangling. Of course, COM DLLs and .NET assembly DLLs are totally different cases. COM objects are almost always easy to call from VB6. .NET assemblies are like C DLL’s: when properly designed with a COM interop, using them is like using a COM object, but if they’re not designed with COM in mind, then they can’t be used.
If you have the source or header files, you should be able to determine the calling convention – although you may have to know a bit about the compiler, too (so you know what the default convention is, and how each convention is identified).
A second method that sometimes works is to use Microsoft’s dumpbin program. You can get dumpbin for free by downloading and registering Visual C++ 2005 Express Edition (notes on Win32 development here) . By dumping the Export list and looking at the decorated names, you can determine the calling convention. I got the idea for this approach from here.
For a function defined as void foo(int a), its decorated name would be:
- _foo for __cdecl (C calling convention)
- _foo@4 for __stdcall (Windows calling convention)
- @foo@4 for __fastcall
I used dumpbin /EXPORTS path_to_dll from the Visual C++ 2005EE command prompt. However, not all DLLs export the decorated names, even for DLLs created with MS VC++. I’ve seen some that do and some that don’t; it might have to do with how the exported names are declared (e.g. in a DEF file). Non-Microsoft C compilers (MingW, gcc, Borland, etc) might decorate names differently.
By the way, you can use dumpbin /DEPENDENTS path_to_DLL to see what DLLs a DLL requires.
Another way is to use Python and the ctypes module. The ctypes module is included in Python 2.5; it’s an add-on to earlier versions. ctypes can load a DLL as either a Windows (stdcall) DLL using windll.LoadLibrary or a C (cdecl) DLL using cdll.LoadLibrary.
Here’s an example using Python and two functions in the MEI PC/DSP 2.5.09 MEDVC60F.DLL. One function (dsp_init) is stdcall; the other function (find_pci_dsp) is cdecl.
>>> from ctypes import *
>>> stdcall = windll.LoadLibrary(‘C:\\medvc60f.dll’)
>>> cdecl = cdll.LoadLibrary(‘C:\\medvc60f.dll’)
>>> ShortArray20Type = c_short * 20
>>> addr = ShortArray20Type()
>>> irq = ShortArray20Type()
>>> numBoards = c_short(0)
>>> cdecl.find_pci_dsp(byref(numBoards), byref(addr), byref(irq))
>>> stdcall.find_pci_dsp(byref(numBoards), byref(addr), byref(irq))
Traceback (most recent call last):
File “<interactive input>”, line 1, in <module>
ValueError: Procedure probably called with too many arguments (12 bytes in excess)
Traceback (most recent call last):
File “<interactive input>”, line 1, in <module>
ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong calling convention
October 25, 2007 No Comments