aardio - 调用C编写的dll时的不同参数类型处理方法

import console; 
//生成 DLL 
import tcc; 
var c = tcc();
c.code = /** 
#include 
#include 
#include 

#ifdef __cplusplus
#define EXTERN_C extern "C" __declspec(dllexport)
#else
#define EXTERN_C __declspec(dllexport)
#endif

#define _CDECL __cdecl
#define _STDCALL __stdcall

struct testStruct 
{
    int a;
    int b;
    float c;
    double d;
    long long f;
    short g;
};

EXTERN_C   void _CDECL test_one(struct testStruct p)
{
    printf("%d\n", p.a);
    printf("%d\n", p.b);
    printf("%f\n", p.c);
    printf("%lf\n", p.d);
    printf("%lld\n", p.f);
    printf("%d\n", p.g);
}

EXTERN_C   void _CDECL test_two(int a ,int b,float c,double d,long long f,short g)
{
    printf("%d\n", a);
    printf("%d\n", b);
    printf("%f\n", c);
    printf("%lf\n", d);
    printf("%lld\n", f);
    printf("%d\n", g);
}

EXTERN_C void _CDECL test_three(struct testStruct *p)
{
    printf("%d\n", p->a);
    printf("%d\n", p->b);
    printf("%f\n", p->c);
    printf("%lf\n", p->d);
    printf("%lld\n", p->f);
    printf("%d\n", p->g);
    p->g = 65;
}

int main()
{
    return 0;
}
**/
c.output( "d:/bin.dll" ) //编译C源码,生成DLL
c.close(); //收工

console.open()
var dll = raw.loadDll("d:/bin.dll",,"cdecl");
console.log("第一种方式:")
dll.test_one(100,200,raw.float(33.3),0,raw.double(99.2),raw.long(30000000),raw.word(97));

console.log('\n第二种方式:')
dll.test_two(100,200,raw.float(33.3),raw.double(99.2),raw.long(30000000),raw.word(97));

console.log('\n第三种方式:')
var testStruct = {
    int a=100;
    int b=200;
    float c=33.3;
    double d=99.2;
    long f=30000000;
    word g=97;
};
dll.test_three(testStruct);

console.log('\n第三种方式运行后成员g的值被修改:')
console.dump(testStruct)

console.pause(true);

aardio - 调用C编写的dll时的不同参数类型处理方法_第1张图片

你可能感兴趣的:(aardio,aardio)