VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Call CDECL DLL's - impossible?

by Paul Caton (from psc cd) (1 Submission)
Category: Windows API Call/Explanation
Compatability: VB 6.0
Difficulty: Intermediate
Originally Published: Mon 4th June 2018
Date Added: Tue 9th February 2021
Rating: (1 Votes)

Updated November 2007, fix a DEP problem. CDECL DLL functions cannot be called from Visual Basic... or so they'll tell you... such dll's use a incompatible technique for parameter stack cleanup. The included class uses VB+ASM to slay the "impossible" cdecl call dragon, even allowing 'C' style variable length/type parameter lists and the use of VB bas module functions as cdecl callback routines. The convention used with a cdecl function is that the caller cleans the stack on return; the stdcall convention is that the called function cleans the stack at function end. The advantage of stdcall is reduced program size, 6 calls to a function, one bit of cleanup code. The advantage of cdecl is that variable length/type parameter lists are "safe" because the caller, he who pushed the parameters onto the stack, cleans the stack... he knows exactly how many parameters he pushed and thus knows the required adjustment on function return. Years ago I worked on a team that lost a project because of our inability to speedily resolve this issue for a third-party dll - So, perhaps not the sexiest submission of the week, however, it might just save your a*s someday. The included sample demonstrates variable length/type parameter lists and callbacks routines, focusing on the std 'C' library qsort (quicksort) function.

Rate Call CDECL DLL's - impossible?

Download Call CDECL DLL's - impossible?

Download Call CDECL DLL's - impossible? (23 KB)

Call CDECL DLL's - impossible? Comments

No comments have been posted about Call CDECL DLL's - impossible?. Why not be the first to post a comment about Call CDECL DLL's - impossible?.

Post your comment

Subject:
Message:
0/1000 characters