PDA

View Full Version : BCB compatibiility


rebellious
22nd December 2004, 06:20
Hi All, I am trying to compile a simple filter for AVISynth 2.5

I am using BCB 4

everything seems to go fine up to the point my GetFrame function is called.

it crashes and MediaPlayer throws up an "unknown error" message

When I investigate the "this" pointer it turns out it is invalid, pointing to outer space somewhere, rather than to the object I actually created.

So I redid everything this time using Bens "Invert" Sample

same problem.

I have tried using different data alignment schemes etc.. but cannot get it to work. I use __stdcall and __cdecl where required and get no compile time errors, though I noticed __stdcall is not used consistantly in avisynth.h it is assumed in some places.

Either the 'this' pointer is being passed differently from MSV C++ to BCB C++ or some other error is occuring (which alludes me at present).

It was my belief that MS and Borland were binary compatible, which means something else is awry.

I can't recompile AVISynth because BCB seems to lack some of the asm opcodes, and I can't get access to an MS Compiler

I was hoping some one would point me in the right direction.

Leak
22nd December 2004, 07:51
Originally posted by rebellious
It was my belief that MS and Borland were binary compatible, which means something else is awry.

Well, they probably are as far as C is concerned, but I wouldn't bet on their output for C++ to be totally compatible - C++ binary compatibility has always been a mess.

Check if you can get your compiler to output an ASM file for your code and have a look how the this pointer is passed; AFAIK MSVC is using eax for it. If BCB uses a different register or the stack you need to find a way to change that...

stickboy
22nd December 2004, 09:12
Why not take the easy route and use Microsoft's C++ compiler?

BlindWanderer
22nd December 2004, 10:27
microsoft gives away the compiler, don't have the link on hand.

rebellious
23rd December 2004, 01:37
I was hoping to do some development while I was away on hols. unfortunately I am limited to a dialup and as little time online as possible to keep the mother in laws line free. :(

I found the problem...

It is due to Microsoft and Borland using different calling conventions.

microsoft passes the 'this' pointer as the last item on the stack
borland passes it as the second last item on the stack. the last being the stack pointer. Microsoft passes this as the second last item.

In short the two parameters are swapped.

Leak
Borland uses ecx to pass the this pointer (for compatibility?) but I think it is ignored in borlands code, Microsofts msdn docs says it uses ecx by default ( __declspec(thiscall) ), but it doesnt it uses eax as you have pointed out (at least with __stdcall)

We wont argue about who's right and whos wrong 'cause its just semantics, unfortunately it means the two are incompatible.


So I guess development pauses until I get back to the office and can use Murcky$ofts compiler.

Not too worry I have many more projects that need attention. :(

Thanks for the response guys.