简体   繁体   中英

OpenWatcom / VisualStudio interoperability in re calling conventions

I would like to compile a Photoshop Filter plugin with OpenWatcom. The code already exists and works perfectly with Visual Studio.

The function looks like this:

extern "C" __declspec(export) void PluginMain(short selector, FilterRecordPtr pb, intptr_t *data, short *result);

It works perfectly in Visual C++. Note that there is explicitly no calling convention specified (Adobe does not define any calling convention in their SDK header files).

While it works in VC++, in OpenWatcom this does not work, and it seems like the calling convention is not correct. (I get weird behavior like corrupted stack, even with a "HelloWorld"-function).

At Wikipedia, I have looked at the table with the calling conventions: The table says that if no calling convention is specified, Watcom puts parameters in registers "EAX, EDX, EBX, ECX", stack filled right to left, and callee cleans the stack. But the table does not say what Microsoft compilers do if no calling convention is specified. I do think that Visual Studio uses a different calling convention as default. So I tried to specify __stdcall , __cdecl or __pascal in OpenWatcom, but it didn't help much.

One of my questions is, what exactly is Visual Studio's default calling convention if nothing is specified? What exactly will put into registers, in what direction on the stack, and who cleans the stack? I couldn't find this information anywhere.

If I would know the exact behavior, I might be able to use the "#pragma aux" functionality in OpenWatcom to enforce a custom calling convention?

Or do you know something else I can try to fix the calling convention in OpenWatcom?

(moving from a comment)

The default calling convention in Visual C++ is cdecl , although it can be changed through a command-line switch ( /Gd , /Gr , /Gv , /Gz ) .

Reading around, it seems like Watcom has a similar set of options as well - -ecc should set it to use cdecl by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM