.NET interview questions: – Windows API calls in .NET?

Windows API calls are not COM based and they are invoked through Platform Invoke Services.

Declare StringConversionType (Function | Sub) MethodName Lib "DllName" ([Args]) As Type

• StringConversionType is for what type of conversion should take place. Either we can specify Unicode to convert all strings to Unicode values, or Auto to convert strings according to the .NET runtime rules.

• MethodName is the name of the API to call.

• DllName is the name of the DLL.

• Args are any arguments to the API call.

• Type is the return type of the API call.

Below is a sample code for VB.NET, which uses Sleep windows API for delaying.

Public Class Form1
Declare Auto Sub Sleep Lib “kernel32.dll” (ByVal dwMilliseconds As Long)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MessageBox.Show(“ start sleeping for 5000 Milli seconds.....”)
MessageBox.Show(“ end of sleeping.....”)
End Sub
End Class

#region Using directives

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace CSharpCode
partial class Form1 : Form
static extern int Sleep(long dwMilliseconds);
public Form1()
private void Form1_Load(object sender, EventArgs e)
MessageBox.Show(“Starting of 5000 ms...”);
MessageBox.Show(“End of 5000 ms...”);

Also view our video on use of VAR keyword: –

Get more tutorials for interview questions and answers for Dotnet


Also view author’s blog for Most asked Dotnet interview questions



About c# and .NET Interview questions

This blog is for developers who want to crack .NET and C# interviews. It has all tips and tricks needed to crack .NET interviews , C# interview , SQL Server interview , Java interview , WCF Interview , Silverlight interview , WPF interview , LINQ interview , Entity framework Interview. Do not forget to watch our Learn step by step video series. Learn MVC in 16 hours:- https://www.youtube.com/watch?v=Lp7nSImO5vk Learn AngularJS Step by Step:- https://www.youtube.com/watch?v=0kmdjqgO9IY Learn Design Pattern in 8 hours:- https://www.youtube.com/watch?v=YDobmucohqk Learn C# and .NET in 60 days:- https://www.youtube.com/watch?v=yh2SrzCkNQA Learn MSBI in 32 hours:- https://www.youtube.com/watch?v=mGPJx3ocFgg Learn SharePoint Step by Step in 8 hours:- https://youtu.be/C2fW76SwJNU
This entry was posted in Uncategorized and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s