Pelles C forum

C language => Beginner questions => Topic started by: ohmycee on August 17, 2011, 08:36:41 PM

Title: How to load and use functions from DLL?
Post by: ohmycee 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:
#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:
gcc -L. -ltest -o usethedll usethedll.c

My question is, how do I use test.dll as easily in Pelles C?

Thanks!
Title: Re: How to load and use functions from DLL?
Post by: TimoVJL on August 17, 2011, 09:30:40 PM
polib.exe test.dll /out:test.lib
cc -x usethedll.c test.lib kernel32.lib
Title: Re: How to load and use functions from DLL?
Post by: ohmycee on August 17, 2011, 09:45:28 PM
Brilliant! That works. Thanks  :)