Advertisement
Teammasik

lr_2_EVM

Mar 6th, 2023 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. // python
  2. from ctypes import CDLL
  3.  
  4. lib = CDLL('C:/Users/6acco/Documents/учёба/IBM/laba 1/1/MathClient/x64/Debug/MathLibrary.dll')
  5.  
  6. a = int(input())
  7. b = int(input())
  8.  
  9.  
  10. print("Sum: %s\nMultiplication: %s\nDivision: %s\nDifference: %s\nGet: %s"
  11.       % (lib.Sum(a, b), lib.Umn(a, b), lib.Del(a, b), lib.Raz(a, b), lib.get()))
  12.  
  13.  
  14. // dll lib .h
  15. extern "C" __declspec(dllexport) int Sum(int a, int b);
  16. extern "C" __declspec(dllexport) int Umn(int a, int b);
  17. extern "C" __declspec(dllexport) int Del(int a, int b);
  18. extern "C" __declspec(dllexport) int Raz(int a, int b);
  19. extern "C" __declspec(dllexport) int get();
  20. extern "C" __declspec(dllexport) void set();
  21.  
  22. // dll cpp
  23.  
  24. # include "pch.h"
  25.  
  26. static int rr = 0;
  27. static int k = 5;
  28. extern "C" __declspec(dllexport) int Sum(int a, int b) {
  29.     return a + b;
  30. }
  31. extern "C" __declspec(dllexport) int Umn(int a, int b) {
  32.     return a * b;
  33. }
  34. extern "C" __declspec(dllexport) int Del(int a, int b) {
  35.     return a / b;
  36. }
  37. extern "C" __declspec(dllexport) int Raz(int a, int b) {
  38.     return a - b;
  39. }
  40. extern "C" __declspec(dllexport) int get() {
  41.     return rr;
  42. }
  43. extern "C" __declspec(dllexport) void set() {
  44.     rr += k;
  45.     k += 5;
  46. }
  47. // c++ client file (client.cpp)
  48. #include <Windows.h>
  49. #include <iostream>
  50. using namespace std;
  51.  
  52. typedef int (WINAPI* GET)();
  53. typedef void(WINAPI* SET)();
  54. // typedef int (WINAPI* TO_ASSIGN)(int);
  55.  
  56.  
  57. int main()
  58. {
  59.  
  60.     HMODULE hModule = LoadLibrary(TEXT("MathLibrary.dll"));
  61.     if (hModule == NULL) return -1;
  62.  
  63.     GET get = (GET)GetProcAddress(hModule, "get");
  64.     SET set = (SET)GetProcAddress(hModule, "set");
  65.     //TO_ASSIGN to_assign = (TO_ASSIGN)GetProcAddress(hModule, "TO_ASSIGN");
  66.     int a;
  67.     cin >> a;
  68.     for (int i = 0; i < 5; i++)
  69.     {
  70.         set();
  71.     }
  72.    
  73.     cout << get();
  74.     cin >> a;
  75.  
  76.     /*cout << "enter first and second numbers" << endl;
  77.     int a, b, cc;
  78.     cin >> a >> b;
  79.     cc = sum(a, b);
  80.  
  81.     cout << "sum of a and b: " << cc << endl;
  82.     cout << "difference of a and b: " << diff(a, b) << endl;
  83.     cout << "assigning 20 to variable a: " << to_assign(a) << endl;*/
  84.    
  85.  
  86.     FreeLibrary(hModule);
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement