how call a c function with stdcall?

mzfhhhh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 24 08:20:12 PDT 2015


for example:use vc compile on x86
func.c:
__declspec(dllexport) int _stdcall sub(int a,int b)
{
	return a-b;
}

func.def:

LIBRARY
EXPORTS
sub

-----------------
i use "implib.exe" to create a omf format lib.
----------------
D code:
import std.exception;

//this is a cdecl call
extern(C) int sub(int a,int b);

void main()
{
     auto c1 = sub(2,1);

     //when this line run,the c1 value is broken
     auto c2 = enforceEx!Exception(sub(1,2));
}
------------------
my question is how write D code to call the c function


More information about the Digitalmars-d-learn mailing list