C 源碼:
#include <stdio.h>
#pragma comment(lib, "DLL_demo.lib")
extern double add(double, double);
extern double sub(double, double);
extern double mul(double, double);
extern double div(double, double);
int main(void)
{
double a, b;
char op, c;
puts("Please input a formula and get the result. (enter q to quit)\n");
while (1)
{
printf("Enter: ");
if (scanf("%lf %c %lf", &a, &op, &b) == 3)
switch (op)
{
case '+':printf("%.2lf + %.2lf = %.2lf\n", a, b, add(a, b)); break;
case '-':printf("%.2lf - %.2lf = %.2lf\n", a, b, sub(a, b)); break;
case '*':printf("%.2lf * %.2lf = %.2lf\n", a, b, mul(a, b)); break;
case '/':printf("%.2lf / %.2lf = %.2lf\n", a, b, div(a, b)); break;
default :printf("Enter error!\n");
}
else
{
if ((c = getchar()) == 'q')
break;
puts("Enter error!");
while (getchar() != '\n')
continue;
}
}
puts("Bye~");
getchar();
getchar();
return 0;
}
DLL 源碼:
_declspec(dllexport) double add(double a, double b)
{
return a + b;
}
_declspec(dllexport) double sub(double a, double b)
{
return a - b;
}
_declspec(dllexport) double mul(double a, double b)
{
return a * b;
}
_declspec(dllexport) double div(double a, double b)
{
return a / b;
}
更多建議: