NO

Author Topic: How to load and use functions from DLL?  (Read 2587 times)

ohmycee

  • Guest
How to load and use functions from DLL?
« on: August 17, 2011, 08:36:41 PM »
Hi all,

I'm starting a new post because the previous one has gone in a confusing direction. Here's my question:

I have a DLL: test.dll. It has 2 functions:
int ReturnNumber(void); // returns 98765
int ReturnAnotherNumber(int, int); // multiples both integers and returns the value

That's all I know about the dll. I don't have the sourcecode. I don't have the .lib.

To use the dll, I write the following. I call it usethedll.c:
Code: [Select]
#include <stdio.h>

int ReturnNumber(void);
int ReturnAnotherNumber(int, int);

int main (int argc, char **argv)
{
  printf("Test: %d\n", ReturnNumber()); //notice I can use the function simply by calling it, no need to loadlibrary or getprocaddress
  printf("Test: %d", ReturnAnotherNumber(8,9)); //same thing here
  return 0;
}

With GCC, I compile the code as such:
Code: [Select]
gcc -L. -ltest -o usethedll usethedll.c
My question is, how do I use test.dll as easily in Pelles C?

Thanks!
« Last Edit: August 17, 2011, 08:41:51 PM by ohmycee »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: How to load and use functions from DLL?
« Reply #1 on: August 17, 2011, 09:30:40 PM »
Code: [Select]
polib.exe test.dll /out:test.lib
Code: [Select]
cc -x usethedll.c test.lib kernel32.lib
« Last Edit: August 17, 2011, 09:43:07 PM by timovjl »
May the source be with you

ohmycee

  • Guest
Re: How to load and use functions from DLL?
« Reply #2 on: August 17, 2011, 09:45:28 PM »
Brilliant! That works. Thanks  :)