Ok, I figured it out !!!

This was actually a calling convention problem. Our software is built
using __fastcall as default convention, and the function in sqlite3.h
is declared as:

int __cdecl sqlite3_create_function(
  sqlite3 *,
  const char *zFunctionName,
  int nArg,
  int eTextRep,
  void*,
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  void (*xFinal)(sqlite3_context*)
);

So the compiler considered the pointers xFunc, xStep and xFinal as
being __fastcall. That's why I got this error when declaring my
callback as __cdecl.

As a solution, I modified the delclaration like this:

int __cdecl sqlite3_create_function(
  sqlite3 *,
  const char *zFunctionName,
  int nArg,
  int eTextRep,
  void*,
  void (__cdecl *xFunc)(sqlite3_context*,int,sqlite3_value**),
  void (__cdecl *xStep)(sqlite3_context*,int,sqlite3_value**),
  void (__cdecl *xFinal)(sqlite3_context*)
);

to force the pointers to be __cdecl. No I can (I even have to) declare
my callback as __cdecl and the parameters are correct again.

Now is there any reason for the declaration to be like this, or do you
think I should submit the fix somewhere ?

Thanks for your clues

Guillaume


On Fri, Dec 19, 2008 at 9:06 AM, Guillaume Schub <grandmo...@gmail.com> wrote:
> Hello,
>
> Looks like my last reply wasn't received....
>
> So I tried with a static function out of a class without more success.
>
> Then I tried changing the calling convention to __stdcall and even
> __cdecl, but I got a compilation error asking for a __fastcall
> function, so no more success here (I'm using Visual Studio on Windows
> XP).
>
> I also thought about a module issue (pointer to callback was not on
> the same dll as sqlite3_create_function) but again no success.
>
>
>
> On Wed, Dec 17, 2008 at 7:17 PM, Igor Tandetnik <itandet...@mvps.org> wrote:
>> Guillaume Schub <grandmo...@gmail.com>
>> wrote:
>>> sqlite3_create_function(m_pDB, "ScorePosition", "ScorePosition", 8,
>>> SQLITE_ANY, NULL, &ScorePosition, NULL, NULL);
>>>
>>> class MyClass
>>> {
>>> ...
>>> static void ScorePosition(sqlite3_context *pContext,int argc,
>>> sqlite3_value** argv);
>>> ...
>>> };
>>>
>>> No the problem is that the callback is called, but pContext is always
>>> NULL, argc a fancy value, and argv always the same value (like
>>> 0x0012f2d4)
>>
>> Sounds like a calling convention mismatch. What compiler are you using,
>> on what OS?
>>
>> Igor Tandetnik
>>
>>
>>
>> _______________________________________________
>> sqlite-users mailing list
>> sqlite-users@sqlite.org
>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>>
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to