Wednesday, 17 December 2008

Directly accessing a sector on a HDD

You can open a physical or logical drive using the CreateFile() application programming interface (API) with these device names provided that you have the appropriate access rights to the drive (that is, you must be an administrator). You must use both the CreateFile() FILE_SHARE_READ and FILE_SHARE_WRITE flags to gain access to the drive.

Once the logical or physical drive has been opened, you can then perform direct I/O to the data on the entire drive. When performing direct disk I/O, you must seek, read, and write in multiples of sector sizes of the device and on sector boundaries. Call DeviceIoControl() using IOCTL_DISK_GET_DRIVE_GEOMETRY to get the bytes per sector, number of sectors, sectors per track, and so forth, so that you can compute the size of the buffer that you will need.

Note that a Win32-based application cannot open a file by using internal Windows NT object names; for example, attempting to open a CD-ROM drive by opening
\Device\CdRom0
does not work because this is not a valid Win32 device name. An application can use the QueryDosDevice() API to get a list of all valid Win32 device names and see the mapping between a particular Win32 device name and an internal Windows NT object name. An application running at a sufficient privilege level can define, redefine, or delete Win32 device mappings by calling the DefineDosDevice() API.

Friday, 21 November 2008

ORA-00947: not enough values

ORA-00947:not enough values

Cause:This error occurs when a SQL statement requires two sets of values equal in number, but the second set contains fewer items than the first set. This can occur in a WHERE or HAVING clause in which a nested SELECT returns too few columns as in:
WHERE (A,B) IN (SELECT C FROM ...)

Another common cause of this error is an INSERT statement in which the VALUES or SELECT clause does not contain enough values needed for the INSERT, as in


INSERT INTO EMP(EMPNO,ENAME) VALUES('JONES')
Action:Check the number of items in each set and change the SQL statement to make them equal.

Thursday, 20 November 2008

Download And Upload A File Using C#

The System.Net namespace contain most of the .NET base class that deal with networking from perspective of the client. The System.Net namespace is generally concerned with Higher-level operations for example download and upload files and making requests using the HTTP and other protocols.

The WebClient Class

If you want to do is carry out a fairly simple operation such as requesting a file from a particular URL, Then you will probably find easiest .NET class to use is System.Net.WebClient. This class is extremely high-level class Designed to perform basic operations with only one or two commands

Downloading Fiels:

There are two ways of downloading a file from a web site using WebClient, depending on whether we want to save the file, or process the contents of the directly within your application. If we simply want to save the file then we should call the DownloadFile() method takes two parameters, The URL from where we want to retrieve the file, and the file name ( or path) that we want to save the file to.




WebClient Client = new WebClient ();
Client.DownloadFile("http://www.csharpfriends.com/Members/index.aspx", " index.aspx");






More commonly, your application will want to process the data retrieved from the web site. In order to do this, you use the OpenRead () method, Which returns a stream reference. You can then simply retrieve the data from the stream.




WebClient Client = new WebClient ();
Stream strm = Client.OpenRead ("http://www.csharpfriends.com/Members/index.aspx");






The following code will demonstrate the WebClient.OpenRead () method.

In this case we will simply display the contents of the downloaded data in list box.

We create the project as standard Windows C# application, and a list box called listbox1, in which we will display the contents of the downloaded file. We make the following changes to the constructor of the main form.




public form1()
{
InitializeComponent();

System.Net.WebClient Client = new WebClient();
Stream strm = Client.OpenRead("http://www.csharpfriends.com");
StreamReader sr = new StreamReader(strm);
string line;
do
{
line = sr.ReadLine();
listbox1.Items.Add(line);
}
while (line !=null);
strm.Close();
}






Updating Files

The webClient class also features UploadFile() and UploadData() methods. The diffrence between them is that UploadFile() uploads a specified file given the file name, While UploadData() uploads binary data, which is supplied as an array of bytes:




