Hi,
I used SCons to create a shared library (dll) from a c++ file (hello.cpp) below. Then I used Python and it ctypes library to load in the dll and call its functions. I can load the dll and call the main function, but nothing else. I cannot call the other prototyped functions in the cpp file or get values of constants. I am pretty sure they are in the dll (any tool to find them?). The Python script is below. How can access the functions other than main and other constants in the dll created from the cpp file?

Thanks!
-Vic

from ctypes import *

c = cdll.LoadLibrary("hello.dll")
print c.main(5,4)

print c.rr

print c.add(5,6)

print c.minus(5,1)

Error Message:

>>> 
9
Traceback (most recent call last):
  File "C:\Documents and Settings\Your Name\Desktop\compile_attempts\testscons.py", line 6, in <module>
    print c.rr
  File "C:\Python25\lib\ctypes\__init__.py", line 361, in __getattr__
    func = self.__getitem__(name)
  File "C:\Python25\lib\ctypes\__init__.py", line 366, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'rr' not found

hello.cpp

#include <iostream>
using namespace std;


int add(int r, int q);
int minus(int r, int q);
int times(int r, int q);
int divide(int r, int q);

int main(int r, int q)
{
    cout << "Hello, world!\n";
    r = add(q,r);
    return r;
}

int add(int r, int q)
{
    cout << "Hello, world!\n";
    return r+q;
}
int minus(int r, int q)
{
    cout << "Hello, world!\n";
    return r-q;
}
int times(int r, int q)
{
    cout << "Hello, world!\n";
    return r*q;
}
int divide(int r, int q)
{
    cout << "Hello, world!\n";
    return r/q;
}

Are the functions in your dll exported? I know I had to do something like

int __declspec(dllexport) add(int r, int q);

instead of just

int add(int r, int q);

when writing my dll.

EDIT: I just saw that this thread is almost a year old. Did you really have to go digging it up?

One year ago! Damn i thought I helped that guy :)

Its always good to reply. If not that person who asked question,, anyone with similar issue will benefit from your responses.
I am facing similar issue right now. And your responses are beneficial.. going through the link you provided.

Thank you !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.