nikhil joshi
windows
Windows related stuff
Modules in CLR
Sep 3rd
Basics
- Packaging deploying and discovering components code in CLR is different from COM, Java or Win 32.
- Programs written in CLR reside in module.
- Module is byte stream typically stored as a file in the local file system or on a web server.
Format of CLR module
- CLR module uses an extended version of PE/COFF executable file format used by Windows NT.
- Due to use of PE/COFF format CLR modules are valid win 32 module that can be loaded using LoadLibrary() system call.
Generating modules at run time
- use System.Reflection.Emit namespace
- CodeDom: it gives higher level of abstraction removing need to know or understand CIL.
Types of modules
RAW, LIBRARY and EXECUTABLE are three types of modules. Let us go through each one in more details
RAW
- By default this modules will use .netmodule file extension.
- This module cannot be deployed by there own nor the CLR can load them directly.
- This module need to be associated with full-fledged components i.e. assembly.
- Usage of raw module
- Multi-language assemblies
- Separately maintained source files
- Small download footprint
- Link the same source files into multiple assemblies
LIBRARY
- By default, this module will use .dll file extension.
- This module contains additional Meta data that allows deploying it as stand-alone code.
- This module cannot be launched as executable program from command shell or windows explorer.
EXECUTABLE
- By default file extensions are .exe (use console UI sub-system) or .winexe (use GUI sub-system)
- Must have initial entry point i.e. method that CLR will execute automatically when the program is launched.
- This method should be static
- This method does not need to declaration as public.
- This method must inside type definition.
- Name of type is immaterial.
- If there are more than one type contains main method, you need to resolve it manually.
Reference
- Essential .NET Volume 1 by Don Box
- MSDN
- etutorials.org
- Netmodule vs. Assembly
WCF
Jul 6th
I was working on WCF. I found some video on MS. They are really good.
Here is the link
http://msdn.microsoft.com/en-us/netframework/first-steps-with-wcf.aspx
WinSock2 Client Server in VC++
Jul 6th
I was working with OpenSSL and VC++, I found that there are very few references available which tell us how to implement OpenSSL through VC++. But real thing missing is Working Client server in VC++ which will communicate through OpenSSL. So Writing one
Lets start with WinSock2 client server.
VC++ Code details
- VS2005
VC++ references required:
(From MSDN)Use the Winsock API by including the Winsock 2 header files. The Winsock2.h header file contains most of the Winsock functions, structures, and definitions. The Ws2tcpip.h header file contains definitions introduced in the WinSock 2 Protocol-Specific Annex document for TCP/IP that includes newer functions and structures used to retrieve IP addresses.
- Add #include <winsock2.h> and #include <ws2tcpip.h> in code
- Add build environment links to the Winsock Library file WS2_32.lib
Source code : click this link WinSock2-BasicClientServer
WinSock2 Server
We need to follow following steps to implement Server
- Initialize Winsock.
- Create and Bind the socket.
- Listen on the socket for a client.
- Accept a connection from a client.
- Receive and send data.
- Disconnect.
WinSock2 Client
- Initialize Winsock.
- Create a socket.
- Connect to the server.
- Send and receive data.
- Disconnect.
This is working fine but no fun. Lets make it working in threads.
Net will be client server communicating with each other in different threads; like read thread and write threads.
Crazy idea…
Jun 11th
I am getting bored while working on daily ‘shit’. nothing really drives me. In office it work i do for last 2 year; so I know how to find solutions for problems. It is not very challenging coding part. So I got and crazy idea.
I will implement RFCs one by one in C# code.
I am choosing C# as this is easy to use and I want to do some heavy coding in C#. Lets see how this work out.
I am staring on http://www.rfc-editor.org/rfcxx00.html form top to bottom.
Windows 7 RC1 Review for hp nx7400 laptop
May 29th
I just installed windows 7 RC on my laptop. This is review
Device drivers status
| Hardware | Working status |
| Display | Working (Auto detected) |
| Dual Screens | Working (Auto detected) |
| Sound | Working (Auto detected) |
| LAN Broadcom 440x 10/100 | Working (Auto detected) |
| WLAN Broadcom 110 | Working (Auto detected) |
| Bluetooth | Not Working by default. |
GUI experience
| GUI | Very good |
| Speed of OS | Very good |
| Networking | Not very impressive |
| Backward GUI compatibility | Bad |
Overall rating 7.5/10
First week
1. Installed Software –Visual Studio 2008.
2. Not even single crash.
3. No lags.
4. Lot of Updates
as this is RC this is acceptable.
Get all database names form MSSQL 2005
Apr 9th
String conxString = “Data Source=” + server + “; Integrated Security=True;”;
using (System.Data.SqlClient.SqlConnection sqlConx = new System.Data.SqlClient.SqlConnection(conxString)) {
sqlConx.Open();
DataTable tblDatabases = sqlConx.GetSchema(“Databases”);
sqlConx.Close();
foreach (DataRow row in tblDatabases.Rows) {
Console.WriteLine(“Database: ” + row["database_name"]);
}
}
Check given IP address is valid for given machine
Mar 24th
Given code useDns.GetHostAddresses(). This function resolves machine host name to IP address. And if IP address is given it check for IP address and if valid returns given IP address.
-
string machineName = "localhost";
-
string checkIP = "127.0.0.1";
-
-
IPAddress[] ipsMachineName = null;
-
IPAddress[] ipsCheckIP = null;
-
//fetch IPs for machine
-
try {
-
ipsMachineName = Dns.GetHostAddresses(machineName);
-
}
-
catch (Exception expMachine) {
-
Console.WriteLine(string.Format("Error while retriving IP address of machine ‘{0}’ : {1} ", machineName, expMachine.Message));
-
return;
-
}
-
//Check IP addrss
-
try {
-
ipsCheckIP = Dns.GetHostAddresses(checkIP);
-
}
-
catch (Exception expIP) {
-
Console.WriteLine(string.Format("Invalid IP address: {0}", expIP.Message));
-
return;
-
}
-
//check ip address.
-
bool validIPAddress = false;
-
foreach (IPAddress machineIP in ipsMachineName) {
-
foreach (IPAddress cIP in ipsCheckIP) {
-
if (string.Compare(machineIP.ToString(), cIP.ToString(), true) == 0) {
-
validIPAddress = true;
-
break;
-
}
-
}
-
if (validIPAddress) {
-
break;
-
}
-
}
-
if (validIPAddress) {
-
Console.WriteLine("Valid IP address");
-
}
-
else {
-
Console.WriteLine("Invalid IP address");
-
}

Recent Comments