Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1448

Executing assembly language functions in VB6 using DispCallFunc.

$
0
0
Yes, I know this has been done to death on these forums but one more couldn't hurt. :bigyello:

This is yet another sample showing how to call function pointers in VB6. In this sample I wrote 3 functions in assembly language, assembled them to x86 machine code and directly execute them from normal byte arrays. This method uses the DispCallFunc API to call them through function pointers.

The 3 assembly demo functions are as follows: One that adds two Longs and returns the result. One that takes an array of Longs, sums them and returns the result. The last one is a sub string function that works like Mid$. These functions were written by me purely for demonstration purposes. I'm far from being an assembly language expert so don't expect them to be top notch, super performant examples of good assembly code.

All the assembly functions observe the standard calling convention.

Additional Credits

The author of this article for showing me how to use DispCallFunc correctly.

The trick

For suggesting the DispCallFunc API which I didn't know about.

Olaf Schmidt

For providing information about a bug I encountered with Variants and the VT_BYREF flag.

Additional Links

The thread where this began. The OP in this thread also demonstrates a method of calling function pointers using CallWindowProc.

A more detailed and robust version of the DispCallFunc method by Olaf Schmidt. His version can also make cdecl calls.

Some additional information on this topic by Olaf Schmidt.
Attached Files

Viewing all articles
Browse latest Browse all 1448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>