NO

Author Topic: DLL problems. Help!  (Read 2981 times)

ohmycee

  • Guest
DLL problems. Help!
« 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:

Code: [Select]
#include <stdio.h>

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

I want to access my dll from python as such:
Code: [Select]
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:
Code: [Select]
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

  • Guest
Re: DLL problems. Help!
« Reply #1 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.


ohmycee

  • Guest
Re: DLL problems. Help!
« Reply #2 on: July 25, 2011, 01:31:57 PM »
Thanks CommonTater,

I'll keep plodding along to see what happens.

CommonTater

  • Guest
Re: DLL problems. Help!
« Reply #3 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.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2094
Re: DLL problems. Help!
« Reply #4 on: July 25, 2011, 02:19:00 PM »
depending calling convention:
Code: [Select]
int __declspec( dllexport ) __cdecl hello(int var)
{
return 5 * var;
}
or
Code: [Select]
int __declspec( dllexport ) __stdcall hello(int var)
{
return 5 * var;
}
« Last Edit: July 25, 2011, 02:36:45 PM by timovjl »
May the source be with you

ohmycee

  • Guest
Re: DLL problems. Help!
« Reply #5 on: July 25, 2011, 04:57:55 PM »
OMG, thanks timovjl!

That bit of code really helped.

I so hate being a noob :-/