Quantcast
Channel: Visual C forum
Viewing all 15302 articles
Browse latest View live

Cannot create win32 Console Application

$
0
0

I'm using Windows 7 Home Premium and Visual C++ 2010 Express.

Every time I try to create a Visual C++ win32 console application project and then I go into the Win32 Application Wizard, it doesn't show the "current project setting"and I am unable to click "Finish" or "Cancel" there is no next button. 

I am following this tutorial I found and it's supposed to look like this.

This is my first time using Microsoft Visual C++ 2010 Express and I would very much appreciate to find out what I'm doing wrong and if I could have some help on what to do?  Or If I should re install or try Visual Studio 2010

Mooncrawler

 


MFC C++ XML Parse - Using MSXML.

$
0
0

Good day,

I got stuck to this part of the feature I am designing can you please help?

Here is my XML Code:

<tables><table name="Stamps.0409"><row index="1" ><column>1st Class Letter</column><column>(Up to 100g)</column><column>60p</column><column>stampbutton1.png</column></row><row index="2" ><column>2nd Class Letter</column><column>(Up to 100g)</column><column>50p</column><column>stampbutton2.png</column></row></table></tables>


Here is my Method:

//log
	_bstr_t logData;
	_bstr_t logAttribute;
	//Attribute variables
	_variant_t vValue;
	BSTR bstrAttributeName = ::SysAllocString(_T("row"));
	IXMLDOMElement *pIDOMElement = NULL;
	IXMLDOMNodeList *pIDOMNodeList = NULL;
	IXMLDOMNode *pIDOMNode = NULL;
	BSTR bstrItemText = NULL;
	long value = 0;
	HRESULT hResult = CoInitialize(NULL);
	if(SUCCEEDED(hResult))
	{
		try{
			MSXML2::IXMLDOMDocumentPtr XMLToRead;
			MSXML2::IXMLDOMNodeListPtr NodeListPtr;
			MSXML2::IXMLDOMNodePtr NodeRowPtr, NodeIndexPtr, NodeTablePtr, NodeNamePtr;
			hResult = XMLToRead.CreateInstance(__uuidof(MSXML2::DOMDocument40), NULL, CLSCTX_INPROC_SERVER);
			//TODO:PLACE LOG and TEST.
			if(XMLToRead->load(cXMLFile) != VARIANT_TRUE)
			{
				trace(L6,_T("XMLDataReader: Failed to Read Data on XML"));
			}
				trace(L6,_T("XMLDataReader: Successful Read Data on XML"));

				//load xml
				_variant_t varXml(cXMLFile);
				_variant_t varOut((bool)TRUE);
				varOut = XMLToRead->load(cXMLFile);
				if((bool)varOut == FALSE)
				throw(0);

				ofstream logfile;
				logfile.open("c:\\UKPostOfficeStampDat.log");
				NodeListPtr =  XMLToRead->getElementsByTagName("column");
				//Attribute
				//Table
				NodeTablePtr = XMLToRead->selectSingleNode("//table");
				NodeNamePtr = NodeTablePtr->attributes->getNamedItem("name");
				//Row
				NodeRowPtr = XMLToRead->selectSingleNode("//row");
				NodeIndexPtr = NodeRowPtr->attributes->getNamedItem("index");

				string logAtt = _bstr_t(NodeIndexPtr->nodeValue);
				string logTable = _bstr_t(NodeNamePtr->nodeValue);
				logfile<<logTable<<","<<logAtt<<",";
				for(int i = 0; i < NodeListPtr->length; i++)
				{
					logData = NodeListPtr->Getitem(i)->text;
					logfile<<(string)logData<<",";
				}	
				logfile.close();

				trace(L6,_T("XMLDataReader: Successful Write Data on log"));

			
		}
		catch(_com_error &e)
		{
			trace(L6,_T("XMLDataReader: ERROR: %ws"), e.ErrorMessage());
		}
		CoUninitialize();

	}

This is my output code:

Stamps.0409,1,1st Class Letter,(Up to 100g),60p,stampbutton.png,1st Class Letter,(Up to 100g),60p,stampbutton.png,

It seems like I have only the first part of the XML data

What I want to do is this:

Stamps.0409,1,1st Class Letter,(Up to 100g),60p,stampbutton.png,2,2nd Class Letter,(Up to 100g),50p,stampbutton2.png,

