Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // python
- from ctypes import CDLL
- lib = CDLL('C:/Users/6acco/Documents/учёба/IBM/laba 1/1/MathClient/x64/Debug/MathLibrary.dll')
- a = int(input())
- b = int(input())
- print("Sum: %s\nMultiplication: %s\nDivision: %s\nDifference: %s\nGet: %s"
- % (lib.Sum(a, b), lib.Umn(a, b), lib.Del(a, b), lib.Raz(a, b), lib.get()))
- // dll lib .h
- extern "C" __declspec(dllexport) int Sum(int a, int b);
- extern "C" __declspec(dllexport) int Umn(int a, int b);
- extern "C" __declspec(dllexport) int Del(int a, int b);
- extern "C" __declspec(dllexport) int Raz(int a, int b);
- extern "C" __declspec(dllexport) int get();
- extern "C" __declspec(dllexport) void set();
- // dll cpp
- # include "pch.h"
- static int rr = 0;
- static int k = 5;
- extern "C" __declspec(dllexport) int Sum(int a, int b) {
- return a + b;
- }
- extern "C" __declspec(dllexport) int Umn(int a, int b) {
- return a * b;
- }
- extern "C" __declspec(dllexport) int Del(int a, int b) {
- return a / b;
- }
- extern "C" __declspec(dllexport) int Raz(int a, int b) {
- return a - b;
- }
- extern "C" __declspec(dllexport) int get() {
- return rr;
- }
- extern "C" __declspec(dllexport) void set() {
- rr += k;
- k += 5;
- }
- // c++ client file (client.cpp)
- #include <Windows.h>
- #include <iostream>
- using namespace std;
- typedef int (WINAPI* GET)();
- typedef void(WINAPI* SET)();
- // typedef int (WINAPI* TO_ASSIGN)(int);
- int main()
- {
- HMODULE hModule = LoadLibrary(TEXT("MathLibrary.dll"));
- if (hModule == NULL) return -1;
- GET get = (GET)GetProcAddress(hModule, "get");
- SET set = (SET)GetProcAddress(hModule, "set");
- //TO_ASSIGN to_assign = (TO_ASSIGN)GetProcAddress(hModule, "TO_ASSIGN");
- int a;
- cin >> a;
- for (int i = 0; i < 5; i++)
- {
- set();
- }
- cout << get();
- cin >> a;
- /*cout << "enter first and second numbers" << endl;
- int a, b, cc;
- cin >> a >> b;
- cc = sum(a, b);
- cout << "sum of a and b: " << cc << endl;
- cout << "difference of a and b: " << diff(a, b) << endl;
- cout << "assigning 20 to variable a: " << to_assign(a) << endl;*/
- FreeLibrary(hModule);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement