NO

Author Topic: Working on beginner C program howto - dll  (Read 2588 times)

cprog

  • Guest
Working on beginner C program howto - dll
« 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.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Working on beginner C program howto - dll
« Reply #1 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;
}
« Last Edit: May 03, 2012, 07:38:51 PM by timovjl »
May the source be with you