since there is row 2. It should have a 2 before the 2nd XML data.

Thanks,

How do you know what include file is required for certain functions,classes,etc?

$
0
0

Ok for example to put it simply lets say i wanted to use _getch() or any command or function,etc how an earth do i find out which header file is required?

There must be a site somewhere or some reference that details which header files are required for all the commands,functions,etc. 

Thread functions

$
0
0

Hi,

In Console application running windows XP, 4 threads are created by application. when I change the bootable drives and load windows XP from different drive, it seems like only one thread keep running. the other threads are created but exited. But when I shutdown the computer (power off) and then restart computer, application works fine and runs all 4 threads. I am trying to understand what is happening?


How do i Close the Thread Created in VC++ 2010 Ultimate

$
0
0

I have Create Thread Below:

this->WriteDataThread = gcnew Thread (gcnew ThreadStart(this, &Form1:: SendData));

this->WriteDataThread->Start();
// SendData Funcrion is
private: void SendData()

{
int i=0;
int test[10] = {0};

//Read data From Serial Port

if(this->serialPort1->IsOpen)
   {
   // Read Data From Serial Port and Store in an array
      for(i=0;i<=9;i++)
      test[i] = this->serialPort->readByte();
   }

}


//-------------------------------------------------------------------

Now How do i Close This Therad, i am also using windows form


VS2010 Serial COM Application (on WIN 7) run slow on Other Machine's

$
0
0

I have Working on Serial Port Windows Form application using VS2010 Ultimate on WIndows-7 Machine (4 GB RAM).

My Code (developed on Visual Studio 2010 Ultimate) Runs as per required specification on my windows 7 machine ,

Problem comes when i run on other machine like WIN XP/ Windows 7.

My application send and receive integer data at 9.6 kbps continuously , after collection serial data it display collected data instantly.

it Send Serial Data properly but wont' display collected serial data (coming at 9.6 kbps) instantly , rather it seems that it display receive data after few min (2 or 3 min later). it seems that it collecting data but won't display instantly.

Regards

kaushal

MFC application

$
0
0

Hello

I'm having very difficult time with visual studio 2013. I try to create a mfc application and debug it but instead of clear new form i get a very strange forms instead. How can i create a black new form app in mfc. Also is vs 2013 good or is there any better compiler ?

Thanks very much

Application won't link with /ltcg:pgi

$
0
0

Hi, 

I'm trying to use profile guided optimizations to squeeze some more speed out of my product, but I'm getting some unresolved external symbol errors.  The project links properly without the /ltcg:pgi option.

1>simpledrawablecomponent.75a42c44.obj : error LNK2001: unresolved external symbol __PogoProbeEntryMDS
1>simpledrawablecomponent.75a42c44.obj : error LNK2001: unresolved external symbol __PogoProbeFilteredValue
1>simpledrawablecomponent.75a42c44.obj : error LNK2001: unresolved external symbol __PogoProbeFilteredValueMDS
1>simpledrawablecomponent.75a42c44.obj : error LNK2001: unresolved external symbol __PogoProbeTemplatedValue
1>simpledrawablecomponent.75a42c44.obj : error LNK2001: unresolved external symbol __PogoProbeTemplatedValueMDS
1>simpledrawablecomponent.75a42c44.obj : error LNK2001: unresolved external symbol __PogoProbeValue
1>simpledrawablecomponent.75a42c44.obj : error LNK2001: unresolved external symbol __PogoProbeValueMDS
1>simpledrawablecomponent.75a42c44.obj : error LNK2001: unresolved external symbol __PogoRuntimeVector
1>build\project\int\triadwars-pc64-ship\triadwarsship.exe : fatal error LNK1120: 8 unresolved externals
1>EXEC : error : SpawnLocalExe Failed!  Return code was not 0 ('1120' '00000460')!
1>ERROR : Win Error Msg = Last error 6: The handle is invalid.

thanks!

dR


accidental linking of release version of a static library to a debug version of the application

$
0
0

Hi,

I have 3 projects in a solution (say A,B and C). A and B create static libraries which I link to my main project C. I accidentally added the release version of the .lib out to the debug version of project C and I am getting error LNK2038 in the linker. I added the libraries by right clicking on project C in the solution explorer and adding the release versions of libraries of A and B. Is there anyway to undo this step?

Template Linker Error (tiny repro included)

$
0
0

template<class T>
struct S
{
	struct N
	{
		static int* ai[];
		static int i0;
	};
};

template<class T>
int S<T>::N::i0 = { 1 };

template<class T>
int* S<T>::N::ai[] = { &i0 };

#include<stdio.h>
int main()
{
	int* tp1 = S<float>::N::ai[0];
	return printf("%p\n", tp1);
}

The above code doesn't instantiate "i0" for some reason. (Tested in vs2010, 2012, 2013).

Gcc and Clang both work as expected.

The error is "unresolved external symbol "public: static int S<float>::N::i0" (?i0@N@?$S@M@@2HA)"

Thanks,
Stephen.

The application was unable to start correctly (0xc000007b). Click ok to close the application.

$
0
0

Hi,

I have a small MFC application.

It works fine.

But when I build Debug instead Release version the following error message dialog pops up:

                " The application was unable to start correctly (0xc000007b). Click ok to close the application. "

after trying to start the debug version.

How can I solve this?  What is the reason therefore?

And what does the number tell me (is it an error code, address, ...?) ?

Windows Forms Applications???

$
0
0
I am slightly new to c++ and am still learning from a book. The book uses visual c++ express 2010, but I downloaded the 2013 edition. The book uses a template called Windows Forms Applications. I can't find it in the downloadable templates or the preset templates. Can you help me find it? If it helps, the book is called C++ Programming In Easy Steps: Fourth Edition, by Mike Mcgrath. Thanks.

CScrollView flickering after horizontal scroolbar is hidden

$
0
0
The component in my MFC application is a SCrollView & OnDraw is overwritten. The flickering problem hapens only if I do the following:
1.  Resize the panel wide enough just to make the horizontal scroll bar appear, and the thump should fill up the most of the horizontal scrollbar.
2.  Move the thump to right most
3.  Try to resize the panel a few times by just a few pixels to left and right
4   The flickering will randomly happen.  The whole panel is "shaking" When it does, it NEVER stop unless I click on the panel

It is not easy to reproduce.  When it happens, I put the  and here is the stack trace:
>MyApp.exe!CMyScrollView::OnDraw(CDC * pDC=0x0018ee08)  Line 694C++
 mfc90d.dll!CView::OnPaint()  Line 185C++
 mfc90d.dll!CWnd::OnWndMsg(unsigned int message=15, unsigned int wParam=0, long lParam=0, long * pResult=0x0018efd8)  Line 2042C++
 mfc90d.dll!CWnd::WindowProc(unsigned int message=15, unsigned int wParam=0, long lParam=0)  Line 1755 + 0x20 bytesC++
 mfc90d.dll!AfxCallWndProc(CWnd * pWnd=0x0368f9c8, HWND__ * hWnd=0x0042123a, unsigned int nMsg=15, unsigned int wParam=0, long lParam=0)  Line 240 + 0x1c bytesC++
 mfc90d.dll!AfxWndProc(HWND__ * hWnd=0x0042123a, unsigned int nMsg=15, unsigned int wParam=0, long lParam=0)  Line 403C++
 mfc90d.dll!AfxWndProcBase(HWND__ * hWnd=0x0042123a, unsigned int nMsg=15, unsigned int wParam=0, long lParam=0)  Line 441 + 0x15 bytesC++

Did you ever see this issue before?  Could you please point me to the right direction?  Your help is greately appreciated.

Thank you,
Emily

How to get Case Sensitive Filename/Path in MFC

$
0
0

Hi,

I need to get the Case sensitive Filename and Path to chek if the filename described in an XML file and the file on hard drive match.

I have searched the web and tried many suggestions, but they all did not work. They just returned the filename as given as argument to such functions.

At the moment I split the path by '\' and use 

DWORD result  = SHGetFileInfo(testPath.c_str(), 0, &sfi, sizeof(sfi), SHGFI_DISPLAYNAME);

for each part of the path to check, and in this way I build up a new string from 

sfi.szDisplayName
which I compare with the string I read from XML file.

This works as long as in "Folder Options" -> "View" the option "Hide extensions for known file types" is unchecked. If checked, sfi.szDisplayName does not contain the extension.

