C# Tip



Nondeterministic Behavior Of Destructors...

In C++, we can define a destructor in a class to perform the clean up jobs. .NET framework also allows to define destructors. But destructors in .NET are different than those in C++. In C++, the destructor gets called when the object is destroyed. In .NET also destructor is called when the object is destroyed. However, when the object would get destroyed is undeterministic. Because, the object is destroyed only when the Garbage Collector is invoked. So, when the destructor of the object would get called is also Nondeterministic. 

Top


VB.NET Tip



Accessing Database Using OLEDB.NET...

Create a database called bank and add a table called account with three fields accno, name and balance. Create a console application. In this application we will connect to the database and display the contents of the table account on the console output. To be able to use class OLEDBDataReader  write following line at the top in 'Module1.Vb'.

Imports System.Data.OleDb

Create the connection string and the command strings. Then create OleDbConnection object and OleDbCommand object. Using the command object execute the query. Write code in Sub Main( ) as shown below:

Sub Main( )

Dim connectionstr As String = "Provider = Microsoft.Jet.OLEDB.4.0 ;Data Source = c:\bank.mdb"
Dim commandstr As String = "SELECT accno, name, balance from account"

Dim connection As New OleDbConnection ( connectionstr )
Dim command As New OleDbCommand ( commandstr, connection )
connection.Open( )
Dim r As OleDbDataReader = command.ExecuteReader( )

While r.Read( )

Console.WriteLine ( r(0) & r(1) & r(2) )

End While
connection.Close( )

End Sub

Top


Device Drivers Tip



Memory Mapped Device Registers...


The memory mapped device registers use the memory address bus. The device that simply have many device register usually are memory mapped. Accessing memory mapped device register is definitely faster than I/O mapped device registers. More often than not device have more than 1 device register. Each device register has a unique location number either in the I/o address space or memory address space. Thus a device tends to work in a range of address. For example a parallel port device works in the range of 378h - 37Fh. A list of all the I/O mapped devices along with their range can be viewed from the computer management applet. Select computer management and browse System tools | System information | Hardware resources | I/O.

Top


VC++ Tip



How do I write code that hides current dialog and displays a new dialog when a button is pressed and on pressing a button of the new dialog it dismisses new dialog and unhide the previous dialog?

Create a dialog based application. Add a button called 'Next' and add a handler for it. Add a new dialog using Resource Editor. Add a class say Dialog1 to handle the newly added dialog. Add a button called 'Previous' to new dialog and add a handler for it. Now add code to OnNext( ) as shown below:

void CMyDlg :: OnNext( ) 
{

this -> ShowWindow ( SW_HIDE ) ;
Dialog1 dlg ( this ) ; // this is the address of parent dialog
dlg.DoModal( ) ;

}

 

Add a data member called m_parent of type CWnd* to Dialog1 class. Collect the address of parent window in m_parent in the constructor as shown below:

Dialog1 :: Dialog1 ( CWnd* pParent /*=NULL*/ )
: CDialog ( Dialog1 :: IDD, pParent )
{

//AppWizard generated code
m_parent = pParent ;

}

 

Now, add code to OnPrevious( ) handler as shown below:

#include "MyDlg.h"
void Dialog1 :: OnPrevious( ) 
{

EndDialog ( 1 ) ; // to dismiss current dialog
( ( CMyDlg * ) m_parent ) -> ShowWindow ( SW_SHOW ) ; // to show previous dialog

}

Top


C++ Tip



The istream_withassign class has been derived from the istream class and overloaded assignment operator has been added to it. The _withassign classes are much like their base classes except that they include overloaded assignment operators. Using these operators the objects of the _withassign classes can be copied. The istream, ostream, and iostream classes are made uncopyable by making their overloaded copy constructor and assignment operators private.

Top


C Tip



How do I know how many elements an array can hold?

Ans: The amount of memory an array can consume depends on the data type of an array. In DOS environment, the amount of memory an array can consume depends on the current memory model (i.e Tiny, Small, Large, Huge, etc.). In general an array cannot consume more than 64 kb. Consider following program, which shows the maximum number of elements an array of type int, float and char can have in case of Small memory model.

main( )
{

int i[32767] ;
float f[16383] ;

char s[65535] ;

}

Top


Article – C# - ASP .NET Services - I



A Web service is an application stored on a machine that can be accessible through another machine over Internet or LAN. Even before introduction of Web services we were able to access applications or business logics across the net. Therefore, before starting with Web Services we must know the need that gave rise to Web services.

To begin with we would discuss the four Ps that are important in doing business using computers.

  •  Partners: Every business needs partners and that is how they make enormous amount of profit.

  • Profit: No business can run without making profits. Profit must increase every year to make the business successful.

  • Productivity: Computer as its very nature can be used to improve productivity of a business and hence the profit.

  • Programming should be cheap: If computer is to improve productivity of the business programming and maintenance cost should decrease.

