Basic Software Interface Question

JC0133

Senior member
Nov 2, 2010
201
1
76
I have taken a few computer science classes(intro class to Java and C++, a data structure class teaching OOP principles, and fundamental programming languages class that focuses on LISP scheme, Prolog and C++) so I know I have a long way to go.

I have also taken a logic design class where I had to design a micro processor and an assembly language class.

I am trying to understand how does software code interface with other software or hardware?

So far most of my programming projects I have written them in Microsoft Visual C++ and Eclipse.

How would I go about taking in other code to interface with my code?
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
13
81
www.markbetz.net
There are a lot of answers to this question. At the most basic level you might have two languages, C# and Visual Basic, for example, that produce linkable code in a common format. We used to be able to link Turbo Pascal object files to Turbo C++ programs.

Another scenario might involve an interpreter for a scripting language like Python, which is able to call down into C libraries as an extension mechanism.

Still another scenario would be having a common runtime call convention, as with COM/DCOM and RPC mechanisms. And of course you can use any number of means to get two programs written in different languages to communicate: they can share files, use pipes, use sockets, etc.
 

N4g4rok

Senior member
Sep 21, 2011
285
0
0
If you're doing Windows programming, you can use .dll files to hold classes and structures that you would like to use elsewhere. I keep a .dll around that holds various sorting mechanisms and data structures just because i'll use them in different .NET languages.
 

brandonb

Diamond Member
Oct 17, 2006
3,731
2
0
As the guys said there are many different ways to handle this and the question is not specific enough.

Typically on modern operating systems, each process get's it's own virtual addresses (memory) which looks like a blank slate to operate with it. Typically these processes are .exe on the windows environment. When an .exe starts up, it gets it's own virtual address space.

If you need to interact with different code, such as provided by an API/SDK. Think of it like a video game. A game developer creates a process or .exe, then it uses .lib files which LoadLibrary to the directx runtime .dlls. These .dlls are loaded through the .lib files, and the .dll is loaded into the .exe virtual address space, and it now has access to these functions. DirectX then goes through some windows/kernel code to interact with the WDDM compatible driver (be it ATI/Nvidia whatever).

The video driver exposes functions or needs to have an interface which is compatible with the Windows Operating system. To make it WDDM compatible, and expose an interface which has a directx compatibility level. They call them feature levels. The DirectX api then provides this information to the app so it can turn on/off features within the app.

Think of it like this:

App <--> DirectX <---> Windows <---> WDDM Driver <---> Graphics Card

Each of those only knows about the levels around it. App only cares about DirectX. It doesn't know how DirectX operates with Windows the driver or graphics card. The graphics card doesn't know anything about Windows or the App or DirectX.

The APP and directX are loaded into the app's address space. Windows and the driver are in the windows address space.

Now you can apply the same type of logic with any external code. You either need to load a .dll or dynamic library into your address space. Or you need to create a way to communicate to another process if the external app in another address space. Many servers just use TCPIP and create network packets to communicate. Such as HTTP, SQL Server, etc. But there are many other methods as well like already mentioned in previous responses.
 

JC0133

Senior member
Nov 2, 2010
201
1
76
Thank you, this makes a little more sense to me now.

I am just curious what, type of class would I take in my B.S for computer science where I will deal with .dll files libraries or coding them?
 

JC0133

Senior member
Nov 2, 2010
201
1
76
I have another question, how does header files work in C or C++? Do they exist in Java?
 

BrightCandle

Diamond Member
Mar 15, 2007
4,762
0
76
The most common is interupts. Most programs speak to the operating system and get out of their memory space using a software interrupt which contains enough information for the OS to root the call to the right code and get the function completed. We interface with that mechanism with various libraries that hide that detail away but that is how software interfaces with the OS.

Header files basically just say what functions and data elements exist in some actual thing of code. They can contain code of their own but its included (literally textually) into the file that included it and then that is what is then compiled with the assumption that methods without actual code can be found at link time later on. The concept doesn't exist within Java, the closest thing is an interface although its really nothing like the same thing.
 

Merad

Platinum Member
May 31, 2010
2,586
19
81
Have you covered anything about how functions are called in C? The way that parameters, the return address, and so on are pushed onto the stack? Well, there are several different ways this can be done (known as calling conventions). As long as you know the calling convention that a function uses and its address in memory, then you can call it. DLLs are just a mechanism that windows provides to easily load a set of functions find the ones you're interested in.

