I am working on a beginner c program. I have 1 simple function to calculate the area of a rectangle. How can I put this in a dll and call the dll from another program. I'm trying to learn to create libraries and dlls, so an example of both could help (so I can examine the differences).
Also, I understand dlls have specific requirements on windows, so if you have any further notes I should be aware of, please tell me.
Build this as dll:
// testDll.c
int __declspec( dllexport ) __cdecl SampleFunction(int a, int b)
{
return a * b;
}
#include <stdio.h>
#pragma comment(lib, "TestDll.lib")
int __declspec( dllexport ) __cdecl SampleFunction(int a, int b);
int main(int argc, char **argv)
{
printf("result: %d\n", SampleFunction(40, 2));
return 0;
}