Pelles C forum

C language => Beginner questions => Topic started by: cprog on May 03, 2012, 06:34:20 PM

Title: Working on beginner C program howto - dll
Post by: cprog on May 03, 2012, 06:34:20 PM
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.
Title: Re: Working on beginner C program howto - dll
Post by: TimoVJL on May 03, 2012, 07:30:17 PM
Build this as dll:
Code: [Select]
// testDll.c
int __declspec( dllexport ) __cdecl SampleFunction(int a, int b)
{
return a * b;
}
Code: [Select]
#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;
}