当前位置:   article > 正文

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

aardio - 调用C编写的dll时的不同参数类型处理方法
  1. import console;
  2. //生成 DLL
  3. import tcc;
  4. var c = tcc();
  5. c.code = /**
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <stdbool.h>
  9. #ifdef __cplusplus
  10. #define EXTERN_C extern "C" __declspec(dllexport)
  11. #else
  12. #define EXTERN_C __declspec(dllexport)
  13. #endif
  14. #define _CDECL __cdecl
  15. #define _STDCALL __stdcall
  16. struct testStruct
  17. {
  18. int a;
  19. int b;
  20. float c;
  21. double d;
  22. long long f;
  23. short g;
  24. };
  25. EXTERN_C void _CDECL test_one(struct testStruct p)
  26. {
  27. printf("%d\n", p.a);
  28. printf("%d\n", p.b);
  29. printf("%f\n", p.c);
  30. printf("%lf\n", p.d);
  31. printf("%lld\n", p.f);
  32. printf("%d\n", p.g);
  33. }
  34. EXTERN_C void _CDECL test_two(int a ,int b,float c,double d,long long f,short g)
  35. {
  36. printf("%d\n", a);
  37. printf("%d\n", b);
  38. printf("%f\n", c);
  39. printf("%lf\n", d);
  40. printf("%lld\n", f);
  41. printf("%d\n", g);
  42. }
  43. EXTERN_C void _CDECL test_three(struct testStruct *p)
  44. {
  45. printf("%d\n", p->a);
  46. printf("%d\n", p->b);
  47. printf("%f\n", p->c);
  48. printf("%lf\n", p->d);
  49. printf("%lld\n", p->f);
  50. printf("%d\n", p->g);
  51. p->g = 65;
  52. }
  53. int main()
  54. {
  55. return 0;
  56. }
  57. **/
  58. c.output( "d:/bin.dll" ) //编译C源码,生成DLL
  59. c.close(); //收工
  60. console.open()
  61. var dll = raw.loadDll("d:/bin.dll",,"cdecl");
  62. console.log("第一种方式:")
  63. dll.test_one(100,200,raw.float(33.3),0,raw.double(99.2),raw.long(30000000),raw.word(97));
  64. console.log('\n第二种方式:')
  65. dll.test_two(100,200,raw.float(33.3),raw.double(99.2),raw.long(30000000),raw.word(97));
  66. console.log('\n第三种方式:')
  67. var testStruct = {
  68. int a=100;
  69. int b=200;
  70. float c=33.3;
  71. double d=99.2;
  72. long f=30000000;
  73. word g=97;
  74. };
  75. dll.test_three(testStruct);
  76. console.log('\n第三种方式运行后成员g的值被修改:')
  77. console.dump(testStruct)
  78. console.pause(true);

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/50928
推荐阅读
相关标签
  

闽ICP备14008679号