homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ctypes: need example how to pass raw data from Python
Type: Stage:
Components: ctypes, Documentation Versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: amaury.forgeotdarc, docs@python, techtonik
Priority: normal Keywords:

Created on 2011年07月03日 08:02 by techtonik, last changed 2022年04月11日 14:57 by admin.

Messages (3)
msg139675 - (view) Author: anatoly techtonik (techtonik) Date: 2011年07月03日 08:02
ctypes documentation lacks an example, how to pass a raw data block from Python to a C function. For example, how to pass this chunk:
data = open('somefile', 'rb').read()
to this function:
int checkBuffer(LPSTR lpData, DWORD dwBufferLength);
?
msg139676 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011年07月03日 08:52
Can you suggest a patch?
msg139686 - (view) Author: anatoly techtonik (techtonik) Date: 2011年07月03日 12:24
ISTM that this code works ok.
data = open('data.raw', 'rb').read()
ret = checkBuffer(data, len(data))
You need to make sure that checkBuffer doesn't try to modify memory though. For mutable memory blocks use create_string_buffer().
History
Date User Action Args
2022年04月11日 14:57:19adminsetgithub: 56685
2011年07月03日 12:24:43techtoniksetmessages: + msg139686
2011年07月03日 08:52:25amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg139676
2011年07月03日 08:02:36techtonikcreate

AltStyle によって変換されたページ (->オリジナル) /