QT Call DLL Dynamic library interface function program collapse

Source: Internet
Author: User

Working with QT Development, invoking an external dynamic library. dll, which is always run after calling an interface function and then collapsing, prompting for a segment error. One-step debugging always has a variable was accidentally changed, took two days to solve with the help of colleagues.

Here's how: adding _stdcall when defining an interface function pointer, its flaw is that it can only run on Windows platforms, not across platforms

typedef _stdcall  Int (*func_wtdev_axiscount) (int vehicleid);
Problem solving. Shame Ah, the road of learning is long.
__stdcallThe function that is modified by this keyword, whose arguments are passed from right to left through the stack (the front part of __fastcall is transmitted by Ecx,edx), the function call is cleaned up by the callee before it is returned.

Not all languages support _cdcel call rules, but all support _sdtcall call rules, if you use VC made a DLL, exported some functions, if you want this DLL can be called by other languages, VB. Dephi. PB.. You declare his calling convention as __stdcallwindows API are _stdcall call rules,

The function calling convention determines how a program implements a function call and how arguments are passed. In a single language program, the calling convention is almost always correct, because there is always a default convention for all modules and the header file is responsible for the consistency between the invocation and the callee. In a mixed language program, different languages cannot share the same header file. Errors resulting from the calling convention cannot be found at compile time until the program is implemented at runtime (run-time) to implement function calls and immediately causes the application to crash.   Keywords                                                        Maintainer of    stack           parameter passing   __cdecl                                                                        Caller parameter Reverse orderinto the stack (right->  left)   __stdcall                                                                 the callee parameter is reversed into the stack (right->  left)   __fastcall                                                                 callee parameter First deposit register, then stack   thiscall (not keyword)        The callee parameter is in the stack, the this pointer is stored ecx  in C + +, you can specify the calling convention with the keyword __stdcall when the function is declared or defined. __stdcall calling conventions are often used in Windows programs or API functions. In GUI programs, PASCAL, WINAPI, and CallbaCK is defined as __stdcall. The default calling convention for the C language is __cdecl.   __stdcall The name modifier is to put the name symbol before the underscore (_), and then add "@" and the function parameter bytes (required stack space)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.