MACRO Plantage à l'éxecution

Bonjour a tous,

J'ai un souci avec une macro qui plante LO à chaque éxecution
Je suis sous Windows 7 avec une version LO 4.0.2

Voici le code qui me permet de récupérer le nom du PC par accès à la base de registre.

Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
(ByVal hKey As Long, _
  ByVal lpSubKey As String, _
  ByVal ulOptions As Long, _
  ByVal samDesired As Long, _
  phkResult As Long) As Long

Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" _
(ByVal hKey As Long, _
  ByVal lpValueName As String, _
  ByVal lpReserved As Long, _
  lpType As Long, _
  lpData As String, _
  lpcbData As Long) As Long

Declare Function RegQueryValueString Lib "advapi32.dll" Alias "RegQueryValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal dwReserved As Long, _
lpType As Long, _
ByVal lpData As String, _
lpcbData As Long) As Long

Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" _
(ByVal hKey As Long, _
  ByVal lpValueName As String, _
  ByVal lpReserved As Long, _
  lpType As Long, _
  ByVal lpData As Long, _
  lpcbData As Long) As Long

Declare Function RegCloseKeyA Lib "advapi32.dll" Alias "RegCloseKey" _
(ByVal hKey As Long) As Long

sub Main

Dim NomPC as string
Const HKLM = &H80000002
Dim hKey as Long
Dim lType as Long
Dim cch as Long

Dim RetourBR as Long
Dim RetourBR1 as Long
Dim RetourBR2 as Long
Dim RetourBR3 as Long

RetourBR = RegOpenKeyEx(HKLM,"SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", 0, &H20019, hKey)
RetourBR1 = RegQueryValueExNULL(hKey, "ComputerName", 0&, lType, 0&, cch)
RetourBR2 = RegQueryValueString(hKey, "ComputerName", 0&, lType, NomPC, cch)
RetourBR3 = RegCloseKeyA(hKey)

print NomPC

End Sub

Ce code fonctionne correctement mais plante systèmatiquement LO. Après pas mal d'essais je me suis apperçu que c'est la ligne suivante qui fait planter LO
RetourBR2 = RegQueryValueString(hKey, "ComputerName", 0&, lType, NomPC, cch)

Merci pour toute aide car là je sèche

Sincères Salutations

F. SEGUIN

Bonjour

SEGUIN François wrote

J'ai un souci avec une macro qui plante LO à chaque éxecution
Je suis sous Windows 7 avec une version LO 4.0.2

Voici le code qui me permet de récupérer le nom du PC par accès à la base
de registre.

Peut-être un problème de niveau de sécurité (droit d'exécution)
Je n'ai pas de 7 sous la main pour tester là tout de suite...

Toutefois, je me demande pourquoi tu n'utilises pas simplement:

print environ("COMPUTERNAME")

Cordialement
Pierre-Yves