Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8280047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:31:54+00:00 2026-06-08T09:31:54+00:00

I have a c function as: extern C __declspec(dllexport) MyStruct foo() { MyStruct s

  • 0

I have a c function as:

extern "C"  __declspec(dllexport) MyStruct foo()
{
    MyStruct s = {0, 0}
    return s;
}

where the MyStruct is define as:

struct MyStruct{
    uInt32   a;
    uInt32   b;
    void *   c;
};

And i am trying to call the function in python, but always get error like:

WindowsError: exception: access violation writing 0x00000000

if i remove void * c from the struct, then it works…

so how should i return the void pointer?
thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:31:56+00:00Added an answer on June 8, 2026 at 9:31 am

    This is almost certainly being caused by a disagreement between your C compiler and the ctypes library on the ABI for returning the object. Without seeing your Python code, it’s hard to say whether the problem is due to an incorrect Python declaration of the return type, a bug in the ctypes library, or a non-standard ABI chosen by the C compiler.

    For the most portable behavior, I’d suggest changing the function to return the object via an out parameter, like so:

    extern "C"  __declspec(dllexport) void foo(MyStruct *ret)
    {
        MyStruct s = {0, 0}
        *ret = s;
    }
    

    And interface with it like so:

    class MyStruct(ctypes.Structure):
        _fields_ = [("a", ctypes.c_uint),
                    ("b", ctypes.c_uint),
                    ("c", ctypes.c_void_p)]
    
    mylib = ctypes.cdll.LoadLibrary('mylibrary')
    foo = mylib.foo
    foo.argtypes = [ctypes.POINTER(MyStruct)]
    
    x = MyStruct()
    foo(ctypes.byref(x))
    # x should now have the return value from the C code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this C++ code: extern C __declspec(dllexport) VOID AllocateFoo(MY_DATA_STRUCTURE** foo) { *foo =
I have the function prototype here: extern C void __stdcall__declspec(dllexport) ReturnPulse(double*,double*,double*,double*,double*); I need to
I have an external function like this: extern C __declspec(dllexport) int __cdecl Identify(BSTR* bstrTemplates,
I have code that looks like this: extern C __declspec(dllexport) myInterface(int id, void** pFunction)
I have a C++ DLL with an exported function: extern C __declspec(dllexport) double* fft(double*
I have a c++ function like, extern C __declspec ( dllexport ) DWORD GetSizeAfterMergeISOTemplates(BYTE*
in c++ I have such function extern C _declspec(dllexport) uint8* bufferOperations(uint8* incoming, int size)
I have an DLL that has this in its h file: extern C __declspec(dllexport)
I have the following function: bool __declspec(dllexport) COMS_HL7QueryAnswer(char *szZone,char* szMessage, char** o_szAnswer) And I'm
I have a function as below extern C int FuncTrace(const char *fmt, ...) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.