Click here to Skip to main content
15,897,334 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: c++ win32, Trouble getting CreateThread and CreateProcess running together Pin
jkirkerx25-Jan-12 10:04
professionaljkirkerx25-Jan-12 10:04 
QuestionRe: c++ win32, Trouble getting CreateThread and CreateProcess running together Pin
CPallini25-Jan-12 10:12
mveCPallini25-Jan-12 10:12 
AnswerRe: c++ win32, Trouble getting CreateThread and CreateProcess running together Pin
jkirkerx25-Jan-12 10:47
professionaljkirkerx25-Jan-12 10:47 
GeneralDone Pin
jkirkerx25-Jan-12 11:28
professionaljkirkerx25-Jan-12 11:28 
QuestionSHFileOperation with SHFILEOPSTRUCT fails when used with vars but works with string literals Pin
bcb_guy25-Jan-12 1:06
bcb_guy25-Jan-12 1:06 
AnswerRe: SHFileOperation with SHFILEOPSTRUCT fails when used with vars but works with string literals Pin
Jochen Arndt25-Jan-12 1:55
professionalJochen Arndt25-Jan-12 1:55 
AnswerRe: SHFileOperation with SHFILEOPSTRUCT fails when used with vars but works with string literals Pin
Richard Andrew x6425-Jan-12 2:06
professionalRichard Andrew x6425-Jan-12 2:06 
AnswerIssue Resolved! (Of Course User Error) Pin
bcb_guy25-Jan-12 17:41
bcb_guy25-Jan-12 17:41 
Well, I have managed to resolve the issue. I had errors even in the second version of the Nullify function. (P.S I changed the project type to Multi-byte char set and I am no longer forced to use wide chars).

Working version of the code is shown below:

C++
int FileCopy(LPSTR cSource, LPSTR cDest)
{
	// Note - This string must be double-null terminated.
	// Source: http://msdn.microsoft.com/en-us/library/windows/desktop/bb759795%28v=vs.85%29.aspx

	cSource = Nullify::NullifyString(cSource, true);
	cDest = Nullify::NullifyString(cDest);
	
	int NullCount = Tools::CountCharType('\0',cSource, strlen(cSource) + 2);
	Messages::ShowMessage(NullCount);

	SHFILEOPSTRUCT shFileOps;
	ZeroMemory(&shFileOps, sizeof(shFileOps));

	shFileOps.wFunc = FO_COPY;
	shFileOps.pFrom = cSource;
	shFileOps.pTo = cDest;

	shFileOps.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_SILENT;
	shFileOps.fFlags |= FOF_ALLOWUNDO;

	return SHFileOperation(&shFileOps);
}


C++
char *NullifyString(const char *cSource, bool DoubleNull = false)
{
    std::string strValue = cSource;

    char *cNullTerminated;

    if (DoubleNull)
        cNullTerminated = new char [strValue.size() + 2];
    else
        cNullTerminated = new char [strValue.size() + 1];

    strcpy (cNullTerminated, strValue.c_str());
    // cNullTerminated now contains a c-string copy of strValue (with a NULL char)

    if (DoubleNull)
        cNullTerminated[strlen(cNullTerminated) + 1] = '\0';

    return cNullTerminated;
}


Here is a wide char version of the Nullify function

C++
// Inserts a NULL at the end of the string
wchar_t *NullifyWideString(const wchar_t *wcSource, bool DoubleNull = false)
{
    std::wstring strValue = wcSource;

    wchar_t *wcNullTerminated;

    if (DoubleNull)
        wcNullTerminated = new wchar_t [strValue.size() + 2];
    else
        wcNullTerminated = new wchar_t [strValue.size() + 1];

    wcscpy (wcNullTerminated, strValue.c_str());
    // wcNullTerminated now contains a c-string copy of strValue (with a NULL char)

    if (DoubleNull)
        wcNullTerminated[wcslen(wcNullTerminated) + 1] = '\0';

    return wcNullTerminated;
}


Smile | :) I don't remember having these issues with C++ Builder but that's probably because 1. It fixes my errors and I don't even know about it, 2. VC++ is more restrictive, 3. There are errors I just haven't noticed it. Thanks Jochen and Richard for your assistance. P.S. I am now making sure there is always a "\0" at the end of any char array.

modified 26-Jan-12 2:38am.

GeneralRe: Issue Resolved! (Of Course User Error) Pin
Jochen Arndt25-Jan-12 21:20
professionalJochen Arndt25-Jan-12 21:20 
GeneralRe: Issue Resolved! (Of Course User Error) Pin
bcb_guy25-Jan-12 23:29
bcb_guy25-Jan-12 23:29 
GeneralRe: Issue Resolved! (Of Course User Error) Pin
David Crow26-Jan-12 3:06
David Crow26-Jan-12 3:06 
QuestionGet the local drives, scan and retrieve files using visual c++ Pin
amabi25-Jan-12 0:43
amabi25-Jan-12 0:43 
AnswerRe: Get the local drives, scan and retrieve files using visual c++ Pin
David Crow25-Jan-12 3:01
David Crow25-Jan-12 3:01 
QuestionXML Data To C++ Objects Pin
002comp24-Jan-12 22:24
002comp24-Jan-12 22:24 
AnswerRe: XML Data To C++ Objects Pin
Rolf Kristensen26-Jan-12 20:20
Rolf Kristensen26-Jan-12 20:20 
QuestionHow to check if an internet connection exist ? Pin
_Flaviu24-Jan-12 1:13
_Flaviu24-Jan-12 1:13 
AnswerRe: How to check if an internet connection exist ? Pin
Rajesh R Subramanian24-Jan-12 2:07
professionalRajesh R Subramanian24-Jan-12 2:07 
Questionusing extern in C Pin
Sakhalean23-Jan-12 22:53
Sakhalean23-Jan-12 22:53 
AnswerRe: using extern in C Pin
Jochen Arndt23-Jan-12 23:09
professionalJochen Arndt23-Jan-12 23:09 
GeneralRe: using extern in C Pin
Sakhalean23-Jan-12 23:32
Sakhalean23-Jan-12 23:32 
GeneralRe: using extern in C Pin
Jochen Arndt23-Jan-12 23:41
professionalJochen Arndt23-Jan-12 23:41 
AnswerRe: using extern in C Pin
Erudite_Eric24-Jan-12 5:33
Erudite_Eric24-Jan-12 5:33 
AnswerRe: using extern in C Pin
Stefan_Lang24-Jan-12 5:50
Stefan_Lang24-Jan-12 5:50 
GeneralRe: using extern in C Pin
Erudite_Eric24-Jan-12 6:23
Erudite_Eric24-Jan-12 6:23 
GeneralRe: using extern in C Pin
Stefan_Lang24-Jan-12 22:44
Stefan_Lang24-Jan-12 22:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.