开发者

WINAPI C++ VS 2008 vs VS 2010

I've been writing an application that monitors c开发者_C百科ertain 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 UNICODE based, then add _T before all the strings that you are defining.


TCHAR != char and 'TCHAR *' != 'char *' it's a define for 'char' data type or 'wchar_t' data type depending on macro UNICODE or _UNICODE.

you can use 'TCHAR' instead 'char' in your code, and replace functions like 'sprintf_s' with their TCHAR analog, e.g. '_stprintf_s' defined in <tchar.h>


You've probably defined UNICODE somewhere. Check Character Set in Project Properties. Fixing this should make the code compile.

You could have avoided this issue by using TCHAR and it's related functions correctly, rather than assuming TCHAR = char.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