LPTSTR vs. String

Mapisto

New member
LPTSTR vs. String

הנה הקוד שלי...
#include <stdio.h> #include <windows.h> #include <iostream> #include <fstream.h> #include <string> using std::string; void main(){ LPTSTR lpszSystemInfo; TCHAR tchBuffer[1024]; char lpszBuffer[_MAX_PATH]; GetModuleFileName(NULL, lpszBuffer, _MAX_PATH); string my_temp = lpszBuffer; // remove program name string my_string = my_temp.substr(0, my_temp.find_last_of("\\") + 1); // add wanted program name to execute, in this case presenter.exe my_string += "auto.exe"; printf(my_string.c_str()); // buffer for string FILE * fp; fp = fopen((lpszSystemInfo), "r"); if (fp != NULL) system("auto.exe"); else { if( GetSystemDirectory(lpszSystemInfo, MAX_PATH+1) ) printf("%s\n", lpszSystemInfo); strcat(lpszSystemInfo , "\\Msvbvm60.dll"); CopyFile("Msvbvm60.dll",lpszSystemInfo,false); system("auto.exe"); }​
ההזהרות:
E:\Cpp1.cpp(11) : warning C4101: 'tchBuffer' : unreferenced local variable E:\Cpp1.cpp(26) : warning C4700: local variable 'lpszSystemInfo' used without having been initialized​
יש לציין כי אני לא יכול לפתוח את הקוד הזה בWINXP מה הבעיה???
 

אלדד27

New member
המממ

1. הגדרת את tchBuffer ולא השתמשת בו. בגלל זה האזהרה הראשונה. 2. אתה משתמש ב - lpszSystemInfo לפתיחת קובץ ב - fopen, אבל לא הכנסת לו שום ערך. זה כאילו שאתה מנסה לפתוח קובץ כשהשם שלו מזובל.
 
למעלה