calling NetShareEnum win32api with ctypes

This is a discussion on calling NetShareEnum win32api with ctypes within the Python forums in Programming Languages category; I want to call NetShareEnum, a function from netapi32.dll NetShareEnum has this definition: NET_API_STATUS NetShareEnum( __in LPWSTR servername, __in DWORD level, __out LPBYTE *bufptr, __in DWORD prefmaxlen, __out LPDWORD entriesread, __out LPDWORD totalentries, __inout LPDWORD resume_handle ); I wrote this code in python 2.5: from ctypes import * cname=c_wchar_p('a-computer-name') level=c_int(1) bufptr=create_string_buffer('\00', 10000) prefmaxlen=c_int(9999) entriesread=c_long(0) totalentries=c_long(0) resume=c_long(0) netapi32=cdll.LoadLibrary('netapi32.dll') netapi32.NetShareEnum(cname, level, byref(bufptr), prefmaxlen, byref(entriesread), byref(totalentries), byref(resume)) but I get this error: Traceback (most recent call last): File "<pyshell#12>", line 1, in <module> s.NetShareEnum(name, level, byref(bufptr), prefmaxlen, entriesread, totalentries, resume) ValueError: Procedure called with not enough arguments (28 bytes missing) or wrong calling ...

Go Back   Application Development Forum > Programming Languages > Python

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-28-2008, 01:00 AM
taghi
Guest
 
Default calling NetShareEnum win32api with ctypes

I want to call NetShareEnum, a function from netapi32.dll
NetShareEnum has this definition:

NET_API_STATUS NetShareEnum(
__in LPWSTR servername,
__in DWORD level,
__out LPBYTE *bufptr,
__in DWORD prefmaxlen,
__out LPDWORD entriesread,
__out LPDWORD totalentries,
__inout LPDWORD resume_handle
);

I wrote this code in python 2.5:

from ctypes import *

cname=c_wchar_p('a-computer-name')
level=c_int(1)
bufptr=create_string_buffer('\00', 10000)
prefmaxlen=c_int(9999)
entriesread=c_long(0)
totalentries=c_long(0)
resume=c_long(0)

netapi32=cdll.LoadLibrary('netapi32.dll')
netapi32.NetShareEnum(cname, level, byref(bufptr), prefmaxlen,
byref(entriesread), byref(totalentries), byref(resume))

but I get this error:
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
s.NetShareEnum(name, level, byref(bufptr), prefmaxlen,
entriesread, totalentries, resume)
ValueError: Procedure called with not enough arguments (28 bytes
missing) or wrong calling convention

entriesread and totalentries has valid values after call but bufptr is
not.
I pass bufptr to function instead of byref(bufptr) but the error was
same.
Reply With Quote
  #2  
Old 08-28-2008, 03:53 AM
Tim Golden
Guest
 
Default Re: calling NetShareEnum win32api with ctypes

taghi wrote:
> I want to call NetShareEnum, a function from netapi32.dll


Not a straightforward answer but... are you aware that
this particular call is already wrapped by the pywin32
packages:

https://sourceforge.net/projects/pywin32/

http://timgolden.me.uk/pywin32-docs/...Enum_meth.html

TJG

PS Is it me or is SourceForge's latest redesign actually
less useful than its last one?
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:26 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.