Author Topic: Use 'DownloadProc' callback function in Qt problem  (Read 306 times)

purenoise

  • Posts: 56
Hi,

 please help figure it out how to
 apply DownloadProc with
 BASS_StreamCreateURL in my Qt app.

I did:
 
Code: [Select]
void CALLBACK downProc(const void *buffer, DWORD length, void *user);
Code: [Select]
BASS_StreamCreateURL( url.c_str(), 0, 0,
                                 (DOWNLOADPROC *)& downProc, 0);

And:
 - getting crash when it comes to call on downProc

Note:

 - app works without callback imprementation,
   but i need this to work with callback func.

Thanks.

saga

  • Posts: 2262
Re: Use 'DownloadProc' callback function in Qt problem
« Reply #1 on: 12 Feb '18 - 12:50 »
First off, don't cast your function pointer forcefully to type DOWNLOADPROC. If omitting the cast gives you an error, then you absolutely must not ignore this error because it means the function signature is wrong. Is your downProc function maybe part of a C++ class? If so, it must be static, because otherwise it will have an implicit "this" parameter:
Code: [Select]
class Foo
{
...
static void CALLBACK downProc(const void *buffer, DWORD length, void *user);
...
void Bar()
{
  BASS_StreamCreateURL( url.c_str(), 0, 0, downProc, 0);
}
}
If you need access to the class instance ("this"), you can pass it as a user parameter to your callback function.

purenoise

  • Posts: 56
Re: Use 'DownloadProc' callback function in Qt problem
« Reply #2 on: 12 Feb '18 - 12:59 »
Still no go:

error: invalid conversion from 'int (__attribute__((__stdcall__)) *)(const void*, DWORD, void*) {aka int (__attribute__((__stdcall__)) *)(const void*, long unsigned int, void*)}' to 'void (__attribute__((__stdcall__)) *)(const void*, DWORD, void*) {aka void (__attribute__((__stdcall__)) *)(const void*, long unsigned int, void*)}' [-fpermissive]
                                  downProc, 0); }
                                             ^

saga

  • Posts: 2262
Re: Use 'DownloadProc' callback function in Qt problem
« Reply #3 on: 12 Feb '18 - 13:35 »
Yes, it tells you that your return type "int" is not the expected return type "void". Did you change the return type of the callback function?

purenoise

  • Posts: 56
Re: Use 'DownloadProc' callback function in Qt problem
« Reply #4 on: 12 Feb '18 - 13:42 »
Still getting build errors,
take a look, what i'm doing wrong please.

Code: [Select]
static void CALLBACK media::
downProc(const void *buffer, DWORD length, void *user){

    qDebug()<< "downProc";
}
Code: [Select]
    return BASS_StreamCreateURL( url.c_str(), 0, 0,
                                 //(DOWNLOADPROC*)&
                                 downProc, 0);

Code: [Select]
error: cannot declare member function 'static void media::downProc(const void*, DWORD, void*)' to have static linkage [-fpermissive]
 downProc(const void *buffer, DWORD length, void *user){
                                                      ^

saga

  • Posts: 2262
Re: Use 'DownloadProc' callback function in Qt problem
« Reply #5 on: 12 Feb '18 - 14:02 »
You need to specify "static" when declaring the function, not when implementing it. For example:
Code: [Select]
class media
{
// declaration
static void CALLBACK downProc(const void *buffer, DWORD length, void *user);
}

// implementation
void CALLBACK media::downProc(const void *buffer, DWORD length, void *user)
{
    qDebug()<< "downProc";
}

Searching for the error message you got will tell you why: https://stackoverflow.com/questions/31305717/member-function-with-static-linkage

purenoise

  • Posts: 56
Re: Use 'DownloadProc' callback function in Qt problem
« Reply #6 on: 12 Feb '18 - 14:10 »
Big thank you mad,
IT WORKS !

purenoise

  • Posts: 56
Re: Use 'DownloadProc' callback function in Qt problem
« Reply #7 on: 12 Feb '18 - 14:50 »
All works.

in media.h

Code: [Select]
static FILE * downloadFile;
Code: [Select]
static void CALLBACK downProc(const void *buffer, DWORD length, void *user);
in media.cpp

Code: [Select]
#include "media.h"

FILE * media:: downloadFile = NULL;

Code: [Select]
void CALLBACK media::
downProc(const void *buffer, DWORD length, void *user){

Code: [Select]
            BASS_StreamCreateURL( url.c_str(), 0, 0,
                                 downProc, 0);
« Last Edit: 12 Feb '18 - 19:21 by purenoise »