Structure with another structure inside it in python ctypes

0

I'm developing a ratchet control software, it uses a dll called xpcomlib, and has examples made in C. I'm developing in Python and for using the DLL I'm using Ctypes, I've been able to make DLL functions work almost all but one, it needs one pointeiro for one structure and in that structure it has another. Let's make it clearer

Follows part of the manual

int FAR PASCAL FXPBasicConvFromText(
  const char FAR* szFileOrig, // Nome do arquivo origem a ser convertido
  const char FAR* szFileDest, // Nome do arquivo destino a ser gerado
  CONVFILEFORMAT FAR* pF // Ponteiro p/ estrutura com formato arquivo origem
);

The 'pF' argument is a pointer to a structure of type CONVFILEFORMAT that defines the format of the source file. cFields The number of fields in the source file must be between 1 and 10. For each of the 'cFields' above fields we have the 'Field' structure defined by:

struct {
cName[11]       Nome do campo só para conversões com arquivo destino tipo DBF
cType           Tipo do campo XPFLD_INT, XPFLD_FLO, XPFLD_STR. Ver XPCOMxx.H.
cLength         Comprimento do campo
cDec            Número de casas decimais usado para ponto flutuante na conversão de arquivos
formato XPbasic para formato DBASE
} Field[10];

Example made in the manual

#include <windows.h>
#include <string.h>
#include “xpcom16.h”
char szInFile[20];
char szOutFile[20];
CONVFILEFORMAT fF;
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
fF.cFields = 3;
fF.Field[0].cType = XPFLD_STR;
fF.Field[0].cLength = 80;
fF.Field[0].cDec = 0;
fF.Field[1].cType = XPFLD_INT;
fF.Field[1].cLength = 2;
fF.Field[1].cDec = 0;
fF.Field[2].cType = XPFLD_FLO;
fF.Field[2].cLength = 8;
fF.Field[2].cDec = 0;
strcpy(szInFile, “C:\TRIX\ARQTXT.DAT”);
strcpy(szOutFile, “C:\TRIX\ARQXPB.DAT”);
if (FXPBasicConvFromText(szInFile, szOutFile, &fF))
return FALSE;
return TRUE;
}

Given this, I need to make use of the dll in python, so far I have done this

class ConvFileField(ctypes.Structure):
    _fields_ = [("cName", ctypes.c_char_p), ("cType", ctypes.c_byte), ("cLength", ctypes.c_byte), ("cDec", ctypes.c_byte)]

class Struct(ctypes.Structure):
    _fields_ = [("cFields", ctypes.c_byte), ("Field", ctypes.POINTER(ConvFileField))]   

    elems = (ConvFileField * 10)()
    Field = ctypes.cast(elems, ctypes.POINTER(ConvFileField))

formatPointer = ctypes.POINTER(Struct)
formatPointer.cFields = 0 #Funciona
formatPointer.Field[0].cType = 1 #Da problema

But I get the following error saying that my structure does not contain the Field field, with cFields above running normal.

  

formatPointer.Field [0] .cType = 1 AttributeError: type object   'LP_Struct' has no attribute 'Field'

    
asked by anonymous 25.10.2018 / 19:45

0 answers