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 7752653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:51:11+00:00 2026-06-01T11:51:11+00:00

I have a structure which contains character array on C side stuct s {

  • 0

I have a structure which contains character array on C side

stuct s
{
    int x;
    char buffer[100];
}

and on my python side I define

class myS(ctypes.Structure):
    _fields_ = [("x", c_int),
         ("buffer",type(create_string_buffer(100)))]

Now, when I do

buf = create_string_buffer(64)
s1 = myS(10,buf)

It gives me error

TypeError: expected string or Unicode object, c_char_Array_100 found

I want a string which will be changed by my C function. how to do it?

  • 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-01T11:51:12+00:00Added an answer on June 1, 2026 at 11:51 am

    You don’t have to create a buffer. The buffer is in the structure when you instantiate it.

    Here’s a quick DLL:

    #include <string.h>
    
    struct s
    {
        int x;
        char buffer[100];
    };
    
    __declspec(dllexport) void func(struct s* a)
    {
        a->x = 5;
        strcpy(a->buffer,"here is the contents of the string.");
    }
    

    And here’s Python code to call it:

    import ctypes
    
    class myS(ctypes.Structure):
        _fields_ = [
            ("x", ctypes.c_int),
            ("buffer",ctypes.c_char * 100)]
    
    s1 = myS()
    dll = ctypes.CDLL('test')
    dll.func(ctypes.byref(s1))
    print s1.buffer
    print s1.x
    

    Output:

    here is the contents of the string.
    5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a business object project, which contains composite structure: public class Tree {
I have a database structure that has a Person table which contains fields such
I have a data structure which is as given below: class File { public
I have a table T (structure below) which initially contains all-NULL values in an
I have a complex structure which contains a list ofthe following form complex tree
I have a program which creates a C structure which contains large arrays of
I have a directory structure like com/example/web under the root directory which contains a
seeking some advice here. I have a structure which contains a pointer to another
I have a zip file which contains the following directory structure: dir1\dir2\dir3a dir1\dir2\dir3b I'm
I have a structure which contains some elements, i free the memory of this

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.