Please Help!

Hello!
I'm developing a C program, mixed with C++, but what is wrong with this code (C-code, made with Pelles C):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

#define WIN32_LEAN_AND_MEAN
/* #define NOCRYPT */
/* #define NOSERVICE */
/* #define NOMCX */
/* #define NOIME */

#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include <mmsystem.h>
#include <stdio.h>
#include "main.h"

#define NELEMS(a)  (sizeof(a) / sizeof((a)[0]))

/** Prototypes **************************************************************/

static INT_PTR CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM);
void CALLBACK waveInProc(HWAVEIN, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR);

/** Global variables ********************************************************/

static HANDLE ghInstance;
BOOL recording;
BOOL stopped;

/****************************************************************************
 *                                                                          *
 * Function: WinMain                                                        *
 *                                                                          *
 * Purpose : Initialize the application.  Register a window class,          *
 *           create and display the main window and enter the               *
 *           message loop.                                                  *
 *                                                                          *
 * History : Date      Reason                                               *
 *           00/00/00  Created                                              *
 *                                                                          *
 ****************************************************************************/

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
    INITCOMMONCONTROLSEX icc;
    WNDCLASSEX wcx;

    ghInstance = hInstance;

    /* Initialize common controls. Also needed for MANIFEST's */
    /*
     * TODO: set the ICC_???_CLASSES that you need.
     */
    icc.dwSize = sizeof(icc);
    icc.dwICC = ICC_WIN95_CLASSES /*|ICC_COOL_CLASSES|ICC_DATE_CLASSES|ICC_PAGESCROLLER_CLASS|ICC_USEREX_CLASSES|... */;
    InitCommonControlsEx(&icc);

    /* Load Rich Edit control support */
    /*
     * TODO: uncomment one of the lines below, if you are using a Rich Edit control.
     */
    // LoadLibrary(_T("riched32.dll"));  // Rich Edit v1.0
    // LoadLibrary(_T("riched20.dll"));  // Rich Edit v2.0, v3.0

    /*
     * TODO: uncomment line below, if you are using the Network Address control (Windows Vista+).
     */
    // InitNetworkAddressControl();

    /* Get system dialog information */
    wcx.cbSize = sizeof(wcx);
    if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx))
        return 0;

    /* Add our own stuff */
    wcx.hInstance = hInstance;
    wcx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
    wcx.lpszClassName = _T("SoundRecClass");
    if (!RegisterClassEx(&wcx))
        return 0;

    /* The user interface is a modal dialog box */
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDlgProc);
}

/****************************************************************************
 *                                                                          *
 * Function: MainDlgProc                                                    *
 *                                                                          *
 * Purpose : Process messages for the Main dialog.                          *
 *                                                                          *
 * History : Date      Reason                                               *
 *           00/00/00  Created                                              *
 *                                                                          *
 ****************************************************************************/

static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_INITDIALOG:
            AllocConsole();
			recording = FALSE;
			stopped = FALSE;
            return TRUE;

        case WM_SIZE:
            /*
             * TODO: Add code to process resizing, when needed.
             */
            return TRUE;

        case WM_COMMAND:
            switch (GET_WM_COMMAND_ID(wParam, lParam))
            {
                /*
                 * TODO: Add more control ID's, when needed.
                 */
                case BTN_START:
                {
					printf("Enter bits-per-sample (8 or 16): ");
					int bits;
					scanf("%d", &bits);
					printf("Enter number of channels (1 or 2)");
					int ch;
					scanf("%d", &ch);
					WAVEFORMATEX format;
					format.cbSize = 0;
					format.wBitsPerSample = bits;
					format.nBlockAlign = ch * bits / 8;
					format.nAvgBytesPerSec = ch * bits / 8;
					format.nSamplesPerSec = 8.0;
					format.nChannels = ch;
					format.wFormatTag = WAVE_FORMAT_PCM;
		/*Error appears here*/	MMRESULT result = waveInOpen(0, WAVE_MAPPER, &format, &waveInProc, 0, CALLBACK_FUNCTION | WAVE_MAPPED);
					if(result != MMSYSERR_NOERROR)
					{
						printf("Error!\n");
						getchar();
						exit(1);
					}
				}
                    return TRUE;
				
            }
            break;

        case WM_CLOSE:
            EndDialog(hwndDlg, 0);
            return TRUE;

        /*
         * TODO: Add more messages, when needed.
         */
    }

    return FALSE;
}

void CALLBACK waveInProc(HWAVEIN hwi, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
{
	switch(uMsg)
	{


		case WIM_OPEN:
		{
			recording = TRUE;
			stopped = FALSE;
			break;
		}
		
		case WIM_CLOSE:
		{
			recording = FALSE;
			stopped = TRUE;
		}

			
	}
}


When i try to compile it, it get this:

TypeError in argument 4 of 'waveInOpen', expected 'unsigned long int' but found 'void __stdcall (*) (HWAVEIN, unsigned int, unsigned long int, unsigned long int, unsigned long int)'.
Where is waveInOpen() defined? Where is it declared?
waveInOpen() lives in mmsystem.h

You need to cast your function pointer to a DWORD :-(

This is because that param can be a window handle, and event handle, or a callback function pointer.
Last edited on
@andywestken: Good catch Andy: I have been out of Windows programming for too long!
Topic archived. No new replies allowed.