Let us now understand the current business scenario. We would take an example of an airlines company. The customers of the airlines company may access the company through personal computers, PDAs or simple phones. The airlines company may communicate with partners such as a food company or the bank. Partners and clients would still be there but the way they would interact would be different. The airlines company would have a web server to which clients would send requests for ASP or HTML pages. The request would be in form of HTTP request. The Web Server would communicate with the business logic in the application server and use the data bases to store the data. The Web Server would respond by sending HTML back to the clients. The food company and bank organization would have application servers running business logic in the form of components. They would also have data base servers for secured and efficient data storage. If airlines company is to access the business logic exposed by application servers of food company and bank it would do so through Remote Procedure Calls. Also the food company and bank may also be interacting with each other.

Different client organizations would use various software and programming model. Even the Operating Systems installed on the client devices would be different. The client would like to interact with the Web Server using these devices. The Web Server of the Airline company may either have IIS, JWS or Apache server running appropriate sever side scripts. The food company may have COM+ model on their Application servers with business logic implemented as COM components and MS-SQL database. The bank organization may have J2EE model with business logic implemented as EJB components running on their Application Servers and data base in Oracle.

In a distributed computing architecture the clients form the Presentation layer and the DCOM components, EJB components, CORBA components and DCOM components form the Business layer. The clients has to cross the firewalls to access components. Firewalls ensure that communication is done through a specified port and data format. The external applications, databases and legacy system form the Data layer. In our Airline example, the main reason of conflict is that all the three interacting companies (airlines company, food company and bank) have different standards. The airlines company has CORBA components installed. The food company has DCOM components and Bank has EJB components. The problems faced in developing these components are as follows:

  • Language: DCOM components could be written only in VC++ or VB, whereas, EJB components could be written only in Java.

  • Infrastructure: CORBA components need ORB libraries and services. DCOM components need COM libraries and services, and EJB components need J2EE Services.

  • Layout of Objects: Layout of CORBA components differ from DCOM components which in turn differs from EJB components.

  • Description: CORBA components are defined using CORBA Interface Description Language, DCOM components are defined using Microsoft Interface definition languages and EJB components are exposed as interfaces.

  • Discovery Standards: CORBA components are discovered using the CORBA registry, DCOM using the Registry and EJB using the Java Native Directory Interface.

The conflict between these models occur mainly due to the Wire Protocol and Data Standard. This was different for each of the infrastructure. CORBA uses IIOP (Inter Internet Object Protocol), DCOM uses RPC (Remote Procedure Calls) and EJB uses RMI (Remote Method Invocation) / IIOP. All these protocols are non-standard protocols and hence are not followed by all companies.

These existing Distributed Computing solutions suffer from various problems. For example, DCOM is a proprietary protocol. It does not support interoperability and it has firewall problems because DCOM transfers data in binary format and it uses many ports to call remote functions. CORBA uses IIOP protocol, which is non-internet friendly. EJB requires very costly infrastructure. Moreover all these object models require their client to use the same libraries as that used on server. This makes a very tight coupling between client and the component. If component is changed and written using new object model the client will also have to change.

To address these needs, XML Web services came into existence and were introduced as part of ASP.NET, which is part of the .NET Framework. Web services are based on open Industry standards, such as HTTP, XML, and SOAP. Using these open standards, Web services deliver application functionality across the Web to any type of client, on any platform.

XML Web services are based on open Web standards that are broadly supported and are used for communication and data formats. XML Web services provide the ability to expose application logic as URI-addressable resources, available to any client in a platform-independent way. Web services are self-describing. Any clients incorporating open Web standards for communication and data formatting (HTTP and XML) can query dynamically for Web service information and retrieve an XML document describing the location and interfaces supported by a particular XML Web service. These open standards make Web services indifferent to the operating system, object model, and programming language used. Web services are accessible to disparate systems, supporting application interoperability to an unprecedented level thanks to the ubiquity of HTTP and XML.

Instead of communicating in binary formats between applications, Web services use XML-encoded messages. Because XML-based messaging is used for the data interchange, a high level of abstraction exists between a Web service implementation and the client. This frees the client from needing to know anything about a Web service except for its location, method signatures, and return values. Additionally, most Web services are exposed and accessed via HTTP, virtually eliminating firewall issues.

We would see more about Web services, the protocols they use and the way they are discovered in the next article.

To be continued...

Top


Joke



After an unusually severe windstorm, Dorsey, a farmer, called his insurance claims adjuster to come to his farm to survey the damage. One major mishap was that the barn roof had been lifted off intact and carried nearly 50 meters from the barn. The adjuster had been there for ten minutes when he said, ”Well, it looks like you lost your roof.” “Nope,”Dorsey replied, ”It’s not lost. It just isn’t where I want it.”

Top


Different Strokes




An Illusion!

Top