Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to declare assembly function with dynamic arguments in C++ like in C

I have some C code and I want to port it to c++, the problem is that in C++ I can’t use an assembly function due to it’s dynamic use

C version

extern asmFunc(); // C function prototype version

//actual use example
asmFunc(var1,ptr2,HANDLE); 
asmFunc(ptr4,var2,NULL,eg ...); //everything works

C++ version

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

extern "C" VOID asmFunc(); // C++ function prototype version

//actual use example
asmFunc(var1,ptr2,HANDLE); // E0140 too many arguments in function call
asmFunc(ptr4,var2,NULL,eg ...); // E0140 too many arguments in function call

The Assembly function is declared in a separate asm file and it uses direct syscalls from ntdll.dll’s functions, that’s why it requires dynamic arguments

How to make it work?

>Solution :

Use ... in the argument list to specify the function is a variadic function taking unspecified arguments, eg:

extern "C" VOID asmFunc(...); // C++ function prototype version

//actual use example
asmFUNC(var1,ptr2,HANDLE);
asmFUNC(ptr4,var2,NULL,eg);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading