Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sorry, I can't reproduce your problem (Windows 7 x64, 32-bit Python 2.7.3). I'll describe what I tried in order to reproduce your problem, in the hope that it will help you.</p> <p>I created a new project and solution in Visual C++ Express 2008, both named "CDll". The project was set to compile as C code and use the stdcall calling convention. Apart from the stuff VC++ 2008 autogenerated, it had the following two files:</p> <p>CDll.h:</p> <pre><code>#ifdef CDLL_EXPORTS #define CDLL_API __declspec(dllexport) #else #define CDLL_API __declspec(dllimport) #endif typedef struct testResult_t { int testId; int TT; double fB; double mD; double mDL; int nS; int nL; } TestResult; TestResult CDLL_API __stdcall dummyTest(); </code></pre> <p>CDll.cpp (yes, I know the extension is '.cpp', but I don't think that matters):</p> <pre><code>#include "stdafx.h" #include "CDll.h" TestResult __stdcall dummyTest() { TestResult a = {0}; a.testId = 3; return a; }; </code></pre> <p>I then compiled and built the DLL. I then attempted to load it and call the function with the following Python script:</p> <pre><code>from ctypes import Structure, c_int, c_double, windll astdll = windll.CDll class TestResult(Structure): _fields_ = [ ("testId", c_int), ("TT", c_int), ("fB", c_double), ("mD", c_double), ("mDL", c_double), ("nS", c_int), ("nL", c_int) ] astdll.dummyTest.restype = TestResult result = astdll.dummyTest() print "Test ID: %d" % (result.testId) </code></pre> <p>When I ran this script I got the output <code>Test ID: 3</code>.</p> <hr> <p>The first thought I had about what your problem might be was that you were attempting to load the DLL using <code>CDLL</code> when you should be using <code>windll</code>, but when I tried using <code>CDLL</code>, I got a completely different error message. You haven't shown us how you are loading the DLL, but I suspect you are using <code>windll</code> as I have done above.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload