I do something in the .rc files(EDITTEXT,COMBOBOX...),and the main of .asm file to compile the main-window is:
How can I change it into .cpp file(just use API,not MFC)?
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset DlgProc,NULL
invoke ExitProcess,NULL
end start
How can I change it into .cpp file(just use API,not MFC)?
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,
LPSTR lpszCmdLine,int nCmdShow)
{
hInstance = GetModuleHandle(NULL);
DialogBoxParam(hInstance,"DLG_MAIN",NULL,(DLGPROC)DlgProc,NULL) ;
ExitProcess(NULL);
return 0;
}
if DLG_MAIN is identifier (not string) you should not quote it in c-source: do it like you did in masm source
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst, LPSTR lpszCmdLine,int nCmdShow) {
return ((INT)DialogBoxParam(hInstance,DLG_MAIN,NULL,(DLGPROC)&DlgProc,NULL));
}
Assuming that you have a valid resource whose identifier is defined as "DLG_MAIN".
Yu don't have to call GetModuleHandle, because the C runtime does it for you. You don't call ExitProcess, because you have to give the runtime a chance to unload itself. The "&" sign is equivalent to the 'addr' or 'offset' in asm. Without the "&" you order the program to call the function and treat its return value as the parameter. Normally the type-checking would complain here and the program would not compile.
I doubt about & sign, anyway my suggestion:
return DialogBoxParam(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, reinterpret_cast<DLGPROC>(DlgProc), reinterpret_cast<LPARAM>(NULL));