Pelles C forum

C language => Beginner questions => Topic started by: ohmycee on July 25, 2011, 12:59:38 PM

Title: DLL problems. Help!
Post by: ohmycee on July 25, 2011, 12:59:38 PM
Hi. I'm trying to create a very simple dll with Pelles C using the wizard. I start by going to File > New > Project > Empty projects > Win32 Dynamic library (DLL). I then create a file named "main.c", and here's my sourcecode:

#include <stdio.h>

int hello(int var)
{
return 5 * var;
}


I want to access my dll from python as such:
from ctypes import *
test = cdll.LoadLibrary("helloDLL.dll")
print(test.hello(5))


The return result should be 25.

When I compile the code using gcc as follows, the DLL works:

gcc -c main.c
gcc -shared -o helloDLL.dll main.o


However, when I build with Pelles C, the function cannot be found.

What am I doing wrong? I'm just about to pull out my hair. Please help. Thanks.
Title: Re: DLL problems. Help!
Post by: CommonTater on July 25, 2011, 01:16:09 PM
http://msdn.microsoft.com/en-us/library/ms682589(v=VS.85).aspx

Also use the Windows DLL Wizard to create a project and look at the way it works.

Title: Re: DLL problems. Help!
Post by: ohmycee on July 25, 2011, 01:31:57 PM
Thanks CommonTater,

I'll keep plodding along to see what happens.
Title: Re: DLL problems. Help!
Post by: CommonTater on July 25, 2011, 01:33:11 PM
Pay particular attention to the DLLMain() function... it is called by LoadLibrary() which will fail if it's not there.
Title: Re: DLL problems. Help!
Post by: TimoVJL on July 25, 2011, 02:19:00 PM
depending calling convention:
int __declspec( dllexport ) __cdecl hello(int var)
{
return 5 * var;
}

or
int __declspec( dllexport ) __stdcall hello(int var)
{
return 5 * var;
}

Title: Re: DLL problems. Help!
Post by: ohmycee on July 25, 2011, 04:57:55 PM
OMG, thanks timovjl!

That bit of code really helped.

I so hate being a noob :-/