PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → API CreateFileA
API CreateFileA
Débuté par Olivier, 21 juil. 2004 19:30 - 3 réponses
Posté le 21 juillet 2004 - 19:30
Je dois récupérer le handle d'un fichier et j'ai trouvé la fonction CreateFileA
mais j'ai des problèmes avec les paramètres. J'ai essayé différentes possibilités
dont la suivante mais je ne trouve pas la solution. Quelqu'un pourrait m'aider?
hFile = AppelDLL32("KERNEL32","CreateFileA","C:\Texte.txt", "GENERIC_READ",
"FILE_SHARE_READ",Null,"CREATE_ALWAYS","FILE_ATTRIBUTE_NORMAL",Null)

Merci d'avance
Posté le 22 juillet 2004 - 10:07
Initialisation du projet :

//********************** Déclaration des structures nécessaires à la fonction
de l'API <CreateFileA> :
SECURITY_ATTRIBUTES est une structure
nLength est un entier //Type C : DWORD
lpSecurityDescriptor est un entier //Type C : LPVOID
bInheritHandle est un booléen //Type C : BOOL
FIN
//********************** Fin de la déclaration des structures pour <CreateFileA>

CONSTANT
GENERIC_READ = 0x80000000
FILE_SHARE_READ = 0x00000001
CREATE_ALWAYS = 2
FILE_ATTRIBUTE_NORMAL = 0x00000080
FIN

Code :

hfile est entier
ST est un SECURITY_ATTRIBUTES

RetourFonction est un entier // Type C :HANDLE
lpFileName est un entier // Type C :LPCSTR, c'est l'adresse d'une chaîne,
il est aussi possible de spécifier directement une chaîne
lchFileName est chaîne
dwDesiredAccess est un entier // Type C :DWORD
dwShareMode est un entier // Type C :DWORD
lpSecurityAttributes est un entier // Pointeur sur structure LPSECURITY_ATTRIBUTES
dwCreationDisposition est un entier // Type C :DWORD
dwFlagsAndAttributes est un entier // Type C :DWORD
hTemplateFile est un entier // Type C :HANDLE

lchFileName = "C:\Texte.txt"
lpFileName = &lchFileName
dwDesiredAccess = GENERIC_READ
dwShareMode = FILE_SHARE_READ
lpSecurityAttributes = &ST
dwCreationDisposition = CREATE_ALWAYS
dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL
hTemplateFile = Null
RetourFonction=API("KERNEL32","CreateFileA",lpFileName,dwDesiredAccess,dwShareMode,lpSecurityAttributes,dwCreationDisposition,dwFlagsAndAttributes,hTemplateFile)

fOuvre fait la même chose !!!

Bon Dev.

Yann

"Olivier" <olivier.tosi@aproz.ch> wrote:


Je dois récupérer le handle d'un fichier et j'ai trouvé la fonction CreateFileA
mais j'ai des problèmes avec les paramètres. J'ai essayé différentes possibilités
dont la suivante mais je ne trouve pas la solution. Quelqu'un pourrait m'aider?
hFile = AppelDLL32("KERNEL32","CreateFileA","C:\Texte.txt", "GENERIC_READ",
"FILE_SHARE_READ",Null,"CREATE_ALWAYS","FILE_ATTRIBUTE_NORMAL",Null)

Merci d'avance
Posté le 22 juillet 2004 - 10:48
Ok Yann, merci beaucoup, ça fonctionne bien.
Seulement pourrais-tu me dire comment tu as trouvé, ou où tu as trouvé les
valeurs des différents paramètres (ex. FILE_ATTRIBUTE_NORMAL = 128?

"Yann" <ywagner@worldcom.ch> wrote:


Initialisation du projet :

//********************** Déclaration des structures nécessaires à la fonction
de l'API <CreateFileA> :
SECURITY_ATTRIBUTES est une structure
nLength est un entier //Type C : DWORD
lpSecurityDescriptor est un entier //Type C : LPVOID
bInheritHandle est un booléen //Type C : BOOL
FIN
//********************** Fin de la déclaration des structures pour <CreateFileA>

CONSTANT
GENERIC_READ = 0x80000000
FILE_SHARE_READ = 0x00000001
CREATE_ALWAYS = 2
FILE_ATTRIBUTE_NORMAL = 0x00000080
FIN

Code :

hfile est entier
ST est un SECURITY_ATTRIBUTES

RetourFonction est un entier // Type C :HANDLE
lpFileName est un entier // Type C :LPCSTR, c'est l'adresse d'une chaîne,
il est aussi possible de spécifier directement une chaîne
lchFileName est chaîne
dwDesiredAccess est un entier // Type C :DWORD
dwShareMode est un entier // Type C :DWORD
lpSecurityAttributes est un entier // Pointeur sur structure LPSECURITY_ATTRIBUTES
dwCreationDisposition est un entier // Type C :DWORD
dwFlagsAndAttributes est un entier // Type C :DWORD
hTemplateFile est un entier // Type C :HANDLE

lchFileName = "C:\Texte.txt"
lpFileName = &lchFileName
dwDesiredAccess = GENERIC_READ
dwShareMode = FILE_SHARE_READ
lpSecurityAttributes = &ST
dwCreationDisposition = CREATE_ALWAYS
dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL
hTemplateFile = Null
RetourFonction=API("KERNEL32","CreateFileA",lpFileName,dwDesiredAccess,dwShareMode,lpSecurityAttributes,dwCreationDisposition,dwFlagsAndAttributes,hTemplateFile)

fOuvre fait la même chose !!!

Bon Dev.

Yann

"Olivier" <olivier.tosi@aproz.ch> wrote:


Je dois récupérer le handle d'un fichier et j'ai trouvé la fonction CreateFileA
mais j'ai des problèmes avec les paramètres. J'ai essayé différentes possibilités
dont la suivante mais je ne trouve pas la solution. Quelqu'un pourrait

m'aider?
hFile = AppelDLL32("KERNEL32","CreateFileA","C:\Texte.txt", "GENERIC_READ",
"FILE_SHARE_READ",Null,"CREATE_ALWAYS","FILE_ATTRIBUTE_NORMAL",Null)

Merci d'avance

Posté le 23 juillet 2004 - 14:18
Dans les outils Windev, programme WDAPI, onglets constantes

A+

Yann


"Olivier" <olivier.tosi@aproz.ch> wrote:


Ok Yann, merci beaucoup, ça fonctionne bien.
Seulement pourrais-tu me dire comment tu as trouvé, ou où tu as trouvé les
valeurs des différents paramètres (ex. FILE_ATTRIBUTE_NORMAL = 128?

"Yann" <ywagner@worldcom.ch> wrote:


Initialisation du projet :

//********************** Déclaration des structures nécessaires à la fonction
de l'API <CreateFileA> :
SECURITY_ATTRIBUTES est une structure
nLength est un entier //Type C : DWORD
lpSecurityDescriptor est un entier //Type C : LPVOID
bInheritHandle est un booléen //Type C : BOOL
FIN
//********************** Fin de la déclaration des structures pour <CreateFileA>

CONSTANT
GENERIC_READ = 0x80000000
FILE_SHARE_READ = 0x00000001
CREATE_ALWAYS = 2
FILE_ATTRIBUTE_NORMAL = 0x00000080
FIN

Code :

hfile est entier
ST est un SECURITY_ATTRIBUTES

RetourFonction est un entier // Type C :HANDLE
lpFileName est un entier // Type C :LPCSTR, c'est l'adresse d'une chaîne,
il est aussi possible de spécifier directement une chaîne
lchFileName est chaîne
dwDesiredAccess est un entier // Type C :DWORD
dwShareMode est un entier // Type C :DWORD
lpSecurityAttributes est un entier // Pointeur sur structure LPSECURITY_ATTRIBUTES
dwCreationDisposition est un entier // Type C :DWORD
dwFlagsAndAttributes est un entier // Type C :DWORD
hTemplateFile est un entier // Type C :HANDLE

lchFileName = "C:\Texte.txt"
lpFileName = &lchFileName
dwDesiredAccess = GENERIC_READ
dwShareMode = FILE_SHARE_READ
lpSecurityAttributes = &ST
dwCreationDisposition = CREATE_ALWAYS
dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL
hTemplateFile = Null
RetourFonction=API("KERNEL32","CreateFileA",lpFileName,dwDesiredAccess,dwShareMode,lpSecurityAttributes,dwCreationDisposition,dwFlagsAndAttributes,hTemplateFile)

fOuvre fait la même chose !!!

Bon Dev.

Yann

"Olivier" <olivier.tosi@aproz.ch> wrote:


Je dois récupérer le handle d'un fichier et j'ai trouvé la fonction CreateFileA
mais j'ai des problèmes avec les paramètres. J'ai essayé différentes possibilités
dont la suivante mais je ne trouve pas la solution. Quelqu'un pourrait
m'aider?

hFile = AppelDLL32("KERNEL32","CreateFileA","C:\Texte.txt", "GENERIC_READ",
"FILE_SHARE_READ",Null,"CREATE_ALWAYS","FILE_ATTRIBUTE_NORMAL",Null)

Merci d'avance