I am just curious what, type of class would I take in my B.S for computer science where I will deal with .dll files libraries or coding them?

Kind doubt that any university courses get into them, unless maybe your school offers an operating systems course that deals with windows.
 

Mark R

Diamond Member
Oct 9, 1999
8,513
14
81
I am trying to understand how does software code interface with other software or hardware?
At the very lowest level, software talks to hardware devices by accessing the hardware device's interface.

This is most easily seen with some very simple, old CPUs like the 8086, or modern microcontrollers like the PIC 16 series.

A common way of doing this is for the peripheral to intercept memory access (so called memory mapped). The peripheral essentially appears to software as a memory location. For example, the PIC16 series chips have a series of pins which can be used for digital inputs (e.g. switches). To access them, the software just accesses a memory location specified in the MCU manual. Inside the MCU, a series of logic gates intercept the signals going to the RAM, and when they detect a read to the specified address, instead sends the state of the pins.

Some CPUs like the x86 series had a second bus for peripherals, so that peripherals didn't have to sit on the high speed memory bus. x86 CPUs have a specific instructions that send/receive signals on this second port - and historically, this port would connect to the ISA bus, serial ports, etc. These days, these buses no longer exist in the same way and this stuff is all emulated. Most peripherals in a modern PC are memory mapped, and the job of the memory controller is to work out what reads/writes go to RAM and which should be routed to a PCI-E port (as well as much, much more).

In a modern OS, all this low-level stuff is handled by the OS and drivers, with the OS providing a universal, stable interface - often called an abstraction layer. There are a variety of methods that OSs use for permitting software to access OS functions: software triggered interrupts, tables of addresses to jump to, etc.

The OS designer provides a mechanism for software to request a specific hardware function. The OS and the hardware driver then translate that function into specific proprietary requests from the actual hardware itself. This permits software to function in a consistent way with different hardware.

In the early days of PCs, software had to be specifically designed for specific makes and models of hardware. E.g. if you wanted to play a game, you'd have to check whether the game was compatible with your sound card. There was no OS driver at that stage, the game developers had to have bought the programming manual from the card manufacturer and coded the sound system specifically for that make and model of card.
 

JC0133

Senior member
Nov 2, 2010
201
1
76
Thanks guys, I really appreciate your responses/help.

For the most part I understood everything your wrote.

If you guys know of any good websites/books that I could read that would help me on these topics please let me know.

I am going to Google some of these topics and will post more questions if I have them in the future.
 

uclabachelor

Senior member
Nov 9, 2009
448
0
71
Thanks guys, I really appreciate your responses/help.

For the most part I understood everything your wrote.

If you guys know of any good websites/books that I could read that would help me on these topics please let me know.

I am going to Google some of these topics and will post more questions if I have them in the future.

The best way to learn would be to get your hands on a Microchip starter kit for around $30 - $100 and get hands on and start coding in C/C++.
 

Savatar

Senior member
Apr 21, 2009
230
1
76
If you guys know of any good websites/books that I could read that would help me on these topics please let me know.

A couple of good Windows system programming texts are:
http://www.amazon.com/dp/0321657748
and
http://www.amazon.com/dp/0735663777

These are the two most recent, anyway, and primarily target Windows Vista / Windows 7. These focus mostly on how Windows works in general on a relatively low level, if you want to go into more depth... though generally this is not needed for the average person who just wants to write or use a DLL once in a while. Richter's text seems to have much more depth on DLLs, with over 100 pages on the topic, while Hart's text goes into some other areas that Richter does not (such as networking). Hart is probably more digestible, while Richter seems more advanced.

Either way, most Windows (and Linux) programming requires a good working knowledge of C/C++. Higher level languages like Java or C# usually have to use functions originally written in lower-level languages at some point to get work done (though Midori might change some of that if it's successful - which is a rumored upcoming language from Microsoft that is supposed to be high enough and low enough to do most everything you need to do).
 
Last edited:

Carson Dyle

Diamond Member
Jul 2, 2012
8,174
524
126
Can anyone recommend a decent and relatively easy to use compiler/linker for writing Windows console (command-line) programs? I'm interested in writing some real-world (not commercial, but for my own use) utilities in C, with which I'm familiar, rather than trying to get into a GUI environment. I do need to be able to make dll calls and I need to be able to work with both SQlite and MySQL databases.
 