What can I do to read the case sensitive filename, extension and path as stored on the hard drive, or is there a function that returns the filename / path as stored on hard drive?

"Hacking" the file system to be case sensitive is not a solution.

BR,

Thorsten

CNG SymmetricProviderSample not working

$
0
0

I want to run the Cryptographic Provider Development Kit\Samples\SymmetricProviderSample sample from the Cryptographic Provider Development Kit samples in order to create my own Symmetric Algorithm Provider.

I have built the VS solution but I get an error when trying to actually encrypt a file using the registered algorithm:

C:\Program Files (x86)\Windows Kits\8.0\Cryptographic Provider Development Kit\Samples\SymmetricProviderS
ample\CPP\Release>Config.exe -enum
Microsoft Primitive Provider
Microsoft Smart Card Key Storage Provider
Microsoft Software Key Storage Provider
Microsoft SSL Protocol Provider
SafeNet Smart Card Key Storage Provider

C:\Program Files (x86)\Windows Kits\8.0\Cryptographic Provider Development Kit\Samples\SymmetricProviderS
ample\CPP\Release>Config.exe -register XOR

C:\Program Files (x86)\Windows Kits\8.0\Cryptographic Provider Development Kit\Samples\SymmetricProviderS
ample\CPP\Release>Config.exe -enum
Microsoft Primitive Provider
Microsoft Smart Card Key Storage Provider
Microsoft Software Key Storage Provider
Microsoft SSL Protocol Provider
SafeNet Smart Card Key Storage Provider
CNG Demo Symmetric Cipher Provider

C:\Program Files (x86)\Windows Kits\8.0\Cryptographic Provider Development Kit\Samples\SymmetricProviderS
ample\CPP\Release>echo asd > clar.txt

C:\Program Files (x86)\Windows Kits\8.0\Cryptographic Provider Development Kit\Samples\SymmetricProviderS
ample\CPP\Release>Client.exe -encrypt clar.txt out.txt
BCryptOpenAlgorithmProvider failed with status: 0xc000007b

x32 error: 0xc000007b

x64 error: 0xc0000135

I just want to run the sample in the first place.


Releasing IMMDeviceEnumerator causes stdout issues on Windows 7

$
0
0

Hello,

Consider the following code:

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <mmdeviceapi.h>
#include <tchar.h>


#define EXIT_ON_ERROR(hres)  \
              if (FAILED(hres)) { _tprintf(_T("Failure (0x%8x)\n"),hres);goto Exit; }


template <class T> void SafeRelease(T **ppT)
{
	if (*ppT)
	{
		(*ppT)->Release(); // Here's what's causing the issue
		*ppT = NULL;
	}
}

int _tmain(int /*argc*/, _TCHAR* /*argv[]*/)
{
	_tprintf(_T("Here are some traces\n"));
	IMMDeviceEnumerator *pEnumerator = NULL;
	HRESULT hr = E_FAIL;
	hr = CoInitialize(NULL);
	if (FAILED(hr))
	{
		_tprintf(_T("CoInitialize failed\n"));
		return 1;
	}
	hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pEnumerator);
	if (SUCCEEDED(hr))
	{
		_tprintf(_T("Releasing pEnumerator\n"));
		SafeRelease(&pEnumerator);
	}
	else
	{
		_tprintf(_T("CoCreateInstance failed\n"));
	}
	return 0;
}

I'm compiling this in Visual Studio 2013 (with the _UNICODE flag set), targeting the VC 2012 or 2013 runtime (no impact on the outcome)
I then run the program (ConsoleApplication2.exe) from a cmd.

> ConsoleApplication2.exe

Here are some traces
Releasing pEnumerator

This is as expected.

> ConsoleApplication2.exe>someLog.log

No output, which is also as expected. However, on Windows 7, someLog.log is empty.
Running the same line on Windows 8 or 8.1 update gives me a log file that contains the traces I expect.
I narrowed down the issue and realized that if I comment-out the release of pEnumerator, I then get the expected traces in the log file, on Windows 7.

Has anyone seen this before? Am I doing something wrong?
I'm starting to suspect an issue in the implementation of the COM interface IMMDeviceEnumerator.

Thanks!

Hide compressing progress dialog on Folder::CopyHere ()

$
0
0

