MS Applications Development Training

SYS-ED Experience

Submit MS Application Development Questions


Submit MS Applications Development Questions

Technology Driven IT Training

Knowledge Base

Submit MS Application Development Questions to SYS-ED Advanced search

Interrelated Information Technology

MS Visual Basic Questions MS Visual C++ Questions
MS Operating Systems and Networks Questions .NET Questions
Java Questions Computer Applications Questions

The SYS-ED knowledge base is a service for answering questions, inclusive of the research and validation of the accuracy of information in the public domain. Citation of source documentation and examples are used to provide answers to the questions. Utilization and reliance on the answers, information, or other materials received through this website is done at your own risk.

MS Visual Basic


I am responsible for maintaining Visual Basic code. Is it possible to modify the VB code to rRun a command line application, open up another Windows program, and bring up the default web browser or email program.


Yes, all three can be implemented programmatically.

Sample Code:

The classes and methods in System.Diagnostics.Process can be used to accomplish these tasks.

  Private Sub Button1_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles Button1.Click
  End Sub

Sample Code:

This code will retrieve the results and wait until the process stops.

  Private Sub Button2_Click(ByVal sender As Object, _
      ByVal e As System.EventArgs) Handles Button2.Click
      Dim psi As New _
      psi.RedirectStandardOutput = True
      psi.WindowStyle = ProcessWindowStyle.Hidden
      psi.UseShellExecute = False
      Dim listFiles As System.Diagnostics.Process
      listFiles = System.Diagnostics.Process.Start(psi)
      Dim myOutput As System.IO.StreamReader _
        = listFiles.StandardOutput
      If listFiles.HasExited Then
        Dim output As String = myOutput.ReadToEnd
      End If
  End Sub


How can a form or dialog be centered programmatically on the screen?


Use this code snippet to center a form or dialog programmatically on the screen:

   Private Sub Form_Load()
        Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
   End Sub


How can version information be returned from the AssemblyInfo file?


Use this VB .NET code at run-time in order to return version information.

Sample Code:

    Function GetVersion() As String
    With System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly.Location)
    Return .FileMajorPart & "." & .FileMinorPart & "." & .FileBuildPart & "." & .FilePrivatePart
    End With
    End Function

    Function GetComments() As String
    With System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly.Location)
    Return .Comments
    End With
    End Function


How is text converted from lower case to upper case in VB.NET?


Use this code for converting text from lower to upper case.

Sample Code:

    Module Module1
    Sub Main ()
            Dim str1 as String=”Welcome to String”
            Dim str2 as String
    End Sub


How are Procedure Delegates created?


Delegates are used to work with the address of procedures. Sometimes it will be useful to pass the location of a procedure to other procedures. Delegates are used to display “Hello from Delegates”.


Sample Code:

  Module Module1
  Delegate Sub SubDelegate1(ByVal str as String)
  Sub Main()
        Dim Mess as SubDelegate1
        Mess-AddressOf Display
        Mess.Invoke(“Hello from Delegates”)
  End Sub
  Sub Display(ByVal str as String)
  End Sub
  End Module


What is anchoring and docking?
A In Visual Basic, the terms docking and anchoring are used to ensure that a control covers the whole client area of a form.

When docked, a window adheres to the edges of its container. The property of the control from the windows can be used to "dock" a particular control. Selecting the Dock property opens up a small window like structure from which a selection can be made on the Form to control the docked state.

An anchor places a control to the edges of its container. Selecting this property in the properties window opens up a small window from to select the edge for anchoring the control.


How can the computer name and IP address be programmatically obtained?


This code uses the System.NET.DNS namespace to access the "computer name" and it's IP address.

Sample Code

  Option Strict Off
  Imports system
  Imports System.Net.DNS
  Public Class GetIP
  Shared Function GetIPAddress() As String
  Dim sam As System.Net.IPAddress
  Dim sam1 As String
  With system.Net.DNS.GetHostByName(system.Net.DNS.GetHostName())
      sam = New System.Net.IPAddress(.AddressList(0).Address)
      sam1 = sam.ToString
  End With
  GetIPAddress = sam1
  End Function
      Shared Sub main()
          Dim shostname As String
          shostname = system.Net.DNS.GetHostName
          console.writeline("Name of the System is = " & shostname)
          console.writeline("Your IP address is= " & GetIPAddress)
      End Sub
  End Class


What is managed code and managed data?


Managed code is written to target the services of the CLR: Common Language Runtime. In order to target these services, the code must provide a minimum level of information to the runtime. All of the C#, Visual Basic .NET and J# .NET code is managed by default.

Managed data is allocated and de-allocated by the Common Language Runtime's garbage collector. C#, Visual Basic, and J#.NET data is managed by default. C++ data can be marked as unmanaged through the use of special keywords. Visual Studio .NET C++ data is unmanaged by default; this occurs even when the /CLR switch is used. When Managed Extensions for C++ are being used, a class can be marked as managed by using the __gc keyword.

With Managed data, the memory used for instances of the class is managed by the garbage collector. The class also becomes a full participating member of the .NET Framework; a major is proper interoperability with classes written in other languages.

A managed class can only inherit from one base class.


How can an .EXE be run from a VB.NET application?


In order to run a .EXE file from a VB.NET application, it will be necessary to import the System.Diagnostics namespace.

This code is used to run Notepad from a VB.NET application.

Sample Code:

  Imports System
  Imports System.Diagnostics
  Dim program As New Process()
  program.StartInfo.FileName = "Notepad.exe"
  program.StartInfo.Arguments = " "

MS Visual C++


What is a buffer overrun? How can I protect my organization from buffer overruns?


Buffer overruns are a programming mistake; they involve copying the contents of a region of memory into another region of memory that is too small to accommodate the source block.


char* source = "A reasonably long string";
  char dest[10];
  ::strcpy(dest, source);

It can be extremely difficult to eliminate buffer overruns in large C/C++ code bases One approach is to limit the size of the data copied in order that it is not greater than the size of the destination buffer.

The utilization of managing technologies such as .NET and Java can significantly reduce the potential for buffer overruns. Buffer protection can be activated by turning on the /GS compiler switch. With Visual Studio, the switch can be activated from the Code Generation option page on the C/C++ tab. By default, the setting will be disabled for the Debug configuration and enabled for the Release configuration.


However, a single compiler switch will not ensure an application is secure. It can help make an application more secure, but security vulnerabilities come in many different forms. Buffer overruns are a security vulnerability. A malicious input can modify the execution flow of a process. Buffer overruns can result in an entire process, machine, or domain being compromised. If the identity that the process is running under is a highly trusted account, such as an administrator or the Local System account, the damage that the hackers can cause is severe and potentially widespread.

Code Red and Blaster worms, were the result of buffer overruns in C/C++ code.


Can a WinHelp be called from a C++ MFC program?


Help can be programmatically called from anywhere in code. The most common reasons for doing this would be to open the WinHelp Table of Contents from the help menu or to call a general help topic from a Help button on a form. Help also can be called using keywords.

The WinHelp function starts WINHLP32.EXE and passes additional data indicating the nature of the help requested by the application.

In order to use these API calls, the WinHelp.bas or Winhelp.cls must be attached.

BOOL WinHelp( HWND hWndMain, LPCTSTR lpszHelp, UINT uCommand, DWORD dwData )

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.


What is a view? How is it different from an application?


When an application is created, the intention will be for the users to see, view, and manipulate its documents. The process of making up a program is to create the application using a class derived from CWinApp and surrounding the program with a frame either based on CFrameWnd or from one of its derived classes. This type of a simple program is designed to show the presence of an application. In order to assist the user with files, the program should be equipped with a document. A document is a representation of a file and in order to present a document to the user, an object called a view, will need to be provided.

There are several ways to present documents. In order to support these variances, the MFC provides different view-based classes. MFC provides a class named CView, for laying a foundation for those classes. Although the MFC provides various view-based classes, there is a high likelihood, that none of them would fit the particular functionality that is required to be implemented.

For this reason, the CView class is the ancestor to the other view-based classes. A view in its own right and can be used to create an application that none of the other classes can handle. CView is an abstract class; it cannot be declared a CView variable.

This code will produce an error.

  CView *view = new CView;

In order to use CView, a class must be derived from it.


How can a window be made not movable?


This can be done by adding the handle function to the WM_WINDOWPOSCHANGING message for the window and write next:

   void CMyDialog::OnWindowPosChanging(WINDOWPOS* pWndPos)
           if (IsWindowVisible())
                      pWndPos->flags |= SWP_NOMOVE;


What is better: AfxEndThread()or return?


Our system consultants recommended avoid using AfxEndThread() function as well as ExitThread in Win32 API). When there is a thread in some objects, the destructor will not be called for them in case of using AfxEndThread().

When the return statement is used, the compiler implicitly adds to the code the appropriate destructor calls before the thread function really ends. Accordingly, AfxEndThread() call is not safe in terms of memory leaks when destructors for objects must be called.

   Declaration of AfxEndThread():
         void AFXAPI AfxEndThread(
               UINT nExitCode,
               BOOL bDelete = TRUE);

The parameter nExitCode specifies the exit code of the thread and bDelete deletes the thread object from memory. If the decision has been made to specify thread exit code this way, the return statement will provide the thread return code. The second parameter will need to be set to TRUE or FALSE for the member m_bAutoDelete (public) for CWndThread object.

It is not a recommended practice to use the AfxEndThread(), ExitThread(), and TerminateThread() API function.


How can a MFC project be created with built-in help files?


When the MFC App Wizard is used for creating a project the WinHelp support can be included for the main window as part of the automatically generated files.

In order create a new project with context sensitive help support:

1. From the Visual C++ File menu, choose New.
2.  Choose MFC AppWizard (.exe).
3.  When given the option, make sure that the Context Sensitive Help box is checked.
4.  Continue through the process to set up the program.

This will create the following:

  • An application with a menu and if requested a toolbar.
  • A help file with topics for each of the automatically generated menu items and toolbar buttons.
    • The help author can use this framework as a starting point.
  • A .hm file with the topic ID to number mapping.
    • This file can be used directly by WinHelp.
  • An operational What's This? Help button on the toolbar.
    • Clicking this button puts the program into What's This? Help mode.
    • Clicking on a menu or control then opens its help.
  • Shift-F1 hooked up to put the program into What's this? Help mode.
    • F1 hooked up to open general help for the child window with focus or the control on which the user is currently clicking.
  • When a dialog box is created, F1 will be hooked up to open a general help topic for the whole dialog box.
  • All help topics opened in the main WinHelp window.


1. Since no dialog boxes are created in this process, it will be necessary to add context sensitive help support for each dialog box as it is created.

2. Once there is an initial help file and .hm file, it is usually easier to have the help author add new topics with a help authoring tool.

3. The program can still be used to generate the framework help for each build, because it will provide appropriate additional topic mapping entries.