Savatar

Senior member
Apr 21, 2009
230
1
76
Can anyone recommend a decent and relatively easy to use compiler/linker for writing Windows console (command-line) programs? I'm interested in writing some real-world (not commercial, but for my own use) utilities in C, with which I'm familiar, rather than trying to get into a GUI environment. I do need to be able to make dll calls and I need to be able to work with both SQlite and MySQL databases.

It might be good to make this its own post so that more people can see it as a new question/thread... but I would recommend either Visual Studio Express (which includes a full graphical IDE and cl.exe which drives the compiler/linker), or either the cygwin or mingw port of gcc (that's just a command-line compiler, though you can still develop either console or graphical applications with it). You have the option of having the Eclipse IDE on top of any of these, and I would recommend an IDE of some sort (like Eclipse) if you choose gcc/g++.

All of the above options are free.

Visual Studio Express would probably be the easiest option for Windows development, especially if you plan on using existing code samples anywhere... they will usually have .sln files which Visual Studio recognizes and can open the project with everything set up for you.

Here are some links for reference:
Visual Studio Express: http://www.visualstudio.com/en-US/products/visual-studio-express-vs The one you would want is Visual Studio Express 2013 for Windows Desktop - it's the third option on the page. 'Win32' is console applications or DLLs.
Eclipse IDE: http://www.eclipse.org/downloads/moreinfo/c.php
Eclipse IDE does not include a compiler, but will work with most of them - some info on compiler options: http://www.eclipse.org/downloads/moreinfo/parts/c_compiler.php

Working with SQLite or MySQL is a matter of just referencing the necessary third-party connectors for C++ (or using ODBC). For example, for MySQL: http://dev.mysql.com/downloads/connector/cpp/
 
Last edited:

Carson Dyle

Diamond Member
Jul 2, 2012
8,174
524
126
Thanks. That's a good start. Does Visual Studio Express include the C compiler? And is cl.exe both the compiler and the linker?
 

Savatar

Senior member
Apr 21, 2009
230
1
76
Thanks. That's a good start. Does Visual Studio Express include the C compiler? And is cl.exe both the compiler and the linker?

Yes, although it only mentions C++ on the page, you can compile .c files as well. The steps to make your project ANSI C instead of C++ should be the same as outlined here on StackOverflow: http://stackoverflow.com/questions/5770858/how-to-develop-c-with-visual-studio-2010

I think cl.exe is just the compiler, but it handles linking tasks as well (it may just separately call link.exe to perform the linking, but I am not sure). Someone else please confirm/correct me on that.

If you are using the IDE, as long the project properties are set up to specify what all needs to be referenced/linked, then it should handle everything for you when you build the project. Some advanced cases may require developers to modify the several command-line parameters which control the compiler (CL.exe), and I have had to change some of those in special cases. Here are some links for reference:

http://msdn.microsoft.com/en-us/library/f35ctcxw.aspx - A summary of the main executables used by Visual Studio
http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx - A summary of the "compiler/linker" (CL.exe) options
http://msdn.microsoft.com/en-us/library/y0zzbyt4.aspx - A summary of the linker options

Some of the relevant information on how to enable ANSI C for VS (Visual Studio) is quoted from StackOverflow below:
Step one is setting the compiler to produce C code, rather than C++ code. Do that from your project's Properties. Expand the C/C++ header, and click on "Advanced". Set the "Compile As" property to "Compile as C Code" (this is the same as specifying the /TC switch on the command line). Even easier is to just name your files with a *.c extension.

Step two is disabling Microsoft's extensions to the ANSI standards. These are governed by the /Za and /Ze compiler switches. You can find these in your project's Properties, as well. /Za causes the compiler to emit an error for language constructs that are not compliant with the ANSI standard. The /Ze switch enables Microsoft-specific extensions; you want to make sure that this one is turned off.

Although I don't believe that Microsoft fully supports the C99 standard. See (and vote for!) this bug report on MS Connect, this blog entry from the VC++ team, and this page for a concrete example of where that lack of support becomes evident. It does, however, have full support for the C90 standard.

It sounds like, for the most part, just using files with a .c extension instead of .cpp extension should do it. I remember reading that C99 and/or C++11 support is improved in Visual Studio 2013, but I would have to dig up a link for that specifically.
 
Last edited:
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |