Skip to main content

How to execute a command in Visual C++

· One min read

There are basically four methods to run a command in Visual C++. WinExec is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function.

· system(), _wsystem() · ShellExecute() or ShellExecuteEx() · CreateProcess() · WinExec()

Win32: How do I get the name of files in a folder ?

· One min read

To get the name of files in a folder,

  1. call the FindFirstFile function to open a search handle and get information about the first file that the file system find in the folder.

  2. call the FindNextFile function to continue listing files from a previous call to FindFirstFile.

WIN32_FIND_DATA FindFileData; 
HANDLE hFind;
TCHAR *FilePathBuff = L"C:RequiredFolder";
hFind = FindFirstFile(FilePathBuff, &FindFileData);

if (hFind == INVALID_HANDLE_VALUE) {
printf(TEXT("FindFirstFile failed (%d)n"), GetLastError());
}
else
{
printf(TEXT("The first file is %sn"), FindFileData.cFileName);
while (FindNextFile(hFind, &FindFileData) != 0)
{
printf(TEXT("The next file is %sn"), FindFileData.cFileName);
} FindClose(hFind);
}

MFC: Enumerate all views of the document

· One min read

To Enumerate all views of the document the CDocument class provides GetFirstViewPosition and GetNextView member functions to enumerate all views associated with the document. We call view’s OnUpdate function to communicate with them.

void EnumerateViews()
{
//get the position of the first view in the list
//of views associated with the document.
POSITION pos = GetFirstViewPosition();

//terate through all of the document's views.
while (pos != NULL)
{
CView* pView = GetNextView(pos);

//update view
pView->OnUpdate(pSender, lHint, pHint);
}
}

C#: Generate xsd and class for an XML document

· One min read

Using xsd.exe which will be install with the Visual studio can be used.
Open Visual Studio Command Prompt and use the following commands

Setting environment for using Microsoft Visual Studio 2010 x86 tools.

C:Program Files (x86)Microsoft Visual Studio 10.0VC>cd C:

C:>xsd CPPData.xml

Microsoft (R) Xml Schemas/DataTypes support utility [Microsoft (R) .NET Framework, Version 4.0.30319.1] Copyright (C) Microsoft Corporation. All rights reserved. Writing file 'C:CPPData.xsd'. C:>xsd CPPData.xsd /classes Microsoft (R) Xml Schemas/DataTypes support utility [Microsoft (R) .NET Framework, Version 4.0.30319.1] Copyright (C) Microsoft Corporation. All rights reserved. Writing file 'C:CPPData.cs'. C:>

C#: How to Select a random item from a List

· One min read
using System; 
using System.Collections.Generic;
namespace RandomSelect {
class Program {
static List lst = new List();
static void Main(string[] args) {
lst.Add("1");
lst.Add("2");
lst.Add("3");
lst.Add("4");
lst.Add("5");
lst.Add("6");
lst.Add("7");
lst.Add("8");
lst.Add("9");
lst.Add("10");
Random rndElement = new Random();
foreach (string i in lst) {
string s = lst[rndElement.Next(lst.Count)];
Console.WriteLine(s);
}
}
}
}

Visual Studio 2008, 2010 Auto Uninstall Tools

· One min read

If you’ve any problems in uninstalling Visual Studio 2008, 2010 from Add/ Remove programs in XP or from Programs and features in Windows  7 you can use Microsoft Visual Studio 2008 Auto uninstall utility to remove Visual Studio 2008 and Visual Studio 2010 Auto uninstall utility to remove Visual Studio 2010 editions from your Computer .

1. Microsoft Visual Studio 2008 Auto Uninstall Tool

Download here

2. Microsoft Visual Studio 2010 Auto Uninstall Tool

Download here

what is the output

· One min read
# include <iostream>

using namespace std;

int main() {
int a=10,b=2;
b = a+++a;
cout<<b<<" "<<a<<"n";
return 0;
}

OUTPUT 20 11
Tags:

WPF - Simple App

· One min read

Step by Step tutorial for creating Simple WPF Application

  1. Open Visual Studio 2010
  2. Go to ‘File’ Menu and select ‘New Project’
  3. Select ‘WPF Application’ as shown below
  4. Give the application name as “FirstWPFApp”
  5. Visual studio generates two xaml files ( App.xaml , MainWindow.xaml) And corresponding code behind .cs files (App.xaml.cs, MainWindow.xaml.cs)
  6. Drag and drop a Button from toolbox on to the Window and give names as ‘btnClickMe’ and Add an even to it by double click on the button.
  7. Open MainWindow.xaml.cs in btnClickMe_Click event add MessageBox.Show("Hello World !!");
  8. Compile and Build the project.

C-Pointers What is the output

· One min read

FAQ-1

void main() { 
int _p = 91; //compilation error
printf("%d n",_ p);
printf("%d n", p);
}

OUTPUT: Does not compile error C2440: 'initializing' : cannot convert from 'int' to 'int *'

FAQ-2

void main() { 
int i = 91; int *p = &i;
printf("%d n", *p); printf("%d n", p);
}

OUTPUT: 91 1245024

FAQ-3

void main() { 
int i = 91;
int *p = &i;

printf(" p = %d n",p);
printf(" p = %d n", p);
printf(" &p = %d n", &p);
printf(" (&p) = %d n", (&p));
printf(" ((&p)) = %d n", ((&p)));
}

OUTPUT: i = 91 &i = 1245024 p = 91 p = 1245024 &p = 1245012 (&p) = 1245024 ((&p)) = 91

FAQ-4

void main() { 
const int p;
int i;
i = 10;
p = &i;
printf("p = %d, p = %d, i = %d", p, p, i);
}

OUTPUT p = 1245012, p = 10, i = 10
Tags: