Re: Mixed stdcall and cdecl code

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Chuck Walbourn [MSFT] (chuckw_at_online.microsoft.com)
Date: 10/20/04


Date: Wed, 20 Oct 2004 16:15:00 -0700


>> I'm writing a DirectShow capture filter, which requires the stdcall
>> calling
>> convention. I link to a 3rd party static library that apparently uses the
>> cdecl calling convention, because I was getting "unresolved external
>> symbol"
>> errors from the linker until I changed my project settings from stdcall
>> to
>> cdecl. The 3rd party did not explicitly declare a calling convention in
>> their headers. All of my COM interface implementations are declared with
>> STDMETHODIMP, so they use the stdcall convention, but simple overrides of
>> methods defined in the DirectShow BaseClasses library do not explicitly
>> declare the calling convention. I do not get any linker errors after
>> changing the project calling convention from stdcall to cdecl. Am I safe
>> to
>> proceed, or am I likely to have stack problems unless I explicitly
>> declare
>> all of my methods as stdcall? Is the runtime able to resolve virtual
>> functions if my project default is cdecl but the base class (from
>> BaseClasses lib) is stdcall?

> THere may be some pragma or define you can set before including the
> library
> header that indicates it is a stdcall. Or whatever.
>

The only way to resolve this is to edit the 3rd party header files and
explicitly list the calling convention for each routine. There isn't a
syntax for doing this as a 'wrapper' around the header. You should also
inform the 3rd party library provider that they should fix this in their
version of the headers. It is 'bad form' to use a different calling
convention and not mark the routines.

-- 
Chuck Walbourn
SDE, Windows Gaming & Graphics
This posting is provided "AS IS" with no warranties, and confers no rights. 


Relevant Pages

  • Re: calling convention stdcalll and cdecl call
    ... According to my understanding of what a calling convention ... But the point is that stdcall could easily have used this ... could support variadic functions (but it does appear to me that a few ... It could be argued that any modification to existing calling ...
    (microsoft.public.vc.language)
  • Re: _BeginThread & the Ex variant
    ... BeginThreadEx DEMANDS a thread function to specify __stdcall calling ... Because a function that calls another function must know what calling ... convention the function it is calling uses. ...
    (comp.programming.threads)
  • Re: Multi VMR9 in VB6
    ... i take this message "Bad DLL calling convention" ... supports __stdcall, which is the native Windows calling ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: Threads on class,
    ... It does work on x86 due to the use of __stdcall which changes the calling ... convention from the default __thiscall. ...
    (microsoft.public.vc.language)
  • Re: Threads on class,
    ... It does work on x86 due to the use of __stdcall which changes the calling ... convention from the default __thiscall. ...
    (microsoft.public.windowsce.embedded.vc)