After a long search I found one hope in Folder::CopyHere() to copy files/folder to a zip file, without using any third party utilities.

However now my concern is on hiding the 'Compressing' progress dialog while copying to a zip file.

My dialog show my own custom progress dialog, so I don not want to display windows default progress bar.

Event after using FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR flags I am not able to hide the 'Compressing' progress dialog. But yes the progress dialog isnot displayed if my destination is a folder.

Is it a known issue or exists any solution or any alternative methods( other than 3rd parties).

My code snippet is shared below:

Code flow

OnBnClickedButtonZip() -> CreateEmptyZipFile()

-> ZipFile() // Calls CopyHere API and Waits for completion

-> MyThreadProc() // signals ZipFile() when completed


struct STR { Folder* pToFolder; int nCount; }; void CzipunzipDlg::OnBnClickedButtonZip() { CreateEmptyZipFile( L"D:\\Sample.zip"); CStringArray strSrcArray; strSrcArray.Add(L"D:\\Test1"); strSrcArray.Add(L"D:\\Test2"); CString csDest = L"D:\\Sample.zip"; ResetEvent(m_hEvtHandle); ZipFile( strSrcArray , csDest ); AfxMessageBox(L"Completed"); } void CzipunzipDlg::CreateEmptyZipFile(CString strPath) { BYTE startBuffer[] = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; FILE *f = _wfopen(strPath.GetBuffer(strPath.GetLength()), _T("wb")); strPath.ReleaseBuffer(); fwrite(startBuffer,sizeof(startBuffer),1,f); fclose(f); } void CzipunzipDlg::ZipFile(CStringArray& strSrcArray, CString& strDest) { HRESULT hResult = S_FALSE; IShellDispatch *pIShellDispatch = NULL; Folder *pToFolder = NULL; VARIANT variantDir, variantFile, variantOpt; CoInitialize(NULL); hResult = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&pIShellDispatch); BSTR bstrDest = strDest.AllocSysString(); if (SUCCEEDED(hResult)) { VariantInit(&variantDir); variantDir.vt = VT_BSTR; variantDir.bstrVal = bstrDest; hResult = pIShellDispatch->NameSpace(variantDir, &pToFolder); if (SUCCEEDED(hResult)) { int nTotalFileCount = strSrcArray.GetSize(); for( int i = 0; i < nTotalFileCount; ++i ) { BSTR bstrSource = strSrcArray[i].AllocSysString(); VariantInit(&variantFile); variantFile.vt = VT_BSTR; variantFile.bstrVal = bstrSource; VariantInit(&variantOpt); variantOpt.vt = VT_I4; variantOpt.lVal = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR; hResult = pToFolder->CopyHere(variantFile, variantOpt); STR str; str.nCount = i + 1; str.pToFolder = pToFolder; CWinThread* pThread = AfxBeginThread( CzipunzipDlg::MyThreadProc, &str ); DWORD dwResult = WaitForSingleObject( pThread->m_hThread, INFINITE ); } pToFolder->Release(); } pIShellDispatch->Release(); } CoUninitialize(); } UINT CzipunzipDlg::MyThreadProc( LPVOID lParam_i ) { CoInitialize(NULL); STR* str = reinterpret_cast<STR*>( lParam_i ); long lFileCount = 0; FolderItems *pFolderItems = NULL; do { HRESULT hResult = str->pToFolder->Items( &pFolderItems ); hResult = pFolderItems->get_Count( &lFileCount); Sleep(100); }while( str->nCount != lFileCount );

HANDLE hAhndle = OpenEvent(EVENT_ALL_ACCESS, FALSE, ZIP_EVENT ); SetEvent( hAhndle ); return 0; }


My development environment is VS2008 and Windows 7 Enterprise.

 

How to convert recursive device tree into non- recursive/Iterative.?

$
0
0

I’m trying to convert  CreateDeviceTree and PrintDeviceTree Function’s into non- recursive/Iterative from below sample code. Any optimal way?

Thanks in advance.

#include<Windows.h>
#include <Setupapi.h>
#include<cfgmgr32.h>
#include<iostream>
#include<vector>
#include<string>
#include<stack>
using namespace std;
//#pragma comment(lib,"cfgmgr32.lib")
class CDevice;
vector<CDevice*> deviceList;
HANDLE ghMachine=NULL;
CONFIGRET	gLastCR;

class CDevice 
{
	CDevice *m_pParent;
	CDevice *m_pChild;
	CDevice *m_pSibling;
	SP_DEVINFO_DATA m_DevData;
	HDEVINFO    m_hDevInfo;
public:
	CDevice()
	{
		m_pParent=NULL;
		m_pChild=NULL;
		m_pSibling=NULL;
		memset(&m_DevData,0,sizeof(SP_DEVINFO_DATA));
	}
	CDevice(SP_DEVINFO_DATA devData)
	{
		m_pParent=NULL;
		m_pChild=NULL;
		m_pSibling=NULL;
		m_DevData=devData;
	}
	CDevice* GetChild() { return m_pChild; }
	CDevice* GetParent() { return m_pParent; }
	CDevice* GetSibling() { return m_pSibling; }
	void SetChild(CDevice* pDevice) { m_pChild = pDevice; }
	void SetParent(CDevice* pDevice) { m_pParent = pDevice; }
	void SetSibling(CDevice* pDevice) { m_pSibling = pDevice; }
	DWORD GetDevInst()
	{
		return m_DevData.DevInst;
	}
	GUID GetGuid()
	{
		return m_DevData.ClassGuid;
	}
	BOOL GetClassFriendlyNameString(string& strClass )
	{
		char DisplayName[LINE_LEN + 1];
		if( SetupDiGetClassDescriptionA( &m_DevData.ClassGuid, DisplayName, sizeof(DisplayName), NULL ) ||
			SetupDiClassNameFromGuidA( &m_DevData.ClassGuid, DisplayName, sizeof(DisplayName), NULL ) )
		{
			strClass = DisplayName;
			return TRUE;
		}
		return FALSE;
	}
};
class CRootDeviceNode:public CDevice
{
	DEVNODE m_dnRoot;
public:
	CRootDeviceNode(DEVNODE dn)
	{
		m_dnRoot=dn;
	}
	virtual DEVNODE GetDevNode(){ return m_dnRoot; }
};
//Helper Class
class DeviceUtil
{
public:
	static CDevice* DevNodeToDevice( DEVNODE dn )
	{
		DWORD i=deviceList.size();
		DWORD j=0;
		for(;j<i;j++)
		{
			if(deviceList[j]->GetDevInst()==dn)
			{
				return deviceList[j];
			}

		}
		return NULL;

	}
	static DEVNODE CmGetChild( DEVNODE dn )
	{
		DEVNODE dnChild;
		gLastCR = CM_Get_Child_Ex(&dnChild, dn, 0, ghMachine);
		if (CR_SUCCESS ==  gLastCR)
			return dnChild;
		return NULL;
	}
	static DEVNODE CmGetSibling( DEVNODE dn )
	{
		DEVNODE dnSibling;
		gLastCR = CM_Get_Sibling_Ex(&dnSibling, dn, 0, ghMachine);
		if (CR_SUCCESS == gLastCR)
			return dnSibling;
		return NULL;
	}

	static DEVNODE CmGetRootDevNode()
	{
		DEVNODE dnRoot;
		gLastCR =  CM_Locate_DevNode_Ex(&dnRoot, NULL, 0, ghMachine);
		if (CR_SUCCESS == gLastCR)
			return dnRoot;
		return NULL;
	}
	static DEVNODE  CmGetParent( DEVNODE dn )
	{
		DEVNODE dnParent;
		gLastCR = CM_Get_Parent_Ex(&dnParent, dn, 0, ghMachine);
		if (CR_SUCCESS == gLastCR)
			return dnParent;
		return NULL;
	}
	static BOOL GetClassFriendlyNameString( LPGUID Guid, string& strClass )
	{
		char DisplayName[LINE_LEN + 1];
		if( SetupDiGetClassDescriptionA( Guid, DisplayName, sizeof(DisplayName), NULL ) ||
			SetupDiClassNameFromGuidA( Guid, DisplayName, sizeof(DisplayName), NULL ) )
		{
			strClass = DisplayName;
			return TRUE;
		}
		return FALSE;
	}

