pb de "type"
Le
Alni
Bonjour,
J'ai un petit soucis avec les types.
(Je suis sous VC++ 5.0)
//J'importe une dll de manipulation des objet COM d'un serveur ISA
#import "C:\Program Files\Microsoft ISA Server\msfpccom.dll"
//Je déclare mes objets :
DWORD dwRet = 0;
HRESULT hr = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED );
if (SUCCEEDED (hr) )
{
FPCLib::IFPCPtr fpcRoot;
FPCLib::IFPCArraysPtr fpcArrays;
FPCLib::IFPCArrayPtr fpcArray;
FPCLib::IFPCServersPtr fpcServers;
FPCLib::IFPCWebSessionPtr fpcWebSession;
FPCLib::IFPCWebSessionsPtr fpcWebSessions;
FPCLib::IFPCServerPtr fpcServer;
FPCLib::IFPCFirewallSessionsPtr fpcFirewallSessions;
FPCLib::IFPCFirewallSessionPtr fpcFirewallSession;
FPCLib::IFPCDestinationSetsPtr fpcDestinationSets;
FPCLib::IFPCDestinationSetPtr fpcDestinationSet;
FPCLib::IFPCDestinationPtr fpcDestination;
// J'obtiens le pointeur sur l'objet ISA
hr = fpcRoot.CreateInstance("FPC.Root");
// Ensuite, je parviens à parcourir la config de mon serveur en utilisant
les
membres de cet objet fpcRoot.
// Sauf ici ou je ne parviens pas à me débrouiller a faire un switch/case à
partir du résultat fourni par une fonction membre d'un des objets.
for (long l=1;l<=fpcDestinationSet->Count;l++)
{
fpcDestination=fpcDestinationSet->Item(_variant_t(l),(BSTR) NULL
,(BSTR) NULL );
switch ( fpcDestination->Type ) //*ICI* ça coince
// On peut aussi utiliser ->GetType() même punition
{
case 0 :
printf ("\t\tDomaine : %-20s ", (char*)
fpcDestination->DomainName);
break;
case 1 :
printf ("\t\tAdresse IP : %-20s ", (char*)
fpcDestination->IP_From);
break;
default :
printf ("\t\tDomaine + URL on verra après.");
}
}
-
J'ai une erreur :
error C2450: switch expression of type 'struct FPCLib::IFPCDestination *' is
illegal Integral expression required
nb : Mon objet destination est bien valide, car si je ne mets que des
destinations de type "domain" dans mon destinationSet, alors je peux les
afficher avec :
printf ("\t\tDomaine : %-20s ", (char*)
fpcDestination->DomainName);
Sans switch/case pour gerer le type.
Le membre Type d'un objet Destination est défini ici dans le msdn
http://msdn.microsoft.com/library/d...2_92ex.asp
Et de ce que j'en ai compris, il renvoie une valeur comprise entre 0 et 2
selon le type de l'objet destination.
enum FpcDestinationAddressType {
fpcDestinationTypeDomain,
fpcDestinationTypeSingleIp,
fpcDestinationTypeIpRange
};
Dans le fichier .tli obtenu par l'import de la dll je trouve :
#pragma implementation_key(447)
inline enum FpcDestinationAddressType FPCLib::IFPCDestination::GetType ( ) {
enum FpcDestinationAddressType _result;
HRESULT _hr = get_Type(&_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _result;
}
le keyword switch requiert un int, mais je n'arrive pas à "caster" ce qui
est renvoyé par cette fonction en un int.
Si je cast en int alors j'ai :
switch ( (int) fpcDestination->Type )
msfpccom.tli(3554) : error C2556: 'GetType' : overloaded functions only
differ by return type
msfpccom.tli(3554) : error C2371: 'GetType' : redefinition; different basic
types
Pourquoi donc ?
J'ai un petit soucis avec les types.
(Je suis sous VC++ 5.0)
//J'importe une dll de manipulation des objet COM d'un serveur ISA
#import "C:\Program Files\Microsoft ISA Server\msfpccom.dll"
//Je déclare mes objets :
DWORD dwRet = 0;
HRESULT hr = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED );
if (SUCCEEDED (hr) )
{
FPCLib::IFPCPtr fpcRoot;
FPCLib::IFPCArraysPtr fpcArrays;
FPCLib::IFPCArrayPtr fpcArray;
FPCLib::IFPCServersPtr fpcServers;
FPCLib::IFPCWebSessionPtr fpcWebSession;
FPCLib::IFPCWebSessionsPtr fpcWebSessions;
FPCLib::IFPCServerPtr fpcServer;
FPCLib::IFPCFirewallSessionsPtr fpcFirewallSessions;
FPCLib::IFPCFirewallSessionPtr fpcFirewallSession;
FPCLib::IFPCDestinationSetsPtr fpcDestinationSets;
FPCLib::IFPCDestinationSetPtr fpcDestinationSet;
FPCLib::IFPCDestinationPtr fpcDestination;
// J'obtiens le pointeur sur l'objet ISA
hr = fpcRoot.CreateInstance("FPC.Root");
// Ensuite, je parviens à parcourir la config de mon serveur en utilisant
les
membres de cet objet fpcRoot.
// Sauf ici ou je ne parviens pas à me débrouiller a faire un switch/case à
partir du résultat fourni par une fonction membre d'un des objets.
for (long l=1;l<=fpcDestinationSet->Count;l++)
{
fpcDestination=fpcDestinationSet->Item(_variant_t(l),(BSTR) NULL
,(BSTR) NULL );
switch ( fpcDestination->Type ) //*ICI* ça coince
// On peut aussi utiliser ->GetType() même punition
{
case 0 :
printf ("\t\tDomaine : %-20s ", (char*)
fpcDestination->DomainName);
break;
case 1 :
printf ("\t\tAdresse IP : %-20s ", (char*)
fpcDestination->IP_From);
break;
default :
printf ("\t\tDomaine + URL on verra après.");
}
}
-
J'ai une erreur :
error C2450: switch expression of type 'struct FPCLib::IFPCDestination *' is
illegal Integral expression required
nb : Mon objet destination est bien valide, car si je ne mets que des
destinations de type "domain" dans mon destinationSet, alors je peux les
afficher avec :
printf ("\t\tDomaine : %-20s ", (char*)
fpcDestination->DomainName);
Sans switch/case pour gerer le type.
Le membre Type d'un objet Destination est défini ici dans le msdn
http://msdn.microsoft.com/library/d...2_92ex.asp
Et de ce que j'en ai compris, il renvoie une valeur comprise entre 0 et 2
selon le type de l'objet destination.
enum FpcDestinationAddressType {
fpcDestinationTypeDomain,
fpcDestinationTypeSingleIp,
fpcDestinationTypeIpRange
};
Dans le fichier .tli obtenu par l'import de la dll je trouve :
#pragma implementation_key(447)
inline enum FpcDestinationAddressType FPCLib::IFPCDestination::GetType ( ) {
enum FpcDestinationAddressType _result;
HRESULT _hr = get_Type(&_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _result;
}
le keyword switch requiert un int, mais je n'arrive pas à "caster" ce qui
est renvoyé par cette fonction en un int.
Si je cast en int alors j'ai :
switch ( (int) fpcDestination->Type )
msfpccom.tli(3554) : error C2556: 'GetType' : overloaded functions only
differ by return type
msfpccom.tli(3554) : error C2371: 'GetType' : redefinition; different basic
types
Pourquoi donc ?

Poser une question


FPCLib::IFPCDestinationSetPtr::Type est de type
FPCLib::IFPCDestination *. Un switch requière un type entier.
--drkm, en recherche d'un stage : http://www.fgeorges.org/ipl/stage.html
Bah... Normalement cette fonction ne renvoie pas un pointeur, mais une
valeur comprise entre 0 et 2. Selon cette définition :
enum FpcDestinationAddressType {
fpcDestinationTypeDomain,
fpcDestinationTypeSingleIp,
fpcDestinationTypeIpRange
};
La doc de la fonction Type pour l'objet Destination se trouve là sur cette
page :
http://msdn.microsoft.com/library/d...2_92ex.asp
nb : en vbs cela s'utilise de cette façon (vu dans un script qui
fonctionne):
'Destination set info
Const Domain = 0
Const SingleIP = 1
Const IPRange = 2
Dim Dtype
For Each Destination in DestinationSet
DType = Destination.Type
Select Case DType
Case Domain
../..
Case SingleIP
../..
Case IPRange
.../..
End Select
Next
Se pourrait il que mon compilo déconne pour penser que cette fonction revoie
un pointeur alors que c'est une valeur entre 0 et 2, et que pourtant dans
les fichiers tli et tlh générés par l'import de la dll je retrouve bien :
#pragma implementation_key(447)
inline enum FpcDestinationAddressType FPCLib::IFPCDestination::GetType ( ) {
enum FpcDestinationAddressType _result;
HRESULT _hr = get_Type(&_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _result;
}
Une chose de ce genre ne marcherait pas mieux ? (non testé)
HRESULT hr;
FpcDestinationAddressType DestType;
hr = fpcDestination->get_Type(&DestType);
if (FAILED(hr)) TraitementErreur();
switch(DestType)
{
case...
Eric
_92ex.asp
Non, 'Type' n'est pas une fonction, mais une propriete qui masque
un acces a GetType() ou SetType(). C'est une extension Microsoft
au langage C++.
MB