WebClient Client = new WebClient();
Client.UploadFile("http://www.csharpfriends.com/Members/index.aspx",
"c:\wesiteFiles\newfile.aspx");

byte [] image;

//code to initialise image so it contains all the binary data for some jpg file
client.UploadData("http://www.csharpfriends.com/Members/images/logocc.jpg", image);





In this way we can download and upload a file through c# project Try to upload files to yours web sites and download files

Wednesday, 29 October 2008

Templates in C++

Templates in C++

Suppose that you are writing a C++ program that requires two stacks--one for integer data and one for string data. You could implement these classes as follows. The implementation below isn't very good (it limits the stack to 100 elements and it does no error checking), but it will serve as an example.

class IntStack {
public:
   IntStack() { top = -1; }
   void push(int i)
      { st[++top] = i; }
   int pop()
      { return st[top--]; }
private:
   int top;
   int st[100];
};
 
class StringStack {
public:
   StringStack() {
 top = -1; }
 
   void push(string i)
      { st[++top] = i; }
   string pop()
      { return st[top--]; }
private:
   int top;
   string st[100];
};
 

The main program would declare and use these stacks as follows:

IntStack ii;
StringStack ss;
ii.push(25);
ss.push("Hello");
 
 

Notice that the only difference between these classes (other than the name of the class) is the type of data that's put onto the stack. C++ allows you to define a single, template class to represent a stack of any possible datatype (including a user-defined datatype). The declaration would look like this:

#ifndef STACK_H
#define STACK_H
template <class T>
class Stack {
public:
   Stack() { top = -1; }
   void push(T i)
      { st[++top] = i; }
   T pop()
      { return st[top--]; }
private:
   int top;
   T st[100];
};
 
 
#endif
 
 

The T represents the type of stack desired. The main program would declare and use the stacks as follows:

 
Stack<int> ii;
Stack ss;
ii.push(25);
ss.push("Hello");
 
 
 

There is never an implementation file (*.cpp) for a template class. All of the member functions should be declared in the header file (in this case, table.h). The following shows how the functions for this class would be declared after the declaration of the class.

#ifndef STACK_H
#define STACK_H
 
 
template <class T>
class Stack {
public:
   Stack();
   void push(T i);
   T pop();
private:
   int top;
   T st[100];
};
 
 
template <class T>
Stack<T>::Stack()
{
   top = -1;
}
 
template <class T>
void Stack<T>::push(T i)
{
   st[++top] = i;
}
 
template <class T>
T Stack<T>::pop()
{
   return st[top--];
}
 
#endif
 
 

Hack into your Administrator account on XP

Change your Limited account to Administrator account on XP

Step One: Identify Who is Administrator

  1. Go to Start > Run...
  2. Type cmd and then press Enter.
  3. Type net user to identify the account name of the local administrator.
  4. Once you have identified the admin account (example here : admin), type in

Step Two: Change Administrator Password

  1. Type in command net user {admin-account-name} * and press Enter. ,replace admin account name with the name of the admin account
  2. When it says enter a password enter whatever password u want to use then press enter(you don’t see the password being typed but it IS being changed)
  3. type your password again then press enter
  4. Type in "exit" and press Enter.

Step Three: Login as Administrator

  1. Log out, and then login into the admin account with your password.
  2. Open User Accounts from Control Panel.
  3. Change your account type as an administrator , or add a new User as Administrator , See if your limited account is in the list (which contains the admin account name, etc) and if it isnt, add it (Click Add...).
  4. you can change numerous file settings. Isnt this sound Bad , don’t try and make any systems get hacked..
  5. Thanks for Co-operation

Tuesday, 21 October 2008

Develop & Deploy RED5 Applications in Tomcat

Introduction:

In this tutorial, we will just have a simple look in How to create Applications for containers… This tutorial explains How to compile the RED5 source into WAR and insert your own code to make the application flexible for the development in J2EE web servers .

Pre-requisites:

Following are the prerequisites for our mission(!) to be accomplished…

