我真的想使用MFC的一些功能,但它的工作很痛苦。將MFC添加到現有的Win32 C++導致錯誤/崩潰
我最初想要做的就是添加兩個自旋控制和它們各自的編輯控制。一旦我實現了適當的方法來設置範圍,我發現我需要使用MFC。
所以VS抱怨沒有MFC。所以我去項目屬性並添加使用MFC共享DLL。運行它,崩潰! Win32Project1.exe中0x5964D8D2(mfc120ud.dll)未處理的異常:0xC0000005:訪問衝突讀取位置0x00000000
因此,我嘗試了靜態,錯誤!許多鏈接器錯誤,以供列出。
所以我回到了共享。錯誤發生在這個區域。
/////////////////////////////////////////////////////////////////////////////
// export WinMain to force linkage to this module
extern int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine, int nCmdShow);
extern "C" int WINAPI
_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine, int nCmdShow)
#pragma warning(suppress: 4985)
{
// call shared/exported WinMain
return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}
與在最後
當地人的箭頭示出了}的hInstance的值作爲紅色+
的hInstance 0x000d0000 {Win32Project1.exe!_IMAGE_DOS_HEADER 基址} {未使用= 9460301} HINSTANCE *
,並在lpCmdLine + lpCmdLine 0x00831f8c L 「」 爲wchar_t *
這超出了我的專業知識的調試和非常坦率地會考慮另一個不使用MFC的旋轉框的替代品,但它似乎我需要MFC越來越多,因爲我想包括更多的功能,所以它會很高興讓MFC工作,但它似乎也更加脆弱。也許對於像我這樣的粗糙程序員來說很敏感。
我想知道如果#includes可能是這個錯誤的原因?要麼訂單?或缺乏?
這是我在stdafx.h中
#pragma once
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "comctl32.lib")
#pragma comment (lib, "winmm.lib")//to play audio
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#include "targetver.h"
//#include <WinSDKVer.h>
//#include <afxwin.h>
#include <afxcmn.h>//for spinControl
#include <Afx.h>
#include <stdio.h>
#include <tchar.h>
#include "iostream"
#include "string.h"
#include <math.h>
//#include <ctime>//more time related stuff
#include <fstream>//for file io
#include <thread>//for threads
//#include <chrono> //for time related stuff
//#include <windows.h>
#include <Mmsystem.h>//to play audio
#include <commctrl.h>
#include <atlstr.h>//for some type of string
#include <io.h>
#include <fcntl.h>
#include <commctrl.h> //For button sytles, maybe other styles
難道會有與代碼衝突? MFC的代碼不同於標準的Win32嗎?也可以Win32做一切MFC可以?我認爲它更難實施? – Nonlin
是的,會有衝突。您將對MFC有很好的理解以解決衝突。這不是直截了當的。我不確定你的Win32應用程序中有多少代碼。所以衝突將取決於此。 –