By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,761 Members | 1,037 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,761 IT Pros & Developers. It's quick & easy.

I can't seem to get Ctypes to find my c++ functions declared within a DLL file.

Jory R Ferrell
P: 62
The following attachments may help better than my own description.

CTypes_1 is a picture of the python code calling the function from the DLL.

CTypes_2 is the code contained within the DLL. (Before compilation of course. The actual DLL looks nothing like this.)

CTypes_3 is the DLL located in the directory I am calling it from during import. It is clearly labeled as a DLL, so I didn't just try to use the wrong file type (would've thrown an error anyways).

CTypes_4 is the actual error output from python.

I have been using older tutorials I suppose, but I would assume that of the four or so ways I have seen people implement to load the files hasn't really changed all that much, so it must be something I am missing. Did I create the functions in the DLL incorrectly? Did I screw-up the import in the python code somehow? I am not seeing what the problem is. Thanks in advance.
Attached Images
File Type: jpg CTypes_1.jpg (17.9 KB, 294 views)
File Type: jpg CTypes_2.jpg (27.6 KB, 408 views)
File Type: jpg CTypes_3.jpg (13.5 KB, 224 views)
File Type: png CTypes_4.PNG (12.3 KB, 372 views)
Oct 28 '12 #1
Share this Question
Share on Google+
2 Replies

Jory R Ferrell
P: 62
As for my choice of function names....mind your business. :P

Oct 28 '12 #2

Jory R Ferrell
P: 62
Ok...ok...calm down everyone. I appreciate the OVERWHELMING amount of help I have received, but I found the answer on my own:

Apparently you need to add a directive to the cpp code and then set-up the function for export as a dll asset. I JUST found this solution so I am not sure what makes it tick (I am not very familiar with c++), but I'll read up on it some and let you know what I find....if I even understand it... :P
I haven't seen any other examples that have to jump through this hoop when creating the dll (If they did, they left out some steps :/ ), but it's working now.
The following added to the c++ verision dll (diff for straight "C" code), gets the entire thing working:
Expand|Select|Wrap|Line Numbers
  1. // ConsApp.cpp : Defines the exported functions for the DLL application.
  2. //
  4. #include "stdafx.h"
  5. #define DLLEXPORT extern "C" __declspec(dllexport)
  7. DLLEXPORT int otters(int a, int b) {
  8.     return a + b;
  9. }
  11. DLLEXPORT int ducks(int a, int b){
  12.     return(a-b);
  13. }
Oct 29 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.