#NEWLINE# def load_resource_pystr( py , filename , resname , resid , reslang ) : #NEWLINE# #INDENT# 'Load the named resource from the given file as a python-level string\n\n    The filename and resource name must be ascii strings, and the resid and\n    reslang must be integers.\n\n    This uses the given python dll object to load the data directly into \n    a python string, saving a lot of copying and carrying on.\n    ' #NEWLINE# l_handle = k32_LoadLibraryExA ( filename , rffi . cast ( rwin32 . HANDLE , 0 ) , LOAD_LIBRARY_AS_DATAFILE ) #NEWLINE# if ( not l_handle ) : #NEWLINE# #INDENT# raise WindowsError ( rwin32 . GetLastError ( ) , 'LoadLibraryExW failed' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# r_handle = k32_FindResourceExA ( l_handle , resname , resid , reslang ) #NEWLINE# if ( not r_handle ) : #NEWLINE# #INDENT# raise WindowsError ( rwin32 . GetLastError ( ) , 'FindResourceExA failed' ) #NEWLINE# #UNINDENT# r_size = k32_SizeofResource ( l_handle , r_handle ) #NEWLINE# if ( not py ) : #NEWLINE# #INDENT# raise WindowsError ( rwin32 . GetLastError ( ) , 'SizeofResource failed' ) #NEWLINE# #UNINDENT# r_info = k32_LoadResource ( l_handle , r_handle ) #NEWLINE# if ( not r_info ) : #NEWLINE# #INDENT# raise WindowsError ( rwin32 . GetLastError ( ) , 'LoadResource failed' ) #NEWLINE# #UNINDENT# r_ptr = k32_LockResource ( r_info ) #NEWLINE# if ( not r_ptr ) : #NEWLINE# #INDENT# raise WindowsError ( rwin32 . GetLastError ( ) , 'LockResource failed' ) #NEWLINE# #UNINDENT# s = py . String_FromStringAndSize ( None , r_size ) #NEWLINE# buf = py . String_AsString ( s ) #NEWLINE# memcpy ( buf , rffi . cast ( rffi . VOIDP , r_ptr ) , r_size ) #NEWLINE# return s #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# if ( not k32_FreeLibrary ( l_handle ) ) : #NEWLINE# #INDENT# raise WindowsError ( rwin32 . GetLastError ( ) , 'FreeLibrary failed' )