old ms platform โ .NET

Overview
<aside> ๐
์ค๋ฒ๋ทฐ
cpp๋ ์ ๋๋ก ๋ฐ๋์ main()์์ ์์ โ ์์ผ๋ฉด ์ปดํ์ผ ์์ฒด๊ฐ ์๋จ
์ ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(lib, .a, .lib ๋ฑ)์ย mainย ํจ์๊ฐ ํฌํจ๋์ด ์๊ณ , ํ๋ก์ ํธ ์์ main์ด ๋ฐ๋ก ์์ผ๋ฉด, ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ค์ด์๋ main์ด "์คํ ํ์ผ์ ์ง์
์ (entry point)"์ด ๋จ
main์ ์จ๊ธฐ๋ ์ด์ โ ํ๋ ์์ํฌ์ ์ผ๊ด์ฑ๊ณผ ํต์ ์ฑ์ ๋ณด์ฅํ๊ธฐ์ํด
/*IFrameworkApp.h*/////////////////////////////////////////////////////////////////////////
#pragma once
class AppBase {
public:
virtual ~AppBase() {}
virtual int run() = 0;
};
extern AppBase* CreateApp(); // ์ฌ์ฉ์๊ฐ ์ด๊ฑธ ๊ตฌํํ๋๋ก ์๊ตฌ
/*MyProject*/////////////////////////////////////////////////////////////////////////
#include "IFrameworkApp.h"
#include <iostream>
// ๋ด ์ ํ๋ฆฌ์ผ์ด์
ํด๋์ค
class MyApp : public AppBase {
public:
int run() override { // main ๋ฃจํ
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0)) // ์
๋ ฅ์ฅ์น๋ฑ์ผ๋ก ์ด๋ฒคํธ ๋ฐ์์ ํ์ ์์
{
// ๋ฉ์์ง๋ฅผ ์๋์ฐ์ ์ ๋ฌ
if (!AfxPreTranslateMessage(&msg)) // WindowProc ์ ์ ์ฒ๋ฆฌ๋๋ ๋ฉ์ธ์ง, ๋ชจ๋ ๋ฉ์ธ์ง ์ฒ๋ฆฌ์ trueํด์ ๋์คํจ์น ์ํ๊ณ ๋์ด๊ฐ
{
TranslateMessage(&msg); // WM_KEYDOWN(VK_A)๋ผ๋ ๋จ์ํ ๋ฉ์ธ์ง๋ฅผ, WM_CHAR('A') ๊ธ์ํ์์ ๊ณ ์ฐจ์๋ฐ์ดํฐ ๋ฉ์์ง๋ก ๋ณํ์์ฑํด์ ํ์ ์ถ๊ฐ
DispatchMessage(&msg); // ํด๋น ์๋์ฐ(=CWnd)์ WindowProc ํธ์ถ.
}
}
return (int)msg.wParam;
}
};
// ํ๋ ์์ํฌ๊ฐ ์๊ตฌํ ํฉํ ๋ฆฌ ํจ์ ๊ตฌํ
AppBase* CreateApp() {
return new MyApp();
}
/*FrameworkMain.cpp*/////////////////////////////////////////////////////////////////////////
#include "IFrameworkApp.h"
#include <iostream>
int main() {
AppBase* app = CreateApp(); // ์ฌ์ฉ์๊ฐ ์ ๊ณต
if (app) {
int result = app->run(); // ์ฌ์ฉ์๊ฐ ์ ์ํ run() ์คํ
delete app;
return result;
}
std::cerr << "No app instance created!" << std::endl;
return -1;
}
MFC์ํธ๋ฆฌํฌ์ธํธ
#include "stdafx.h"
#include "sal.h"
/////////////////////////////////////////////////////////////////////////////
// export WinMain to force linkage to this module
extern int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine, int nCmdShow); // .lib ์ธ์์ ์ํ ์ ๋ฐฉ์ ์ธ
extern "C" int WINAPI
_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine, int nCmdShow) // WinMain์ ๋ํ์ธ์คํ, ๋๋ค extern์ด ํฌ์ธํธ
#pragma warning(suppress: 4985)
{
// call shared/exported WinMain
return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow); // ์ค์ ๋ฆฌํด
}
<aside> ๐ผ๏ธ
๋ฉ์ธ์ง๋งต
์ ์ธ๋ถ
DECLARE_MESSAGE_MAP
#define DECLARE_MESSAGE_MAP() \\
protected: \\
static const AFX_MSGMAP* PASCAL GetThisMessageMap(); \\
virtual const AFX_MSGMAP* GetMessageMap() const; \\
class CMyDialog : public CDialogEx
{
// ... ๊ธฐํ ๋ฉค๋ฒ ์ ์ธ ...
protected:
afx_msg void OnBnClickedMyButton(); // ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ ํธ๋ค๋ฌ ์ ์ธ
DECLARE_MESSAGE_MAP() // ๋ฉ์์ง ๋งต ์ ์ธ ๋งคํฌ๋ก
};
๊ตฌํ๋ถ
BEGIN_MESSAGE_MAP(CMyDialog, CDialogEx)
ON_BN_CLICKED(IDC_MYBUTTON, &CMyDialog::OnBnClickedMyButton)
END_MESSAGE_MAP()
// ์๋์ ๊ฐ์ด ๋ณํ
const AFX_MSGMAP* CMyDialog::GetMessageMap() const { return GetThisMessageMap(); }
const AFX_MSGMAP* PASCAL CMyDialog::GetThisMessageMap() {
typedef CMyDialog ThisClass;
typedef CDialogEx TheBaseClass;
static const AFX_MSGMAP_ENTRY _messageEntries[] = {
{ WM_COMMAND, CN_COMMAND, (WORD)IDC_MYBUTTON, (WORD)IDC_MYBUTTON, AfxSig_vv,
(AFX_PMSG)(void (AFX_MSG_CALL CWnd::*)(void))&CMyDialog::OnBnClickedMyButton },
{0, 0, 0, 0, AfxSig_end, 0}
};
static const AFX_MSGMAP messageMap = {
&TheBaseClass::GetThisMessageMap, &_messageEntries[0]
};
return &messageMap;
}
</aside>