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

Go 复制代码
import console; 
//生成 DLL 
import tcc; 
var c = tcc();
c.code = /** 
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#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);
相关推荐
白叔King15 天前
aardio 5分钟多线程开发简单入门
aardio
IssacNew4 个月前
【原创软件】第7期:文件夹生成器V1.0-按照列表批量生成文件夹,简单小巧
aardio·列表·批量生成·记住文件夹·同名文件夹·文件夹
卢光庆4 个月前
aardio —— 今日减bug
aardio
卢光庆8 个月前
aardio - godking.json 【库】测试
aardio
belldeep1 年前
aardio:用 WebView 模仿 mdict 界面
aardio·webview2