26 May '13 - 10:22 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Qt (C++) Callback Function Undeclared Identifier Error (C2065)  (Read 1145 times)
AName
Posts: 20


« on: 20 Jun '12 - 19:36 »
Reply with quoteQuote

Hello,

I've been trying to follow the C example for "synth" in Qt. I received this error when trying to pass my CALLBACK function to BASS_StreamCreate:

http://msdn.microsoft.com/en-us/library/ewcf0002%28v=VS.80%29.aspx

In the constructor for a Dialog window in Qt, I set config options on BASS, initialized it, and then used this piece of code:

HSTREAM stream = BASS_StreamCreate(44100, 2, 0, &WriteStream, 0);

In the same code file ("dialog.cpp"), just below the constructor, I wrote a CALLBACK function:

Quote
uint CALLBACK WriteStream(HSTREAM handle, short* buffer, uint length, void* user)
{
    //Stuff
}

These are my includes:

#include "dialog.h"
#include "ui_dialog.h"
#include "bass.h"
#include <QMessageBox>
#include <QtCore>

The actual error I'm receiving is "...\dialog.cpp:30: error: C2065: 'WriteStream' : undeclared identifier" (line 30 is the Bass_StreamCreate call).

I also tried this:

HSTREAM stream = BASS_StreamCreate(44100, 2, 0, (STREAMPROC*)WriteStream, 0);

as it was used in the synth example, and I tried using DWORD in the CALLBACK function just to make sure it wasn't some type of mismatch error (although from my understanding, DWORD and uint are replaceable):

Quote
DWORD CALLBACK WriteStream(HSTREAM handle, short* buffer, DWORD length, void* user)
{
    //Stuff
}

I think it should go without saying, but if I comment out the Bass_StreamCreate call (and the BASS_ChannelPlay call after it, which I did not mention before because it's irrelevant), the code executes without any problems.

I'm new to C++ and Qt, so I'm not surprised to receive an error like this. It seems like the error I'm receiving is telling me that it's having problems "finding" my WriteStream CALLBACK function, but it's right there! :O What's wrong, and how do I fix it?

Thanks,

- Andrew
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #1 on: 21 Jun '12 - 13:35 »
Reply with quoteQuote

Is the "WriteStream" function located before or after the BASS_StreamCreate call in your source file? If it's after, then the compiler won't know about it yet when processing the BASS_StreamCreate call. You can fix that by declaring the function earlier in the source file...

uint CALLBACK WriteStream(HSTREAM handle, short* buffer, uint length, void* user);
Logged
AName
Posts: 20


« Reply #2 on: 22 Jun '12 - 00:22 »
Reply with quoteQuote

Thanks, that worked! I'm surprised that that could happen.

I had to make 3 more changes to get it to run. I'll just post the working code:

uint CALLBACK WriteStream(HSTREAM handle, short* buffer, uint length, void* user)
{
    //Stuff
    handle = handle;
    user = user;
    return length;
}

HSTREAM stream = BASS_StreamCreate(44100, 2, 0, (STREAMPROC*)WriteStream, 0);

Now I am getting an unexpected termination of the program. The exact error is "The program has unexpectedly finished.", with no error generated or line number provided. Obviously I can't use BASS_ErrorGetCode here. I've tried commenting out some code, and I've found that StreamCreate works successfully (stream != 0) and the problem occurs on the next line of code (because the program only terminates unexpectedly when it's uncommented):

BASS_ChannelPlay(stream, false);

It's worth mentioning that I do not even see the form. I've been getting an exit code of 1073741819, although I can't find it in my web searches (even in hex, as I've seen recommended).

Sorry, I wouldn't ask for your help if I hadn't already done research to detect and solve my problems.

Thank you!

- Andrew
Logged
AName
Posts: 20


« Reply #3 on: 26 Jun '12 - 06:49 »
Reply with quoteQuote

I realize that you weren't going to reply, I just want to let you know that I won't be using Qt anyways... I've deemed it as more of a problem causer than a problem solver. Smiley

- Andrew
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #4 on: 26 Jun '12 - 12:59 »
Reply with quoteQuote

Sorry, I missed that you had posted a follow-up question. If the problem is only happening when you call BASS_ChannelPlay, then it may be caused by something in the "WriteStream" function (which BASS_ChannelPlay will call to get some sample data to play). What does that function look like? You could try placing a breakpoint in there, and then step through it in the debugger, to confirm whether it's entering and successfully leaving the function.
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines