Problème de transfert d'un bout de code dans une procédure
Publié : dim. 17/avr./2005 22:35
Bonsoir,
Je m'arrache les cheveux en essayant de comprendre pourquoi, quand j'intègre le programme principal ci-dessous dans une procédure, il ne marche plus
(Rien ne se passe).
J'ai mis en commentaire le début et la fin de ma procédure, pour vous donner une idée de la façon dont je procédais... c'est peut être là que je me plante ?
Toute aide sera la bienvenue, d'avance un grand merci à ceux qui passeront un peu de temps à m'aider ! Je suis en 3.93, pour info.
Nico.
Je m'arrache les cheveux en essayant de comprendre pourquoi, quand j'intègre le programme principal ci-dessous dans une procédure, il ne marche plus

J'ai mis en commentaire le début et la fin de ma procédure, pour vous donner une idée de la façon dont je procédais... c'est peut être là que je me plante ?
Toute aide sera la bienvenue, d'avance un grand merci à ceux qui passeront un peu de temps à m'aider ! Je suis en 3.93, pour info.
Nico.
Code : Tout sélectionner
Procedure.l ansi2bstr(ansi.s)
size.l=MultiByteToWideChar_(#CP_ACP,0,ansi,-1,0,0)
Dim unicode.w(size)
MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), size)
ProcedureReturn SysAllocString_(@unicode())
EndProcedure
Procedure.s unicode2ansi(mem)
ansi.s=""
Repeat
a=PeekW(mem)
ansi=ansi+Chr(a)
mem+2
Until a=0
ProcedureReturn ansi
EndProcedure
; ------------------------------------------------------------
; OS_info
; ------------------------------------------------------------
;Procedure OS_info()
;_______________ données_________________________
DataSection
CLSID_WbemLocator:
;4590f811-1d3a-11d0-891f-00aa004b2e24
Data.l $4590F811
Data.w $1D3A, $11D0
Data.b $89, $1F, $00, $AA, $00, $4B, $2E, $24
IID_IWbemLocator:
;dc12a687-737f-11cf-884d-00aa004b2e24
Data.l $DC12A687
Data.w $737F, $11CF
Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24
IID_IUnknown:
;00000000-0000-0000-C000-000000000046
Data.l $00000000
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
IID_IWbemRefresher:
;49353c99-516b-11d1-aea6-00c04fb68820
Data.l $49353C99
Data.w $516B, $11D1
Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20
CLSID_WbemRefresher:
;c71566f2-561E-11D1-AD87-00C04FD8FDFF
Data.l $C71566F2
Data.w $561E, $11D1
Data.b $AD,$87,$00,$C0,$4F,$D8,$FD,$FF
IID_IWbemConfigureRefresher:
;49353c92-516b-11d1-aea6-00c04fb68820
Data.l $49353C92
Data.w $516B, $11D1
Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20
IID_IWbemObjectAccess:
;49353c9a-516b-11d1-aea6-00c04fb68820
Data.l $49353C9A
Data.w $516B, $11D1
Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20
EndDataSection
#COINIT_MULTITHREAD=0
#RPC_C_AUTHN_LEVEL_CONNECT=2
#RPC_C_IMP_LEVEL_IDENTIFY=2
#EOAC_NONE=0
#RPC_C_AUTHN_WINNT=10
#RPC_C_AUTHZ_NONE=0
#RPC_C_AUTHN_LEVEL_CALL=3
#RPC_C_IMP_LEVEL_IMPERSONATE=3
#CLSCTX_INPROC_SERVER=1
#WBEM_S_NO_ERROR = 0
Structure d
l.l
h.l
EndStructure
; ___________________ Initialisations __________________________
; partout, hres doit être nul si pas d'erreur
CoInitializeEx_(0,#COINIT_MULTITHREAD)
hres=CoInitializeSecurity_(0, -1,0,0,#RPC_C_AUTHN_LEVEL_CONNECT,#RPC_C_IMP_LEVEL_IDENTIFY,0,#EOAC_NONE,0)
hres=CoCreateInstance_(?CLSID_WbemLocator,0,#CLSCTX_INPROC_SERVER,?IID_IWbemLocator,@loc.IWbemLocator)
hres=loc\ConnectServer(ansi2bstr("root\cimv2"),0,0,0,0,0,0,@svc.IWbemServices)
hres=svc\queryinterface(?IID_IUnknown,@pUnk.IUnknown)
hres=CoSetProxyBlanket_(svc,#RPC_C_AUTHN_WINNT,#RPC_C_AUTHZ_NONE,0,#RPC_C_AUTHN_LEVEL_CALL,#RPC_C_IMP_LEVEL_IMPERSONATE,0,#EOAC_NONE)
hres=CoSetProxyBlanket_(pUnk,#RPC_C_AUTHN_WINNT,#RPC_C_AUTHZ_NONE,0,#RPC_C_AUTHN_LEVEL_CALL,#RPC_C_IMP_LEVEL_IMPERSONATE,0,#EOAC_NONE)
pUnk\release()
hres=CoCreateInstance_(?CLSID_WbemRefresher,0,#CLSCTX_INPROC_SERVER,?IID_IWbemRefresher,@pRefresher.IWbemRefresher)
hres=pRefresher\queryinterface(?IID_IWbemConfigureRefresher,@pConfig.IWbemConfigureRefresher)
hres=pConfig\AddEnum(svc,ansi2bstr("Win32_OperatingSystem"),0,0,@penum.IWbemHiPerfEnum,@id)
pConfig\release()
Dim tab.IWbemObjectAccess(100)
For x=1 To 2
pRefresher\refresh(0)
hres=penum\GetObjects(0,100*SizeOf(IWbemObjectAccess),@tab(),@retour.l)
If x=1
hres=tab(0)\GetPropertyHandle(ansi2bstr("Name"),0,@info)
EndIf
If x>1
*MemoryID = AllocateMemory(500)
For i=0 To retour-1
tab(i)\Readpropertyvalue(info,500,@len,*MemoryID)
result$=(unicode2ansi(*MemoryID))
ZeroMemory_(*MemoryID,500)
tab(i)\release()
Next i
FreeMemory(*MemoryID)
EndIf
Delay(500)
Next
penum\release()
pRefresher\release();
svc\release()
loc\release()
CoUninitialize_()
MessageRequester("OS", result$, #MB_OK)
;EndProcedure
;OS_info()