main.cpp 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. #include <inttypes.h>
  2. #include <stdio.h>
  3. namespace Tests
  4. {
  5. struct Interop
  6. {
  7. struct StructA
  8. {
  9. int mA;
  10. static int sVal;
  11. int MethodA0(int arg0)
  12. {
  13. return arg0 + mA * 100;
  14. }
  15. StructA MethodA1(StructA other, int arg0)
  16. {
  17. StructA ret;
  18. ret.mA = mA + other.mA + arg0;
  19. return ret;
  20. }
  21. const float& MethodA2(const float& val)
  22. {
  23. return val;
  24. }
  25. const float& MethodA3(const float& val)
  26. {
  27. return val;
  28. }
  29. };
  30. struct StructB
  31. {
  32. int mA;
  33. char mB;
  34. int MethodB0(int arg0)
  35. {
  36. return arg0 + mA * 100 + mB * 10000;
  37. }
  38. StructB MethodB1(StructB other, int arg0)
  39. {
  40. StructB ret;
  41. ret.mA = mA + other.mA + arg0;
  42. ret.mB = mB + other.mB;
  43. return ret;
  44. }
  45. };
  46. struct StructC
  47. {
  48. char mA;
  49. int mB;
  50. int MethodC0(int arg0)
  51. {
  52. return arg0 + mA * 100 + mB * 10000;
  53. }
  54. StructC MethodC1(StructC other, int arg0)
  55. {
  56. StructC ret;
  57. ret.mA = mA + other.mA + arg0;
  58. ret.mB = mB + other.mB;
  59. return ret;
  60. }
  61. };
  62. struct StructD
  63. {
  64. int mA;
  65. int mB;
  66. int MethodD0(int arg0)
  67. {
  68. return arg0 + mA * 100 + mB * 10000;
  69. }
  70. StructD MethodD1(StructD other, int arg0)
  71. {
  72. StructD ret;
  73. ret.mA = mA + other.mA + arg0;
  74. ret.mB = mB + other.mB;
  75. return ret;
  76. }
  77. };
  78. struct StructE
  79. {
  80. int mA;
  81. int mB;
  82. int mC;
  83. int MethodE0(int arg0)
  84. {
  85. return arg0 + mA * 100 + mC * 10000;
  86. }
  87. StructE MethodE1(StructE other, int arg0)
  88. {
  89. StructE ret;
  90. ret.mA = mA + other.mA + arg0;
  91. ret.mB = mB + other.mB;
  92. return ret;
  93. }
  94. };
  95. struct StructF
  96. {
  97. char mA;
  98. char mB;
  99. char mC;
  100. int MethodF0(int arg0)
  101. {
  102. return arg0 + mA * 100 + mC * 10000;
  103. }
  104. StructF MethodF1(StructF other, int arg0)
  105. {
  106. StructF ret;
  107. ret.mA = mA + other.mA + arg0;
  108. ret.mB = mB + other.mB;
  109. return ret;
  110. }
  111. };
  112. struct StructG
  113. {
  114. char mA;
  115. char mB;
  116. char mC;
  117. char mD;
  118. int MethodG0(int arg0)
  119. {
  120. return arg0 + mA * 100 + mC * 10000;
  121. }
  122. StructG MethodG1(StructG other, int arg0)
  123. {
  124. StructG ret;
  125. ret.mA = mA + other.mA + arg0;
  126. ret.mB = mB + other.mB;
  127. return ret;
  128. }
  129. };
  130. struct StructH
  131. {
  132. int64_t mA;
  133. int64_t mB;
  134. int64_t mC;
  135. int MethodH0(int arg0)
  136. {
  137. return arg0 + (int)mA * 100 + (int)mC * 10000;
  138. }
  139. StructH MethodH1(StructH other, int arg0)
  140. {
  141. StructH ret;
  142. ret.mA = mA + other.mA + arg0;
  143. ret.mB = mB + other.mB;
  144. return ret;
  145. }
  146. };
  147. struct StructI
  148. {
  149. char mA;
  150. char mB;
  151. char mC;
  152. char mD;
  153. char mE;
  154. int MethodI0(int arg0)
  155. {
  156. return arg0 + (int)mA * 100 + (int)mC * 10000;
  157. }
  158. StructI MethodI1(StructI other, int arg0)
  159. {
  160. StructI ret;
  161. ret.mA = mA + other.mA + arg0;
  162. ret.mB = mB + other.mB;
  163. return ret;
  164. }
  165. };
  166. struct StructJ
  167. {
  168. char* mPtr;
  169. intptr_t mLength;
  170. int MethodJ0(int arg0)
  171. {
  172. return arg0 + (int)mLength * 100;
  173. }
  174. StructJ MethodJ1(StructJ other, int arg0)
  175. {
  176. StructJ ret;
  177. ret.mPtr = other.mPtr;
  178. ret.mLength = other.mLength + arg0;
  179. return ret;
  180. }
  181. };
  182. struct StructK
  183. {
  184. float mX;
  185. float mY;
  186. };
  187. struct StructL
  188. {
  189. float mX;
  190. float mY;
  191. float mZ;
  192. };
  193. struct StructM
  194. {
  195. float mX;
  196. float mY;
  197. float mZ;
  198. float mW;
  199. };
  200. struct StructN
  201. {
  202. float mX;
  203. float mY;
  204. float mZ;
  205. float mW;
  206. float mU;
  207. };
  208. struct StructO
  209. {
  210. float mX;
  211. int mY;
  212. };
  213. struct StructP
  214. {
  215. float mX;
  216. float mY;
  217. int mZ;
  218. };
  219. struct StructQ
  220. {
  221. float mX;
  222. float mY;
  223. int mZ;
  224. int mW;
  225. };
  226. struct StructR
  227. {
  228. double mX;
  229. double mY;
  230. };
  231. struct StructS
  232. {
  233. float mX;
  234. double mY;
  235. };
  236. struct StructT
  237. {
  238. double mX;
  239. double mY;
  240. double mZ;
  241. };
  242. struct StructU
  243. {
  244. StructK mK;
  245. };
  246. struct StructV
  247. {
  248. int64_t mX;
  249. short mY;
  250. };
  251. struct StructW
  252. {
  253. float mX;
  254. };
  255. struct StructX
  256. {
  257. int mA;
  258. int mB;
  259. char* mC;
  260. };
  261. };
  262. int Interop::StructA::sVal = 1234;
  263. }
  264. using namespace Tests;
  265. extern "C" int Func0(int a, int b)
  266. {
  267. return a + b * 100;
  268. }
  269. extern "C" int Func0K(int a, Interop::StructK b)
  270. {
  271. //printf("Func0K: %d %f %f\n", a, b.mX, b.mY);
  272. return a + (int)b.mX * 100 + (int)b.mY * 10000;
  273. }
  274. extern "C" int Func0L(int a, Interop::StructL b)
  275. {
  276. return a + (int)b.mX * 100 + (int)b.mY * 10000;
  277. }
  278. extern "C" int Func0M(int a, Interop::StructM b)
  279. {
  280. return a + (int)b.mX * 100 + (int)b.mY * 10000;
  281. }
  282. extern "C" int Func0N(int a, Interop::StructN b)
  283. {
  284. return a + (int)b.mX * 100 + (int)b.mY * 10000;
  285. }
  286. extern "C" int Func0O(int a, Interop::StructO b)
  287. {
  288. return a + (int)b.mX * 100 + (int)b.mY * 10000;
  289. }
  290. extern "C" int Func0P(int a, Interop::StructP b)
  291. {
  292. return a + (int)b.mX * 100 + (int)b.mY * 10000;
  293. }
  294. extern "C" int Func0Q(int a, Interop::StructQ b)
  295. {
  296. return a + (int)b.mX * 100 + (int)b.mY * 10000;
  297. }
  298. extern "C" int Func0R(int a, Interop::StructR b)
  299. {
  300. return a + (int)b.mX * 100 + (int)b.mY * 10000;
  301. }
  302. extern "C" int Func0S(int a, Interop::StructS b)
  303. {
  304. return a + (int)b.mX * 100 + (int)b.mY * 10000;
  305. }
  306. extern "C" int Func0T(int a, Interop::StructT b)
  307. {
  308. return a + (int)b.mX * 100 + (int)b.mY * 10000;
  309. }
  310. extern "C" int Func0U(int a, Interop::StructU b)
  311. {
  312. return a + (int)b.mK.mX * 100 + (int)b.mK.mY * 10000;
  313. }
  314. extern "C" int Func0V(int a, Interop::StructV b)
  315. {
  316. return a + (int)b.mX * 100 + (int)b.mY * 10000;
  317. }
  318. extern "C" int Func0W(int a, Interop::StructW b)
  319. {
  320. return a + (int)b.mX * 100;
  321. }
  322. extern "C" int Func0KM(Interop::StructK a, Interop::StructM b, Interop::StructK c)
  323. {
  324. return (int)a.mX + (int)b.mX * 100 + (int)c.mX * 1000;
  325. }
  326. //////////////////////////////////////////////////////////////////////////
  327. extern "C" int Func1A(Interop::StructA arg0, Interop::StructA arg1, int arg2)
  328. {
  329. return arg0.mA + arg1.mA * 100 + arg2 * 10000;
  330. }
  331. extern "C" int Func1B(Interop::StructB arg0, Interop::StructB arg1, int arg2)
  332. {
  333. return arg0.mA + arg1.mA * 100 + arg2 * 10000;
  334. }
  335. extern "C" int Func1C(Interop::StructC arg0, Interop::StructC arg1, int arg2)
  336. {
  337. return arg0.mA + arg1.mA * 100 + arg2 * 10000;
  338. }
  339. extern "C" int Func1D(Interop::StructD arg0, Interop::StructD arg1, int arg2)
  340. {
  341. return arg0.mA + arg1.mA * 100 + arg2 * 10000;
  342. }
  343. extern "C" int Func1E(Interop::StructE arg0, Interop::StructE arg1, int arg2)
  344. {
  345. return arg0.mA + arg1.mA * 100 + arg2 * 10000;
  346. }
  347. extern "C" int Func1F(Interop::StructF arg0, Interop::StructF arg1, int arg2)
  348. {
  349. return arg0.mA + arg1.mA * 100 + arg2 * 10000;
  350. }
  351. extern "C" int Func1G(Interop::StructG arg0, Interop::StructG arg1, int arg2)
  352. {
  353. return arg0.mA + arg1.mA * 100 + arg2 * 10000;
  354. }
  355. extern "C" int Func1H(Interop::StructH arg0, Interop::StructH arg1, int arg2)
  356. {
  357. return (int)arg0.mA + (int)arg1.mA * 100 + arg2 * 10000;
  358. }
  359. extern "C" int Func1I(Interop::StructI arg0, Interop::StructI arg1, int arg2)
  360. {
  361. return (int)arg0.mA + (int)arg1.mA * 100 + arg2 * 10000;
  362. }
  363. //////////////////////////////////////////////////////////////////////////
  364. extern "C" Interop::StructA Func2A(Interop::StructA arg0, int arg1)
  365. {
  366. Interop::StructA ret;
  367. ret.mA = arg0.mA + arg1;
  368. return ret;
  369. }
  370. extern "C" Interop::StructB Func2B(Interop::StructB arg0, int arg1)
  371. {
  372. Interop::StructB ret;
  373. ret.mA = arg0.mA + arg1;
  374. return ret;
  375. }
  376. extern "C" Interop::StructC Func2C(Interop::StructC arg0, int arg1)
  377. {
  378. Interop::StructC ret;
  379. ret.mA = arg0.mA + arg1;
  380. return ret;
  381. }
  382. extern "C" Interop::StructD Func2D(Interop::StructD arg0, int arg1)
  383. {
  384. Interop::StructD ret;
  385. ret.mA = arg0.mA + arg1;
  386. return ret;
  387. }
  388. extern "C" Interop::StructE Func2E(Interop::StructE arg0, int arg1)
  389. {
  390. Interop::StructE ret;
  391. ret.mA = arg0.mA + arg1;
  392. return ret;
  393. }
  394. extern "C" Interop::StructF Func2F(Interop::StructF arg0, int arg1)
  395. {
  396. Interop::StructF ret;
  397. ret.mA = arg0.mA + arg1;
  398. return ret;
  399. }
  400. extern "C" Interop::StructG Func2G(Interop::StructG arg0, int arg1)
  401. {
  402. Interop::StructG ret;
  403. ret.mA = arg0.mA + arg1;
  404. return ret;
  405. }
  406. extern "C" Interop::StructH Func2H(Interop::StructH arg0, int arg1)
  407. {
  408. Interop::StructH ret;
  409. ret.mA = arg0.mA + arg1;
  410. return ret;
  411. }
  412. extern "C" Interop::StructI Func2I(Interop::StructI arg0, int arg1)
  413. {
  414. Interop::StructI ret;
  415. ret.mA = arg0.mA + arg1;
  416. return ret;
  417. }
  418. extern "C" Interop::StructX Func2X(Interop::StructX arg0, int arg1)
  419. {
  420. Interop::StructX ret;
  421. ret.mA = arg0.mA + arg1;
  422. ret.mB = arg0.mB;
  423. ret.mC = arg0.mC + 1;
  424. return ret;
  425. }
  426. //////////////////////////////////////////////////////////////////////////
  427. extern "C" int Func3A(Interop::StructA* ptr)
  428. {
  429. return ptr[0].mA + ptr[1].mA * 100;
  430. }
  431. extern "C" int Func3B(Interop::StructB* ptr)
  432. {
  433. return ptr[0].mA + ptr[1].mA * 100;
  434. }
  435. extern "C" int Func3C(Interop::StructC* ptr)
  436. {
  437. return ptr[0].mA + ptr[1].mA * 100;
  438. }
  439. extern "C" int Func3D(Interop::StructD* ptr)
  440. {
  441. return ptr[0].mA + ptr[1].mA * 100;
  442. }
  443. extern "C" int Func3E(Interop::StructE* ptr)
  444. {
  445. return ptr[0].mA + ptr[1].mA * 100;
  446. }
  447. extern "C" int Func3F(Interop::StructF* ptr)
  448. {
  449. return ptr[0].mA + ptr[1].mA * 100;
  450. }
  451. extern "C" int Func3G(Interop::StructG* ptr)
  452. {
  453. return ptr[0].mA + ptr[1].mA * 100;
  454. }
  455. //////////////////////////////////////////////////////////////////////////
  456. extern "C" Interop::StructJ Func4J(Interop::StructJ arg0, Interop::StructJ arg1, Interop::StructJ arg2, Interop::StructJ arg3)
  457. {
  458. Interop::StructJ ret;
  459. ret.mPtr = arg0.mPtr;
  460. ret.mLength = arg0.mLength + arg1.mLength * 100 + arg2.mLength * 10000 + arg3.mLength * 1000000;
  461. return ret;
  462. }
  463. extern "C" double Func5(float v0[2], float v1[3])
  464. {
  465. return v0[0] + v0[1]*10 + v1[0]*100 + v1[1]*1000 + v1[2]*10000;
  466. }
  467. void UseIt()
  468. {
  469. Interop::StructA sa;
  470. sa.MethodA0(0);
  471. sa.MethodA1(sa, 1);
  472. float f = 123;
  473. sa.MethodA2(f);
  474. sa.MethodA3(f);
  475. Interop::StructB sb;
  476. sb.MethodB0(0);
  477. sb.MethodB1(sb, 1);
  478. Interop::StructC sc;
  479. sc.MethodC0(0);
  480. sc.MethodC1(sc, 1);
  481. Interop::StructD sd;
  482. sd.MethodD0(0);
  483. sd.MethodD1(sd, 1);
  484. Interop::StructE se;
  485. se.MethodE0(0);
  486. se.MethodE1(se, 1);
  487. Interop::StructF sf;
  488. sf.MethodF0(0);
  489. sf.MethodF1(sf, 1);
  490. Interop::StructG sg;
  491. sg.MethodG0(0);
  492. sg.MethodG1(sg, 1);
  493. Interop::StructH sh;
  494. sh.MethodH0(0);
  495. sh.MethodH1(sh, 1);
  496. Interop::StructI si;
  497. si.MethodI0(0);
  498. si.MethodI1(si, 1);
  499. Interop::StructJ sj;
  500. sj.MethodJ0(0);
  501. sj.MethodJ1(sj, 1);
  502. }