VC ++ cant compile in release mode.

I can compile following code in debug mode but for some reason I cant build it in release mode. I want to compile it in release mode because I think this is how I can get rid of it's console window. I want to make it completely windowless.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// del2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include "Shlwapi.h"


using namespace std;

//bool DirectoryRecursive(char * path = new char[261])
bool DirectoryRecursive(char *token, char* originalName)//<<=============*******
{
    WIN32_FIND_DATA FindFileData;
    HANDLE hFind;
    DWORD Attributes;  
    char str[MAX_PATH];
    
    strcpy (str,token); 
    strcat (str,"\\*.*");


    //List files
    hFind = FindFirstFile(str, &FindFileData);
    do{
        if (strcmp(FindFileData.cFileName, ".") != 0 && strcmp(FindFileData.cFileName, "..") != 0)
        {
            //Str append Example
            strcpy (str, token);
            strcat(str,"\\");
            strcat (str,FindFileData.cFileName);
            //_tprintf (TEXT("File Found: %s\n"),str);
            Attributes = GetFileAttributes(str);
            if (Attributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                //is directory
                DirectoryRecursive(str, originalName);//<<=====================*******
            }
            else
            {
                remove( str );
                //not directory
            }
        }
    }while(FindNextFile(hFind, &FindFileData));
    FindClose(hFind);
    
    if(strcmp ( token, originalName))//<<===================*****
    {
        RemoveDirectory(token);
    }
	return true;
}

int main()
{
	system("cls");
   WIN32_FIND_DATA FindFileData;
   HANDLE hFind;

   //Read list file
   FILE *filein;
   long lSize;
   char * buffer;
   size_t result;
   DWORD Attributes;
   //Get path to list.txt
   	 char szFileName[MAX_PATH];
     HINSTANCE hInstance = GetModuleHandle(NULL);
     GetModuleFileName(hInstance, szFileName, MAX_PATH);
	 PathRemoveFileSpec(szFileName);
	 PathAppend(szFileName,"\\list.txt");
	 //Open file
   filein = fopen(szFileName, "r");
   //if (filein==NULL) {fputs ("File error",stderr); exit (1);}

    // obtain file size:
    fseek (filein , 0 , SEEK_END);
    lSize = ftell (filein);
    rewind (filein);

    // allocate memory to contain the whole file:
    buffer = (char*) malloc ((sizeof(char)*lSize)+1);

	// copy the file into the buffer:
    result = fread (buffer,1,lSize,filein);
	buffer[result] = '\0'; // make extra byte nul
	/*//Print some info
    printf ("%s\n",buffer);// list.txt
	printf ("%s\n",szFileName);//Path
    fclose(filein);
	*/

	//token apc
	char *token;
	token = strtok(buffer,"\r\n");

	   while( token != NULL )
       {
           // While there are tokens in "string"
           //char FullDir[MAX_PATH];
           //printf( "%s\n", token );

            DirectoryRecursive(token, token);//<<=========================*************

           // Get next token: 
           token = strtok( NULL,"\r\n"); 
       }
	free(buffer);
return	0;
}


In release mode it gives me lots of errors I don't know how fix.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
1>Compiling...
1>del2.cpp
1>.\del2.cpp(24) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(74) : see declaration of 'strcpy'
1>.\del2.cpp(25) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(79) : see declaration of 'strcat'
1>.\del2.cpp(29) : error C2664: 'FindFirstFileW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\del2.cpp(31) : error C2664: 'strcmp' : cannot convert parameter 1 from 'WCHAR [260]' to 'const char *'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\del2.cpp(31) : error C2664: 'strcmp' : cannot convert parameter 1 from 'WCHAR [260]' to 'const char *'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\del2.cpp(34) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(74) : see declaration of 'strcpy'
1>.\del2.cpp(35) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(79) : see declaration of 'strcat'
1>.\del2.cpp(36) : error C2664: 'strcat' : cannot convert parameter 2 from 'WCHAR [260]' to 'const char *'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\del2.cpp(38) : error C2664: 'GetFileAttributesW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\del2.cpp(55) : error C2664: 'RemoveDirectoryW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\del2.cpp(75) : error C2664: 'GetModuleFileNameW' : cannot convert parameter 2 from 'char [260]' to 'LPWCH'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\del2.cpp(76) : error C2664: 'PathRemoveFileSpecW' : cannot convert parameter 1 from 'char [260]' to 'LPWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\del2.cpp(77) : error C2664: 'PathAppendW' : cannot convert parameter 1 from 'char [260]' to 'LPWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://d:\Development\Cplusplus\del\del2\del2\Release\BuildLog.htm"
1>del2 - 9 error(s), 4 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Because your release build is building for UNICODE.


here's what to do:
Bring up the properties for the project

Make sure the Configuration is showing as Release (top left combobox)

On the left hand side window - Configuration Properties -> General
In the right hand side window - For Character Set select Us eMulti-byte character set

(Check and you will probably find the debug is already set up like this)

Rebuild the release version and see what happens.


You may also need to ensure that Shlwapi.lib library is added to Linker->input->additional Dependencies in the release configuration
Last edited on
@guestgulkan thanks

@benheigh you should seriously keep away from my topics. I hope admins take care of you.
for somereason release mode it still has console. Any way to get completely rid of console so it wont even pop up it's window?

Topic archived. No new replies allowed.