Tuesday, August 14, 2012

DllImport in C# vs VB.NET (unmanaged DLL Import)

The following code example shows how to use the DllImportAttribute attribute to import the Win32 MessageBox function. The code example then calls the imported method.
C#

using System;
using System.Runtime.InteropServices;

class Example
{
// Use DllImport to import the Win32 MessageBox function.
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);

static void Main()
{
// Call the MessageBox function using platform invoke.
MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);
}
}
VB.NET
Imports System
Imports System.Runtime.InteropServices

Module Example

' Use DllImport to import the Win32 MessageBox function.
"user32.dll"
, CharSet:=CharSet.Unicode)> _ Function MessageBox(ByVal hwnd As IntPtr, ByVal t As String, ByVal caption As String, ByVal t2 As UInt32) As Integer End Function Sub Main() ' Call the MessageBox function using platform invoke. MessageBox(New IntPtr(0), "Hello World!", "Hello Dialog", 0) End Sub End Module
Source : msdn 
url :http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx

Thursday, August 9, 2012

How to open visual studio 2010 projects in visual studio 2008 (downgrade from VS 2010 to VS 2008)

1.Make back up of your .sln file
 

2.Open the .sln file corresponding to the Project to be converted with Notepad
 

Locate the following line: Microsoft Visual Studio Solution File, Format Version 11.00 Replace 11.00 with 10.00

3.Locate the following line: # Visual Studio 10

4.Replace 2010 with 2008

5.Save the File

6.Delete the .cache files existing in the following paths:
* obj/debug
* obj/release

7.Open the project with Visual Studio 2008

8.Build the project with Visual Studio 2008