	static void CreateDeviceTree( CDevice* pParent, CDevice* pSibling, DEVNODE dn )
	{

		CDevice* pDevice = NULL;
		DEVNODE dnChild;
		while( dn )
		{
			pDevice = DevNodeToDevice( dn );
			if( pDevice )
			{
				if (!pSibling)
				{
					pParent->SetChild(pDevice);
				}
				else
				{
					pSibling->SetSibling(pDevice);
				}
				pDevice->SetParent(pParent);
				pSibling = pDevice;
				dnChild = CmGetChild(dn);
				if (dnChild)
				{
					CreateDeviceTree(pDevice, NULL, dnChild);
				}
			}
			dn = CmGetSibling( dn );
		}
	}

	static void PrintDeviceTree( CDevice* dtmp)
	{
		static DWORD count=0;
		if(dtmp==NULL)
			return;
		CDevice *pSibling, *pChild;
		do
		{

			string strDisplayName;
			pSibling=dtmp->GetSibling();
			pChild=dtmp->GetChild();
			dtmp->GetClassFriendlyNameString(strDisplayName);
			cout<<"Count:"<<count;
			cout<<"->Class Name:"<<strDisplayName<<endl;
			count++;
			if(pChild)
				PrintDeviceTree(pChild);
			dtmp = pSibling;
		}while(dtmp!=NULL);
	}
};

int main()
{
	DEVNODE dnRoot;
	string strClassName;

	DWORD i=0;
	SP_DEVINFO_DATA DeviceInfoData;

	HDEVINFO hDevInfo = SetupDiGetClassDevs(NULL,0, 0,DIGCF_PRESENT | DIGCF_ALLCLASSES );
	if (hDevInfo == INVALID_HANDLE_VALUE)
	{
		cout<<"Fail To get DevInfo"<<endl;
		return 1;
	}
	DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
	cout<<"Enumerating  through device list..."<<endl;
	while(SetupDiEnumDeviceInfo(hDevInfo,i,&DeviceInfoData))
	{
		CDevice *pDevice=new CDevice(DeviceInfoData);
		deviceList.push_back(pDevice);
		i++;
		memset(&DeviceInfoData,0,sizeof(SP_DEVINFO_DATA));
		DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
	}
	cout<<"Total Number of devices:"<<i<<endl;

	cout<<"Creating Tree..."<<endl;

	CRootDeviceNode *pRootNode=new CRootDeviceNode(DeviceUtil::CmGetRootDevNode());
	DEVNODE dn1=DeviceUtil::CmGetChild(DeviceUtil::CmGetRootDevNode());
	DeviceUtil::CreateDeviceTree(pRootNode,NULL,dn1);
	cout<<"Printing Tree..."<<endl;
	CDevice *dtmp=DeviceUtil::DevNodeToDevice(dn1);
	DeviceUtil::PrintDeviceTree(dtmp);


	SetupDiDestroyDeviceInfoList(hDevInfo);
	return 0;
}


Nandkumar T.

Use of Visual C++ Compiler and Linker (not libraries) for OS Development

$
0
0

Based on reading the license files included with Visual Studio and the respective ones for the platform SDK, I believe that using the Visual C++ compiler and linker is fair game for OS development on the grounds that the license excludes using "Distributable Code" on non-Microsoft platforms where "Distributable Code" is defined very specifically further up the license as:

"4.a.i Right to Use and Distribute. The code and text files listed below are “Distributable Code.” · Sample Code. You may modify, copy, and distribute the source and object code form of code marked as “sample.” · Third Party Distribution. You may permit distributors of your programs to copy and distribute the Distributable Code as part of those programs."

Is my thinking correct, or is there some other license portion am I missing?

Grab local logon/off event through WtsApi

$
0
0

Hi experts,

Can I grab local console logon/off event through WtsApi Enumeration funciton? My service is trying to monitor these two events and take action accordingly. Highlight, it needs to grab local console logon/off event.

And how to achieve that if possible. To procedure-oriented programming I am considered experienced, but with VC++, I have got not much better than a beginner, so simple workable code would be mostly appreciated.

The service also needs to launch a serial of applications with current logged on user account without knowing password, I will appreciate if someone can tell me how about this.

I dont know whether I am going through a correct process, but this is urgent as project is getting delivered and this case suddenly has got raised up.

Thank you in advance.

Environment: Win 7 Ultimate, VS 2008 C++

Regards

Yang Guang

Viewing all 15302 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>