I do something in the .rc files(EDITTEXT,COMBOBOX...),and the main of .asm file to compile the main-window is:

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;
}



Posted on 2005-12-28 01:00:59 by Eric4ever
if DLG_MAIN is identifier (not string) you should not quote it in c-source: do it like you did in masm source
Posted on 2005-12-28 01:05:38 by Shoo
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.
Posted on 2005-12-28 07:15:14 by ti_mo_n
I doubt about & sign, anyway my suggestion:

return DialogBoxParam(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, reinterpret_cast<DLGPROC>(DlgProc), reinterpret_cast<LPARAM>(NULL));
Posted on 2005-12-28 10:54:27 by ramguru