Re: Problems calling a function in a DLL

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



shanzer <shanzer@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
typedef DWORD (WINAPI *tfn) (unsigned char *, unsigned int, unsigned
int *);

The typedef defines a poitner to function using __stdcall calling
convention (that's what WINAPI expands to).

extern "C" {
__declspec(dllexport) DWORD GetData(unsigned char *data,
unsigned int dataSize,
unsigned int *dataLen)

The actual function is declared with no explicit calling convention, and
most likely defaults to __cdecl. When the caller and the callee don't
agree on the calling convention, the result is corrupted stack.

Specify WINAPI in both places.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • [RFC] per thread page reservation patch
    ... This patch adds an API to reserve some number of pages for exclusive use ... off calling task_struct. ... +int perthread_pages_reserve(int nrpages, int gfp); ...
    (Linux-Kernel)
  • Re: Mixed stdcall and cdecl code
    ... >> convention. ... I link to a 3rd party static library that apparently uses the ... >> errors from the linker until I changed my project settings from stdcall ... The 3rd party did not explicitly declare a calling convention in ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: [PATCH 3/3] x86: OLPC: speed up device tree creation during boot (v2)
    ... static int bar; ... I wouldn't object to a convention like that, ... Intel Open Source Technology Center ...
    (Linux-Kernel)
  • Re: Languages for embedded
    ... calling constructors of the structure's members. ... If I want to know whether xyz had a constructor, ... On the other hand, if I have a C struct xyz, and the API provides a ... If function ftakes an int by value, it can't modify any int value ...
    (comp.arch.embedded)
  • Re: BUG? atleast >=2.6.19-rc5, x86 chroot on x86_64
    ... Calling VFAT_IOCTL_READDIR_BOTH ... ioctl: Inappropriate ioctl for device ... typedef unsigned int u32; ... int ret, short_only, both; ...
    (Linux-Kernel)