First real WinAPI program...

This is a discussion on First real WinAPI program... within the Windows Programming forums, part of the Platform Specific Boards category; Recently I've been working on a Click and Create extention and the ease of useing dialogs struck me, so as ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    41

    Question First real WinAPI program...

    Recently I've been working on a Click and Create extention and the ease of useing dialogs struck me, so as a side project I started "CK-Prog" for lack of the better name at the time, I planned it to be a simple app that Created a Dialog and that'll be the main window.

    But now I've come across a seemingly novice problem, CreateDialog() isn't working, heres the code:

    main.cpp -- Sence I very much think the problem is only in main.cpp, I've only put main.cpp source in.
    Code:
    /*-- CK-Prog
     *
     *
     *
     */
    
    #include "main.h"
    
    int mainProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        char hi[100],tmphi[100];
    	
    	switch(Message)
        {
            case WM_INITDIALOG:
    			SetDlgItemText(hwnd, ID_NAME_EB, "ck4r1");
    
    			return 0;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case ID_EXIT:
                        EndDialog(hwnd, ID_EXIT);
    					break;
    
    				case ID_INFO:
    					MessageBox(NULL,"\tCK-Prog\nCKarl's first real program with WinAPI.\n\n(C) Karl 2004","CK-Prog",MB_OK);
    
    					break;
    
    				case ID_HELLO: // clicked "Hello!"
    					GetDlgItemText(hwnd, ID_NAME_EB, tmphi, 100);
    					//^ Put the edit box text into a tmp buffer
    					wsprintf(hi,"Hello %s",tmphi);
    					//^ put the tmp buffer with "Hello" into hi
    					MessageBox(hwnd, hi,"Hello!",MB_OK);
    					//^ pops up the MsgBox with your name in it!
    					break;
                }
            break;
            default:
    			return 1;
        }
        return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
    {
    	HWND WIN_MAIN = NULL;
    
    	WIN_MAIN = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_MAIN), NULL, mainProc);
    
    	if(WIN_MAIN == NULL)
    		MessageBox(WIN_MAIN, "'WIN_MAIN' did not open correctly!","ERROR!",MB_OK | MB_ICONINFORMATION);
    
    	
    	return(0);// no error
    }
    and if anyone finds other problems that might make it go in a undesireble way, plz post it.

    Here is the error:

    C:\Programs\CKProg\main.cpp(53) : error C2664: 'CreateDialogParamA' : cannot convert parameter 4 from 'int (void *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(void)'


    THX, CK4R1 0U7
    Last edited by Budgiekarl; 05-23-2004 at 07:06 AM.
    THERE IS NO PLACE LIKE 127.0.0.1

  2. #2
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    mainProc should be

    INT_PTR CALLBACK mainProc( HWND hwnd, UING msg, WPARAM wParam, LPARAM lParam )

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    41
    I do that and I get 27 errors:
    C:\Programs\CKProg\main.cpp(9) : error C2501: 'INT_PTR' : missing decl-specifiers
    C:\Programs\CKProg\main.cpp(9) : error C2239: unexpected token '__stdcall' following declaration of 'INT_PTR'
    C:\Programs\CKProg\main.cpp(9) : error C2059: syntax error : '__stdcall'
    C:\Programs\CKProg\main.cpp(13) : error C2143: syntax error : missing ';' before 'switch'
    C:\Programs\CKProg\main.cpp(18) : error C2143: syntax error : missing ';' before 'return'
    C:\Programs\CKProg\main.cpp(19) : error C2143: syntax error : missing ';' before 'case'
    C:\Programs\CKProg\main.cpp(24) : error C2143: syntax error : missing ';' before 'break'
    C:\Programs\CKProg\main.cpp(26) : error C2143: syntax error : missing ';' before 'case'
    C:\Programs\CKProg\main.cpp(31) : error C2143: syntax error : missing ';' before 'break'
    C:\Programs\CKProg\main.cpp(33) : error C2143: syntax error : missing ';' before 'case'
    C:\Programs\CKProg\main.cpp(36) : error C2065: 'hi' : undeclared identifier
    C:\Programs\CKProg\main.cpp(36) : error C2065: 'tmphi' : undeclared identifier
    C:\Programs\CKProg\main.cpp(36) : error C2501: 'wsprintfA' : missing decl-specifiers
    C:\Programs\CKProg\main.cpp(36) : error C2040: 'wsprintfA' : 'int' differs in levels of indirection from 'int (char *,const char *,...)'
    C:\Programs\CKProg\main.cpp(38) : error C2065: 'hwnd' : undeclared identifier
    C:\Programs\CKProg\main.cpp(38) : error C2501: 'MessageBoxA' : missing decl-specifiers
    C:\Programs\CKProg\main.cpp(38) : error C2040: 'MessageBoxA' : 'int' differs in levels of indirection from 'int (void *,const char *,const char *,unsigned int)'
    C:\Programs\CKProg\main.cpp(40) : error C2143: syntax error : missing ';' before 'break'
    C:\Programs\CKProg\main.cpp(41) : error C2143: syntax error : missing ';' before '}'
    C:\Programs\CKProg\main.cpp(43) : error C2143: syntax error : missing ';' before 'default'
    C:\Programs\CKProg\main.cpp(45) : error C2143: syntax error : missing ';' before '}'
    C:\Programs\CKProg\main.cpp(47) : error C2143: syntax error : missing ';' before '}'
    C:\Programs\CKProg\main.cpp(53) : error C2501: 'WIN_MAIN' : missing decl-specifiers
    C:\Programs\CKProg\main.cpp(53) : error C2065: 'mainProc' : undeclared identifier
    C:\Programs\CKProg\main.cpp(55) : error C2143: syntax error : missing ';' before 'if'
    C:\Programs\CKProg\main.cpp(59) : error C2143: syntax error : missing ';' before 'return'
    C:\Programs\CKProg\main.cpp(60) : error C2143: syntax error : missing ';' before '}'
    THERE IS NO PLACE LIKE 127.0.0.1

  4. #4
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    You need the latest SDK to access the latest Windows Data Types:
    http://msdn.microsoft.com/library/en...data_types.asp

    INT_PTR is 32-bits in size for 32-bit Windows, and 64-bits in size for 64-bit Windows, so that it always matches the size of a pointer. Therefore, to have code compatible with both versions of Windows, you should use it whenever you need a variable to do pointer arithmetic.

  5. #5
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Btw, since you are NOT using the latest SDK, then you should be able to compile the program using the OLD style DialogProc, like so:

    BOOL CALLBACK DialogProc( HWND hwndDlg,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam
    );

    So, basically, you forgot that CALLBACK calling convention, since BOOL is equivalent to int.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting text into MDI program
    By Rutabega in forum Windows Programming
    Replies: 0
    Last Post: 12-23-2005, 10:25 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Problem with simple XOR program
    By spike_ in forum C++ Programming
    Replies: 8
    Last Post: 08-17-2005, 12:09 AM
  4. a tutorial on a voice communications program
    By Geo-Fry in forum C++ Programming
    Replies: 5
    Last Post: 08-12-2003, 07:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21