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

  • Home
  • SEARCH
  • 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 7993217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:47:10+00:00 2026-06-04T13:47:10+00:00

With regard to Python 2.5, I wish to implement the following C code in

  • 0

With regard to Python 2.5, I wish to implement the following C code in python:

C code:

#include <wtypes.h>

__declspec(dllexport) X_ERROR __stdcall GetAdmSize(INT* piAdmSize, CHAR** chBuf, INT iBufSize);

int iProgSize = 0;
char szProgSize[50];
char* pszProgSize = szProgSize;
error = GetAdmSize(&iProgSize, &pszProgSize, 49);

Python code:

from ctypes import *
c_bool = c_int

x = windll.LoadLibrary("x.dll")
iProgSize = c_int()
szProgSize = create_string_buffer(50)
getAdmSize = x.AdkGetAdmSize
getAdmSize.argtypes = [POINTER(c_int), POINTER(c_char_p), c_int]
status = getAdmSize(byref(iProgSize), byref(szProgSize), 49)

But I’m getting the following exception:

Traceback (most recent call last):
    status = getAdmSize(byref(iProgSize), (szProgSize), 49)
ArgumentError: argument 2: <type 'exceptions.TypeError'>: expected LP_c_char_p instance instead of c_char_Array_50

What am I doing wrong?

UPDATE:

I tried:

pointerToStringBuffer = cast(szProgSize, c_char_p)
status = getAdmSize(byref(iProgSize), byref(pointerToStringBuffer), 49)

But this gives me:

Traceback (most recent call last):
    status = getAdmSize(byref(iProgSize), byref(pointerToStringBuffer), 49)
WindowsError: exception: access violation reading 0x00000031

As a matter of interest, I get the same error in C if I call this:

error = AdkGetAdmSize((int*)0, (char**)49, 0);

Seems like my arguments are not aligned correctly perhaps

Any suggestions?

  • 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-04T13:47:12+00:00Added an answer on June 4, 2026 at 1:47 pm

    A direct translation of your C code would be more like:

    from ctypes import *
    x = windll.LoadLibrary("x.dll")
    iProgSize = c_int(0)
    szProgSize = create_string_buffer(50)
    pszProgSize = c_char_p(addressof(szProgSize))
    getAdmSize = x.GetAdmSize
    getAdmSize.argtypes = [POINTER(c_int), POINTER(c_char_p), c_int]
    status = getAdmSize(byref(iProgSize), byref(pszProgSize), 49)
    

    Fake DLL I tested with:

    typedef int X_ERROR;
    typedef int INT;
    typedef char CHAR;
    
    #include <string.h>
    
    __declspec(dllexport) X_ERROR __stdcall GetAdmSize(INT* piAdmSize, CHAR** chBuf, INT iBufSize)
    {
        *piAdmSize = 5;
        strcpy_s(*chBuf,iBufSize,"abcd");
        return 1;
    }
    

    Results:

    >>> x.iProgSize
    c_long(5)
    >>> x.pszProgSize
    c_char_p('abcd')
    >>> x.szProgSize.value
    'abcd'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I search the Python equivalent for the following Bash code: VAR=$(echo $VAR) Pseudo Python
I'm cleaning some of the Python code I wrote when I was...not as knowledgeable.
Running GNU Emacs 22.2.1 on Ubuntu 9.04. When editing python code in emacs, if
python newbie here. I'm writing the code to control an experiment that has multiple
In python 3, int(50)<'2' causes a TypeError , and well it should. In python
I'm using Python 2.6.6 I have this code: height = 20 width = 10
In the book - Core Python Programming, there is following example - >>> f
I need urgent help in this regard. I am trying to run a Python
I have this code in Python that was quite simple to do with mechanize
How can I implement encryption between server side in (php/python) and C++ (Win32/Native Windows)?

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.