WinSock program error

Pages: 12
It does matter if the functions are in the same file or not, what's in the header file(s) if the functions are in different files and so on. That's why I asked you to post the code that demonstrates the error. I think you're posting extracts that seem reasonable rather than the actual code.

Without seeing your actual code, I can't really add anything. Clearly you have a something called MyStreamWriter that's visible in one function and not another. I don't know if they're the same thing, two local things with the same name, and so on.
Hi kbw,

Below is the exact code.


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
HSTREAM BASSDEF(BASS_StreamCreate)(DWORD freq, DWORD chans, DWORD flags, STREAMPROC *proc, void *user);//Function of bass.dll

DWORD CALLBACK MyStreamWriter(HSTREAM handle, void *buf, DWORD len, void *user)
{

//

}

unsigned int __stdcall read_udp_data(void* data)
{

BASS_StreamCreate( Decoder.Samplerate(), Decoder.Channels(),BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE, &MyStreamWriter, 0);
}

int main( int argc, char *argv[] )
{

_beginthreadex( NULL,
                                          0,
                                          read_udp_data,
                                          NULL,
                                          0, 
                                          &uiThreadID0 );
return 0;
}
You said it works when called in main.

I don't see it being called in main.
Above code shown is when the function is called from the thread. This gives a building error.


If I called BASS_StreamCreate( Decoder.Samplerate(), Decoder.Channels(),BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE, &MyStreamWriter, 0);

function inside main() it works fine.

e.g.
1
2
3
4
5
6
7
8
9
10
11
12
int main(){

_beginthreadex( NULL,
                                          0,
                                          read_udp_data,
                                          NULL,
                                          0, 
                                          &uiThreadID0 );
return 0;

BASS_StreamCreate( Decoder.Samplerate(), Decoder.Channels(),BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE, &MyStreamWriter, 0);
}


But when I called from the thread it gives an error see below code

1
2
3
4
5
6
unsigned int __stdcall read_udp_data(void* data)
{

BASS_StreamCreate( Decoder.Samplerate(), Decoder.Channels(),BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE, &MyStreamWriter, 0);

}
Hi Kbw,

Still couldn't find a solution... Any suggestions?

erhct
You're using identifiers without showing the declarations. I can't really comment any further as I can't see the declarations for the identifiers you're using and the files they're in.

In short, if you don't post all the relevant code, I can't help.
Hi Kbw,

The full code is attached. When I called the BASS_StreamCreate() function from the thread (i.e. read_udp_data()) it says &MyStreamWriter is a undeclared identifier.

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
HSTREAM BASSDEF(BASS_StreamCreate)(DWORD freq, DWORD chans, DWORD flags, STREAMPROC *proc, void *user);//This Function id defined in bass.dll


unsigned int __stdcall read_udp_data(void* data)//thread function
{

         BASS_StreamCreate( Decoder.Samplerate(), Decoder.Channels(),BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE, &MyStreamWriter, 0);

}

DWORD CALLBACK MyStreamWriter(HSTREAM handle, void *buf, DWORD len, void *user)
{

//

}

DecoderC Decoder = DecoderC(input_buffer, output_buffer);//Derived based on a separate class


int main( int argc, char *argv[] )
{

	DWORD   dwExitCode0;
	DWORD	dwEvent;
    	HANDLE   hthDecoder[2];
    	unsigned  uiThreadID0;
	

        hthDecoder[0] = (HANDLE)_beginthreadex( NULL,
                                          0,
                                          read_udp_data,
                                          NULL,
                                          0, 
                                          &uiThreadID0 );

       if ( hthDecoder[0] == 0 )
             printf("Failed to create decoder thread\n");

       WaitForSingleObject( hthDecoder[0], INFINITE );

       return 0;
}
Last edited on
Either make a prototype for MyStreamWriter and place it at the top of the file (or in a header file) or move it above read_udp_data in the file.

At the point the compiler parses read_upd_data(), it hasn't seen a declaration for MyStreamWriter, but it will by the time it gets to main().
Topic archived. No new replies allowed.
Pages: 12