DLL problems. Help!

Started by ohmycee, July 25, 2011, 12:59:38 PM

Previous topic - Next topic

ohmycee

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.

CommonTater

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.


ohmycee

Thanks CommonTater,

I'll keep plodding along to see what happens.

CommonTater

Pay particular attention to the DLLMain() function... it is called by LoadLibrary() which will fail if it's not there.

TimoVJL

#4
depending calling convention:
int __declspec( dllexport ) __cdecl hello(int var)
{
return 5 * var;
}

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

May the source be with you

ohmycee

OMG, thanks timovjl!

That bit of code really helped.

I so hate being a noob :-/