Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Directory

Status
Not open for further replies.

SmileeTiger

Programmer
Mar 13, 2000
200
US
I am trying to get info on where the windows directory is stored using the getwindowsdirectory system call however for some reason the call crashes my program any idea what's wring with this piece of code?


Cory
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include &quot;SystemInfo.h&quot;

typedef BOOL (WINAPI *P_GDFSE)(LPCTSTR, PULARGE_INTEGER,
PULARGE_INTEGER, PULARGE_INTEGER); //For GetDiskInfo

void main (int argc, char **argv)
{
LPTSTR lpBuffer;
UINT uSize=256;
UINT tmp;
tmp = GetWindowsDirectory(
lpBuffer, // buffer for Windows directory
uSize // size of directory buffer
);
}
 
Hi

The first parameter of the function is the address of the buffer that will store the directory. So, pass the pointer of an actual buffer. Microsoft advices to use a buffer of at least MAX_PATH.

Here is the code:

char szBuffer[MAX_PATH];

if ( GetWindowsDirectory( szBuffer, MAX_PATH))
AfxMessageBox( szBuffer);

HTH

Thierry
EMail: Thierry.Marneffe@swing.be
 
Because you must allocate memory for buffer:

LPTSTR lpBuf = new TCHAR[MAX_PATH];
::GetWindowsDirectory(lpBuf, MAX_PATH);

// use lpBuf.

delete []lpBuf;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top