Free2Code
 
Time: 2008-11-21, 08:42pm
can't compile
Subject: can't compile  ·  Posted: 2004-03-26, 07:42pm
Rank: Unregistered
The following code doesn't want to compile.

It gives this error:

error C2664: 'Options' : cannot convert parameter 2 from 'char *[]' to 'const char ** ' Conversion loses qualifiers


#include "EvryThng.h"

BOOL TraverseDirectory (LPCTSTR, DWORD, LPBOOL);
DWORD FileType (LPWIN32_FIND_DATA);
BOOL ProcessItem (LPWIN32_FIND_DATA, DWORD, LPBOOL);

int _tmain (int argc, LPTSTR argv [])
{
BOOL Flags [MAX_OPTIONS], ok = TRUE;
TCHAR PathName [MAX_PATH + 1], CurrPath [MAX_PATH + 1];
LPTSTR pSlash, pFileName;
int i, FileIndex;

FileIndex = Options (argc, argv, _T ("Rl", &Flags [0], &Flags [1], NULL); // HERE IS THE ERROR ??


GetCurrentDirectory (MAX_PATH, CurrPath);
if (argc < FileIndex + 1)
ok = TraverseDirectory (_T ("*", MAX_OPTIONS, Flags);
else for (i = FileIndex; i < argc; i++) {
_tcscpy (PathName, argv [i]);

pSlash = _tstrrchr (PathName, '\\');

if (pSlash != NULL) {
*pSlash = '\0';
SetCurrentDirectory (PathName);
*pSlash = '\\'; pFileName = pSlash + 1;
} else pFileName = PathName;
ok = TraverseDirectory (pFileName, MAX_OPTIONS, Flags) && ok;
SetCurrentDirectory (CurrPath); /* Restore working directory. */
}

return ok ? 0 : 1;
}

static BOOL TraverseDirectory (LPCTSTR PathName, DWORD NumFlags, LPBOOL Flags)
{
HANDLE SearchHandle;
WIN32_FIND_DATA FindData;
BOOL Recursive = Flags [0];
DWORD FType, iPass;
TCHAR CurrPath [MAX_PATH + 1];


GetCurrentDirectory (MAX_PATH, CurrPath);

for (iPass = 1; iPass <= 2; iPass++) {
SearchHandle = FindFirstFile (PathName, &FindData);
if (SearchHandle == INVALID_HANDLE_VALUE) {
ReportError (_T ("Error opening Search Handle.", 0, TRUE);
return FALSE;
}
do {

FType = FileType (&FindData);
if (iPass == 1) /* ProcessItem is "print attributes". */
ProcessItem (&FindData, MAX_OPTIONS, Flags);


if (FType == TYPE_DIR && iPass == 2 && Recursive) {
_tprintf (_T ("\n%s\\%s:", CurrPath, FindData.cFileName);
SetCurrentDirectory (FindData.cFileName);
TraverseDirectory (_T ("*", NumFlags, Flags);
SetCurrentDirectory (_T ("..");
}


} while (FindNextFile (SearchHandle, &FindData));

FindClose (SearchHandle);
}
return TRUE;
}

static DWORD FileType (LPWIN32_FIND_DATA pFileData)

/ {
BOOL IsDir;
DWORD FType;
FType = TYPE_FILE;
IsDir = (pFileData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
if (IsDir)
if (lstrcmp (pFileData->cFileName, _T (".") == 0
|| lstrcmp (pFileData->cFileName, _T ("..") == 0)
FType = TYPE_DOT;
else FType = TYPE_DIR;
return FType;
}
/
static BOOL ProcessItem (LPWIN32_FIND_DATA pFileData, DWORD NumFlags, LPBOOL Flags)

{
const TCHAR FileTypeChar [] = {' ', 'd'};
DWORD FType = FileType (pFileData);
BOOL Long = Flags [1];
SYSTEMTIME LastWrite;

if (FType != TYPE_FILE && FType != TYPE_DIR) return FALSE;

_tprintf (_T ("\n");
if (Long) {
_tprintf (_T ("%c", FileTypeChar [FType - 1]);
_tprintf (_T ("%10d", pFileData->nFileSizeLow);
FileTimeToSystemTime (&(pFileData->ftLastWriteTime), &LastWrite);
_tprintf (_T (" %02d/%02d/%04d %02d:%02d:%02d",
LastWrite.wMonth, LastWrite.wDay,
LastWrite.wYear, LastWrite.wHour,
LastWrite.wMinute, LastWrite.wSecond);
}
_tprintf (_T (" %s", pFileData->cFileName);
return TRUE;
}

 
  Reply to this ·  Post link ·  Top
Subject: Re: can't compile  ·  Posted: 2004-03-27, 02:19am
Rank: ? (533)
Member #: 8648
Well it is saying that the second argument to the options function is a char*[] and it wants a const char**. I don't know if this will work, but can't you change

LPTSTR argv[]

to

LPCTSTR* argv


? LPCTSTR is a constant array of characters.

ZapX Technologies - We have the solution for you! See zapx.net for web hosting, design, graphics, custom applications, and a forum! Affordable web hosting guaranteeing 99.9% uptime, quality 24/7 support, and a 30-day money back guarantee. hosting.zapx.net
 
  Reply to this ·  Post link ·  Top
Subject: Re: can't compile  ·  Posted: 2007-12-19, 05:56am
Rank: ? (1)
Member #: 29698
I'm reading Hart's book also. I had a heck of a time with that error, although I only got a warning, (I think. Hard to remember now.)

Anyway, the problem isn't with that particular program, it's with the support code called "Options.c"

if you look you'll see Options.c uses a function called _memtchr Now, if you go into support.h, you'll find this:

#define _memtchr wmemchr

in the same file you look for:

LIBSPEC LPCTSTR wmemchr (LPCTSTR, TCHAR, DWORD);

And here is your solution: comment out the last line.

If you go back into the first chapter on Unicode in that book, called "Interlude: Unicode and Generic Characters"
Hart talks about the collection of functions for generic characters in the C-library. He mentions that they are not yet complete and that one such function needed is wmemchr. So, he had to define his own function for Unicode ready compilation. Well, since the book was written a wmemchr has been added to the library. But official definition conflicts with Hart's definition. So, you comment out Hart's definition. Then the compiler does not see the conflict.

I believe that will fix your problem.

Good Luck.

 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

icons