1. JDK 1.5

2. Apache Ant

3. The Web Archive source from RED5 ..

The JDK can be downloaded http://java.sun.com/j2se/1.5.0/download.html Apache Ant version 1.6.2 can be downloaded (http://archive.apache.org/dist/ant/binaries/ . The Red source can be downloaded from http://svn1.cvsdude.com/osflash/red5/java/war/trunk/... You may need eclipse to download the entire content

Getting the War source from eclipse:

Open the eclipse , Select Fileà Import à Other à Checkout Projects from SVN à Create a new Repository Location à URL http://svn1.cvsdude.com/osflash/red5/java/war/ à Select Cancel (As we are going to build using ANT)

Now Window à Open Perspective à Other à SVN Repository Exploring

A perspective window is opened with content http://svn1.cvsdude.com/osflash/red5/java/war/

Expand the branch you will see three child nodes 1. branches 2.tags 3. trunk

Right click on Node trunk & select Export

Select a directory , where do you need to keep the source….After the progress is over , switch to next step…

Building a web context (Virtual directory):

Open the source directory on your local computer {src dir } à trunk à www à WEB-INF .. Now we are going to create a scope , I am going to name it samplescope , open a text editor and type the below content..

version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:lang="http://www.springframework.org/schema/lang"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd">

samplescope.context" class="org.red5.server.Context" autowire="byType" />

samplescope.scope" class="org.red5.server.WebScope"

init-method="register">

samplescope.context" />

samplescope.handler" />

samplescope " />

value="*,localhost, localhost:5080, 127.0.0.1:5080" />

samplescope.handler" class="my.first.Application" />

Save this content in a file …samplescope-context.xmlunder WEB-INF folder .. The first bean is to define the context, next bean is to define the scope of the context, and the third denotes the handler for the context

Starting a simple Application:

We are going to create the Handler(application) now…

Goto {src-dir} à trunk à src à { create the src files here}

As we have mentioned my.first.Application

Create directories my à first under src..

Create a java file named Application.java and place it under

{src-dir} à trunk à src à myà first à Application.java

package my.first;

import org.red5.server.adapter.ApplicationAdapter;

public class Application extends ApplicationAdapter {

public String getmyName(){

return “I don’t Know”;

}

public String Congratulate(String b){

return "Alka " + b;

}

//Add as many functions as you need…..

}

Building the source:

Make sure Path variables are pointing to the bin directories of Jdk & ANT installations.. Now open build.xml (present in {src-dir} à trunk à build.xml..

Create a property tag

and insert under

save build.xml

In command prompt either in win or linux

Goto the directory…

{src-dir} à trunk

enter ant and hit the enter key

don’t worry abt minor warnings , verify at last red5.war is finished….

If yes…then fine… if not send a mail to red5 …

The war file will be present in {src-dir} à trunk à red5.war

Deploying WAR file in Tomcat..:

Open the Tomcat manager… usually will be

http://localhost:8080/manager/html

it will prompts for admin username & password , provide it….

And now under a table “ WAR file to upload “ upload the newly build war file…

…That’s it , Our WAR file has been deployed in Tomcat usually deployed with the name of the WAR file….

So it can be accessed via http://localhost:8080/red5

If you have problem in accessing tomcat manager ..

Download the Administration Web Application: of tomcat from http://tomcat.apache.org/download-55.cgi it is usually a zip copy consists of two folders ..

conf & server..

Stop your Tomcat service and replace the two folders in your Tomcat installation directory.. and start service again… and try to deploy the WAR file..

Simple client :

Open flash IDE , use the below code to invoke the functions

nc = new NetConnection();

nc.connect("rtmp://localhost/samplescope");

nc.onStatus = function(info) {

trace("Level: " + info.level + " Code: " + info.code );

}

nc.onResult = function(obj) {

trace("The result is " + obj);

}

nc.call("Congratulate", nc, “ Me”);

The result will be Congratulate Me”