I’ve been writing an application that monitors certain directory for files being added, and sending those files in certain order. It does work perfectly. But I’ve encountered an interesting problem – I wrote this project on Windows XP, using VS 2008, and I need to merge my solution with another one, located on PC with Windows 7 and VS 2010, but the code I wrote just simply doesn’t work the same! A. k. a. I’ve treated TCHAR* as char*, as far as I know it shouldn’t give problems, but on VS 2010 the conversion doesn’t happen. The code is posted below.
int ftp_send(char* filename, TCHAR* path) {
FILE *fPtr,*fp;
char s[128],*loc=NULL;
char command1[1024];
char log[1024];
char systemcom[2048];
char name1[1024];
int success = 0;
sprintf_s(command1, 1024, "open 127.0.0.1\nbear\nitriv100\nbinary\nprompt\nmput %s\\rev%s*\n\nbye\n", path, filename);
sprintf_s(log, 1024, "%s\\log.txt", path);
sprintf_s(name1, 1024, "%s\\ftp.txt", path);
sprintf_s(systemcom, 2048, "ftp -s:%s -d | find\"226\" > %s", name1, log);
//printf("%s\n%s\n%s\n", systemcom, name1, log);
fopen_s(&fp, name1, "w+");
fprintf(fp,command1);
fclose(fp);
while(!success){
system(systemcom);
fopen_s(&fPtr, log, "r");
if (!fPtr) {
printf("open file failure...\n");
return -1;
}
while (fgets(s, 128, fPtr) != NULL) {
loc = strstr(s, "226");
if(loc != NULL) {
printf("File rev%s completely!!\n",filename);
success = 1;
return 0;
}
}
fclose(fPtr);
}
return -1;
}
Thanks in advance.
Constantine
Most probably, the problem here is that your VS 2008 project was Multibyte CharacterSet based and VS 2010 project is UNICODE based.
Right-click on Project->Properties->General->Character Set
Change it to ‘Use Multi-Byte Character Set‘.
Alternatively, if you want to keep your code
UNICODEbased, then add_Tbefore all the strings that you are defining.