-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNativeFromC++.cpp
35 lines (30 loc) · 1.24 KB
/
NativeFromC++.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <windows.h>
#include <stdio.h>
#include <iostream>
int main()
{
auto nativeLibrary = LoadLibrary(TEXT("/native-demo/native-c#.dll"));
auto print_message = GetProcAddress(nativeLibrary, "print_message");
auto add_numbers = (int (*)(int, int))GetProcAddress(nativeLibrary, "add_numbers");
auto subtract_numbers = (int (*)(int, int))GetProcAddress(nativeLibrary, "subtract_numbers");
auto multiply_numbers = (double (*)(double, double))GetProcAddress(nativeLibrary, "multiply_numbers");
auto divide_numbers = (double (*)(double, double))GetProcAddress(nativeLibrary, "divide_numbers");
auto populate_array = (void (*)(double[], int))GetProcAddress(nativeLibrary, "populate_array");
auto added = add_numbers(7, 2);
auto subtracted = subtract_numbers(7, 2);
auto multiplied = multiply_numbers(7, 2);
auto divided = divide_numbers(7, 2);
auto array = new double[5];
populate_array(array, sizeof(array));
print_message();
std::cout << added << std::endl;
std::cout << subtracted << std::endl;
std::cout << multiplied << std::endl;
std::cout << divided << std::endl;
for (int i = 0; i < 5; i++)
{
std::cout << array[i] << " ";
}
FreeLibrary(nativeLibrary);
return 0;
}