Discussion:
BCB6 dynamic link id3lib.dll ?
(too old to reply)
Jim Davis
2007-05-29 23:17:05 UTC
Permalink
In XP with BCB6 , dynamic linking
3.8.3 VC id3lib.dll ,
modified 2003-03-02 ,
from www.sourceforge ... binaries .

Did implib -a mylib.lib C:\Windows\id3lib.dll .
Coding w/ C covers in <id3.h> .

Tried changing #define(s)
ID3_C_EXPORT & CCONV
in \id3\globals.h (lines 73-76) .

Compile & link OK , but runtime :
ID3Tag_New() & ID3Tag_Link() run , then
ID3Tag_FindFrameWithID()
incorrectly twice returns NULL ,
then crash on corrupted for loop counter .

Any help appreciated .
Ed Mulroy
2007-05-30 00:40:37 UTC
Permalink
My guess is that the header file function prototype is missing a calling
convention. It could be that the functions are WINAPI (or __stdcall which
is the same thing) but the header file does not specify.

With the standard C/C++ calling convention (__cdecl calling convention):
- calling parameters are pushed onto the stack
in right to left order
- upon return from the function the calling code
cleans up the space on the stack that was used
for the calling parameters

With WINAPI/__stdcall calling convention
- calling parameters are pushed onto the stack
in left to right order
- the function cleans up the space on the stack
that was used for the calling parameters

Therefore if the calling convention is wrong and you have 2 or more calling
parameters, they will be in reversed order so the wrong values will be
received by the function. Depending upon which convention is the wrong one
the stack space used will not be cleaned up or the stack will be corrupted
because twice the correct amount will be freed from the stack. Either of
those will corrupt the program. The symptoms you describe are consistent
with what I would expect to happen in this circumstance.

Note that all the functions Windows supplies in DLLs except for wsprintf use
WINAPI/__stdcall calling convention. It is the calling convention commonly
used for functions exported by DLLs.

. Ed
Post by Jim Davis
In XP with BCB6 , dynamic linking
3.8.3 VC id3lib.dll ,
modified 2003-03-02 ,
from www.sourceforge ... binaries .
Did implib -a mylib.lib C:\Windows\id3lib.dll .
Coding w/ C covers in <id3.h> .
Tried changing #define(s)
ID3_C_EXPORT & CCONV
in \id3\globals.h (lines 73-76) .
ID3Tag_New() & ID3Tag_Link() run , then
ID3Tag_FindFrameWithID()
incorrectly twice returns NULL ,
then crash on corrupted for loop counter .
Any help appreciated .
Loading...