剛裝的VS2015 自動生成的對話框程式 編程成功 CTRL+F5可以運行 F5就彈出一個 無效指標的對話,各位大大知道是為什么嗎?
uj5u.com熱心網友回復:
崩潰的時候在彈出的對話框按相應按鈕進入除錯,按Alt+7鍵查看Call Stack即“呼叫堆疊”里面從上到下列出的對應從里層到外層的函式呼叫歷史。雙擊某一行可將游標定位到此次呼叫的源代碼或匯編指令處,看不懂時雙擊下一行,直到能看懂為止。uj5u.com熱心網友回復:
趙老師,這段是不是刪減版
uj5u.com熱心網友回復:
有時不將“呼叫函式名字+各引數值,進入函式后各引數值,中間變數值,退出函式前準備回傳的值,回傳函式到呼叫處后函式名字+各引數值+回傳值”這些資訊寫日志到檔案中是無論如何也發現不了問題在哪里的,包括捕獲各種例外、寫日志到螢屏、單步或設斷點或生成core或dmp檔案、……這些方法都不行! 寫日志到檔案參考下面:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#pragma warning(disable:4996)
#include <windows.h>
#include <io.h>
#else
#include <unistd.h>
#include <sys/time.h>
#include <pthread.h>
#define CRITICAL_SECTION pthread_mutex_t
#define _vsnprintf vsnprintf
#endif
//Log{
#define MAXLOGSIZE 20000000
#define MAXLINSIZE 16000
#include <time.h>
#include <sys/timeb.h>
#include <stdarg.h>
char logfilename1[]="MyLog1.log";
char logfilename2[]="MyLog2.log";
static char logstr[MAXLINSIZE+1];
char datestr[16];
char timestr[16];
char mss[4];
CRITICAL_SECTION cs_log;
FILE *flog;
#ifdef _MSC_VER
void Lock(CRITICAL_SECTION *l) {
EnterCriticalSection(l);
}
void Unlock(CRITICAL_SECTION *l) {
LeaveCriticalSection(l);
}
#else
void Lock(CRITICAL_SECTION *l) {
pthread_mutex_lock(l);
}
void Unlock(CRITICAL_SECTION *l) {
pthread_mutex_unlock(l);
}
#endif
void LogV(const char *pszFmt,va_list argp) {
struct tm *now;
struct timeb tb;
if (NULL==pszFmt||0==pszFmt[0]) return;
_vsnprintf(logstr,MAXLINSIZE,pszFmt,argp);
ftime(&tb);
now=localtime(&tb.time);
sprintf(datestr,"%04d-%02d-%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday);
sprintf(timestr,"%02d:%02d:%02d",now->tm_hour ,now->tm_min ,now->tm_sec );
sprintf(mss,"%03d",tb.millitm);
printf("%s %s.%s %s",datestr,timestr,mss,logstr);
flog=fopen(logfilename1,"a");
if (NULL!=flog) {
fprintf(flog,"%s %s.%s %s",datestr,timestr,mss,logstr);
if (ftell(flog)>MAXLOGSIZE) {
fclose(flog);
if (rename(logfilename1,logfilename2)) {
remove(logfilename2);
rename(logfilename1,logfilename2);
}
} else {
fclose(flog);
}
}
}
void Log(const char *pszFmt,...) {
va_list argp;
Lock(&cs_log);
va_start(argp,pszFmt);
LogV(pszFmt,argp);
va_end(argp);
Unlock(&cs_log);
}
//Log}
int main(int argc,char * argv[]) {
int i;
#ifdef _MSC_VER
InitializeCriticalSection(&cs_log);
#else
pthread_mutex_init(&cs_log,NULL);
#endif
for (i=0;i<10000;i++) {
Log("This is a Log %04d from FILE:%s LINE:%d\n",i, __FILE__, __LINE__);
}
#ifdef _MSC_VER
DeleteCriticalSection(&cs_log);
#else
pthread_mutex_destroy(&cs_log);
#endif
return 0;
}
//1-79行添加到你帶main的.c或.cpp的那個檔案的最前面
//81-86行添加到你的main函式開頭
//90-94行添加到你的main函式結束前
//在要寫LOG的地方仿照第88行的寫法寫LOG到檔案MyLog1.log中
uj5u.com熱心網友回復:
F5 和 Ctrl+F5 運行的當前路徑不一樣,如果用到與路徑相關的代碼需要留意
uj5u.com熱心網友回復:
專案、屬性、配置屬性、除錯、作業目錄。
uj5u.com熱心網友回復:
樓主解決沒啊,求助
uj5u.com熱心網友回復:
我已經解決了,樓主如果你沒有解決的話 m我uj5u.com熱心網友回復:
我已經解決了,樓主如果你沒有解決的話 m我
你好我也是這個問題,怎么解決 的?求解方便發我郵箱么?[email protected]
uj5u.com熱心網友回復:
我也遇到同樣的問題,求解決方法,謝謝!uj5u.com熱心網友回復:
對,直接點擊Alt+F5就好了,就解決了!轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/79664.html
標籤:基礎類
