IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Discussion :

Structure avec fonction dedans


Sujet :

Windows

  1. #1
    Membre du Club
    Inscrit en
    Juillet 2008
    Messages
    117
    Détails du profil
    Informations forums :
    Inscription : Juillet 2008
    Messages : 117
    Points : 58
    Points
    58
    Par défaut Structure avec fonction dedans
    Bonjour, alors voila j'ai un petit peu de mal a comprendre une structure comprenant des pointeurs sur fonction (habituellement j'utilise les pointeurs sur fonction dans un tableau).
    J'aurais donc voulu savoir et comprendre comment utiliser cette structure :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
        typedef struct IProcessVtbl
        {
            BEGIN_INTERFACE
    
            HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
                IProcess * This,
                /* [in] */ REFIID riid,
                /* [iid_is][out] */ void **ppvObject);
    
            ULONG ( STDMETHODCALLTYPE *AddRef )(
                IProcess * This);
    
            ULONG ( STDMETHODCALLTYPE *Release )(
                IProcess * This);
    
            HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )(
                IProcess * This,
                /* [out] */ UINT *pctinfo);
    
            HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )(
                IProcess * This,
                /* [in] */ UINT iTInfo,
                /* [in] */ LCID lcid,
                /* [out] */ ITypeInfo **ppTInfo);
    
            HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )(
                IProcess * This,
                /* [in] */ REFIID riid,
                /* [size_is][in] */ LPOLESTR *rgszNames,
                /* [in] */ UINT cNames,
                /* [in] */ LCID lcid,
                /* [size_is][out] */ DISPID *rgDispId);
    
            /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )(
                IProcess * This,
                /* [in] */ DISPID dispIdMember,
                /* [in] */ REFIID riid,
                /* [in] */ LCID lcid,
                /* [in] */ WORD wFlags,
                /* [out][in] */ DISPPARAMS *pDispParams,
                /* [out] */ VARIANT *pVarResult,
                /* [out] */ EXCEPINFO *pExcepInfo,
                /* [out] */ UINT *puArgErr);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_AutoSave )(
                IProcess * This,
                /* [retval][out] */ VARIANT_BOOL *AutoSave);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_AutoSave )(
                IProcess * This,
                /* [in] */ VARIANT_BOOL AutoSave);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *CreateDocument )(
                IProcess * This,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *OpenDocument )(
                IProcess * This,
                /* [in] */ BSTR Filename,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *SaveDocument )(
                IProcess * This,
                /* [in] */ BSTR Filename,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *PrintImages )(
                IProcess * This,
                /* [in] */ short FirstPage,
                /* [in] */ short LastPage,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *PrintText )(
                IProcess * This,
                /* [in] */ short FirstPage,
                /* [in] */ short LastPage,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_TTSStatus )(
                IProcess * This,
                /* [retval][out] */ VARIANT_BOOL *Avail);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_TTSEnabled )(
                IProcess * This,
                /* [retval][out] */ VARIANT_BOOL *Enabled);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_TTSEnabled )(
                IProcess * This,
                /* [in] */ VARIANT_BOOL Enabled);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *ReadDocument )(
                IProcess * This,
                /* [in] */ short Page,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *StopReading )(
                IProcess * This,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_DocModifiedFlag )(
                IProcess * This,
                /* [retval][out] */ VARIANT_BOOL *Modified);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_PageCount )(
                IProcess * This,
                /* [retval][out] */ long *Modified);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *ImportImage )(
                IProcess * This,
                BSTR Filename);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *LoadImages )(
                IProcess * This,
                /* [in] */ BSTR Filename,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_ImageSource )(
                IProcess * This,
                /* [retval][out] */ IMGSRC *IMGSRC);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_ImageSource )(
                IProcess * This,
                /* [in] */ IMGSRC IMGSRC);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_INSERTMODE )(
                IProcess * This,
                /* [retval][out] */ INSERTMODE *insertpage);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_INSERTMODE )(
                IProcess * This,
                /* [in] */ INSERTMODE insertpage);
    
            /* [id] */ HRESULT ( STDMETHODCALLTYPE *StartAddImage )(
                IProcess * This,
                /* [in] */ short w,
                /* [in] */ short h,
                /* [in] */ short bpp,
                /* [in] */ short xres,
                /* [in] */ short yres,
                /* [in] */ short align,
                /* [retval][out] */ long *pError);
    
            /* [id] */ HRESULT ( STDMETHODCALLTYPE *AddImageData )(
                IProcess * This,
                /* [in] */ short lineStart,
                /* [in] */ short lineLen,
                /* [in] */ VARIANT vSafeArray,
                /* [in] */ short dataSize,
                /* [retval][out] */ long *pError);
    
            /* [id] */ HRESULT ( STDMETHODCALLTYPE *StopAddImage )(
                IProcess * This,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_LayoutDescription )(
                IProcess * This,
                /* [retval][out] */ LYTDESCR *Layout);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_LayoutDescription )(
                IProcess * This,
                /* [in] */ LYTDESCR *Layout);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_TemplateFilename )(
                IProcess * This,
                /* [retval][out] */ BSTR *Filename);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_TemplateFilename )(
                IProcess * This,
                /* [in] */ BSTR Filename);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_AutoZoneState )(
                IProcess * This,
                /* [retval][out] */ VARIANT_BOOL *Value);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_AutoZoneState )(
                IProcess * This,
                /* [in] */ VARIANT_BOOL Value);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *ZoneImage )(
                IProcess * This,
                /* [in] */ long Flag,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_RejectSymbol )(
                IProcess * This,
                /* [retval][out] */ short *Reject);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_RejectSymbol )(
                IProcess * This,
                /* [in] */ short Reject);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_UserDictionary )(
                IProcess * This,
                /* [retval][out] */ BSTR *UserDict);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_UserDictionary )(
                IProcess * This,
                /* [in] */ BSTR UserDict);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_TrainingFile )(
                IProcess * This,
                /* [retval][out] */ BSTR *Train);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_TrainingFile )(
                IProcess * This,
                /* [in] */ BSTR Train);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *Recognize )(
                IProcess * This,
                /* [in] */ RECMODE Flag,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *ProcessImage )(
                IProcess * This,
                /* [in] */ BSTR ImageFilename,
                /* [in] */ BSTR TextFilename,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Languages )(
                IProcess * This,
                /* [retval][out] */ IDispatch **Languages);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_AutoRotation )(
                IProcess * This,
                /* [retval][out] */ VARIANT_BOOL *autoorient);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_AutoRotation )(
                IProcess * This,
                /* [in] */ VARIANT_BOOL autoorient);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_RetainColor )(
                IProcess * This,
                /* [retval][out] */ RETAINCOLOROPT *pValue);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_RetainColor )(
                IProcess * This,
                /* [in] */ RETAINCOLOROPT pValue);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_AutoProof )(
                IProcess * This,
                /* [retval][out] */ VARIANT_BOOL *pValue);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_AutoProof )(
                IProcess * This,
                /* [in] */ VARIANT_BOOL pValue);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *Proof )(
                IProcess * This,
                /* [in] */ eProofReadFlag Flag,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_ExportTarget )(
                IProcess * This,
                /* [retval][out] */ EXPTRG *pValue);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_ExportTarget )(
                IProcess * This,
                /* [in] */ EXPTRG pValue);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_ExportTextFormat )(
                IProcess * This,
                /* [retval][out] */ VARIANT *ConvID);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_ExportTextFormat )(
                IProcess * This,
                /* [in] */ VARIANT ConvID);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_ExportFormattingLevel )(
                IProcess * This,
                /* [retval][out] */ FMTLVL *pValue);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_ExportFormattingLevel )(
                IProcess * This,
                /* [in] */ FMTLVL pValue);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_TextSeparation )(
                IProcess * This,
                /* [retval][out] */ EXPFILEOPT *pValue);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_TextSeparation )(
                IProcess * This,
                /* [in] */ EXPFILEOPT pValue);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_LaunchOnExport )(
                IProcess * This,
                /* [retval][out] */ VARIANT_BOOL *pValue);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_LaunchOnExport )(
                IProcess * This,
                /* [in] */ VARIANT_BOOL pValue);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_ExportTextFormats )(
                IProcess * This,
                /* [retval][out] */ IDispatch **pValue);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *ExportDocument )(
                IProcess * This,
                /* [in] */ BSTR Filename,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *ExportImageFiles )(
                IProcess * This,
                /* [in] */ BSTR Filename,
                /* [retval][out] */ long *Error);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_ExportImageFormat )(
                IProcess * This,
                /* [retval][out] */ VARIANT *FormatID);
    
            /* [helpstring][propputtypedef struct IProcessVtbl][id] */ HRESULT ( STDMETHODCALLTYPE *put_ExportImageFormat )(
                IProcess * This,
                /* [in] */ VARIANT FormatID);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_ImageSeparation )(
                IProcess * This,
                /* [retval][out] */ IMGFILEOPT *pValue);
    
            /* [helpstring][propput][id] */ HRESULT ( STDMETHODCALLTYPE *put_ImageSeparation )(
                IProcess * This,
                /* [in] */ IMGFILEOPT pValue);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_ImageFormats )(
                IProcess * This,
                /* [in] */ IMAGEFORMATTYPE type,
                /* [retval][out] */ IDispatch **pValue);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *LoadSettings )(
                IProcess * This,
                /* [in] */ BSTR Filename,
                /* [retval][out] */ long *pError);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *SaveSettings )(
                IProcess * This,
                /* [in] */ BSTR Filename,
                /* [retval][out] */ long *pError);
    
            /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *OptionsDialog )(
                IProcess * This,
                /* [in] */ long Flag);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Scanner )(
                IProcess * This,
                /* [retval][out] */ IDispatch **Scanner);
    
            /* [helpstring][propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_LastError )(
                IProcess * This,
                /* [retval][out] */ BSTR *ErrorString);
    
            END_INTERFACE
        } IProcessVtbl;
    
        interface IProcess
        {
            CONST_VTBL struct IProcessVtbl *lpVtbl;
        };
    Elle sort d'un .h généré à partir de visual studio depuis un .tlb (décompiler puis recompilé, encore merci a médinoc d'ailleurs pour l'aide)

  2. #2
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 381
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 381
    Points : 41 582
    Points
    41 582
    Par défaut
    Donc, tu n'as encore jamais utilisé d'objet COM ?
    Ou bien c'est seulement que tu ne les a jamais utilisés en C ?

    Sais-tu au moins ce qu'est un comptage de références intrusif, comme celui utilisé par les objets COM ?

  3. #3
    Rédacteur

    Avatar de ram-0000
    Homme Profil pro
    Consultant en sécurité
    Inscrit en
    Mai 2007
    Messages
    11 517
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultant en sécurité
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mai 2007
    Messages : 11 517
    Points : 50 367
    Points
    50 367
    Par défaut
    Tu as une structure qui s'appelle IProcessVtbl qui contient plein de membres.

    Le 1er de ces membres s'appelle QueryInterface et c'est un pointeur de fonction qui attend 3 paramètres (un IProcess * This, un REFIID riid et un void **ppvObject) et qui retourne un HRESULT.

    etc pour les autres membres.

    Maintenant, comment est renseignée cette structure, je n'en sais rien.

  4. #4
    Membre du Club
    Inscrit en
    Juillet 2008
    Messages
    117
    Détails du profil
    Informations forums :
    Inscription : Juillet 2008
    Messages : 117
    Points : 58
    Points
    58
    Par défaut
    Citation Envoyé par Médinoc Voir le message
    Donc, tu n'as encore jamais utilisé d'objet COM ?
    Ou bien c'est seulement que tu ne les a jamais utilisés en C ?

    Sais-tu au moins ce qu'est un comptage de références intrusif, comme celui utilisé par les objets COM ?
    Non je n'ai jamais utiliser d'objet COM, j'ai fais beaucoup de C et uniquement du C. En ce qui concerne ce .h, c'est a la demande de mon maître de stage que je dois bosser dessus. Donc je suis preneur de toute doc ou autre lien (ce qui n'empêche pas que de mon coté je fasse des recherches).

  5. #5
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 381
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 381
    Points : 41 582
    Points
    41 582
    Par défaut
    C'est fort dommage, car c'est inspiré du C++.
    Les interfaces COM reprennent le principe de la vtable C++, c'est-à-dire que l'interface contient juste un pointeur vers une structure contenant tout plein de pointeurs de fonction.

    À cela s'ajoute le comptage de références, qui suit le principe que toute fonction qui augmente le nombre de pointeurs vers l'interface doit appeler AddRef(), et Release() doit être appelée avant toute destruction de pointeur (bien qu'il y ait une exception pour les pointeurs passés en paramètre d'une fonction, à vocation temporaire). La fonction QueryInterface() appelle AddRef(), et tout objet COM est créé avec un compteur de références de 1.=, et détruit automatiquement lorsque le compteur descend à zéro (lors du "dernier Release").

    Exemple d'utilisation d'un objet COM en C:
    http://www.developpez.net/forums/m1103863-7/
    Là-dessus, tu vois un appel à CoCreateInstance(), quelques appels de fonctions de l'objet COM, et un Release() à la fin.
    L'objet COM lui-même est de "type" CLSID_ActiveDesktop, et l'interface utilisée ici est une interface IActiveDesktop.

  6. #6
    Membre du Club
    Inscrit en
    Juillet 2008
    Messages
    117
    Détails du profil
    Informations forums :
    Inscription : Juillet 2008
    Messages : 117
    Points : 58
    Points
    58
    Par défaut
    Ok, ce que j'avais pas compris c'est que les fonction retournais (dans la cas de la première) HRESULT.

    Donc pour l'utiliser, je dois déclarer une structure de type : IProcessVtbl *toto par exemple et pour utiliser les fonction je dois procéder de la sorte :

    HRESULT titi = toto->QueryInterface(this, riid, ppvObject);

    ?

  7. #7
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 381
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 381
    Points : 41 582
    Points
    41 582
    Par défaut
    IProcess* seulement.

    Et tu n'as à utiliser QueryInterface() que si un objet expose plusieurs interfaces. Le plus souvent, on demande directement l'interface qu'on veut lors du CoCreateInstance()...

  8. #8
    Membre du Club
    Inscrit en
    Juillet 2008
    Messages
    117
    Détails du profil
    Informations forums :
    Inscription : Juillet 2008
    Messages : 117
    Points : 58
    Points
    58
    Par défaut
    Bonjour, tout d'abord merci pour les réponses, j'y vois un peu plus clair à propos des interfaces COM (même si je trouve quand même ce truc très compliquer).

    Toutefois j'ai quand même pas mal de problème, notamment lors de la compilation, malgré mon include de objbase.h, il me met un undefined reference to CoInitialize@4, pas mal d'aurte erreurs dans le même genre avec toujours ce "@" derriere plus un chiffre.

    Je vous met le code pour vous faire une idée, mais attention c'est sans doute bourré de grossière erreur (mes premiers pas dans les interfaces COM) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    #include <stdio.h>
    #include <stdlib.h>
    #include <wininet.h>
    #include <shlobj.h>
    #include <objbase.h>
    
    #include "OmniPage15.h"
    
    
    int main()
    {
      IApplication * myApp;
      BSTR myKey;
      IProcess * myProcess;
      BSTR myFileName;
      long * MyError;
      myKey = "";
      HRESULT hr;
    
      myFileName = "C:\\Documents and Settings\\ag\\Mes documents\\test_dll_formulaire\\test_omnioage\\ImageMatch2.jpg";
    
      CoInitialize(NULL);
    
      hr=CoCreateInstance(&CLSID_Application,
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          &IID_IApplication,
                          (void**)&myApp);
    
      CoUninitialize();
    Voila voila.

  9. #9
    Rédacteur

    Avatar de ram-0000
    Homme Profil pro
    Consultant en sécurité
    Inscrit en
    Mai 2007
    Messages
    11 517
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultant en sécurité
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mai 2007
    Messages : 11 517
    Points : 50 367
    Points
    50 367
    Par défaut
    Lu dans la doc MSDN de CoInitialize()

    Il faut se linker avec la librairie ole32.lib

  10. #10
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 381
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 381
    Points : 41 582
    Points
    41 582
    Par défaut
    Alors, pour les erreurs de ton code:
    1. Une BSTR ne s'utilise pas ainsi, voir la fonction SysAllocString() et ses amies sur MSDN.
    2. Tu ne testes pas le retour des fonctions. CoInitialize() aussi retourne un HRESULT qu'il faut tester, typiquement avec les macros SUCCEEDED() et FAILED().
    3. Tu as oublié le Release(), qui est très important.

  11. #11
    Membre du Club
    Inscrit en
    Juillet 2008
    Messages
    117
    Détails du profil
    Informations forums :
    Inscription : Juillet 2008
    Messages : 117
    Points : 58
    Points
    58
    Par défaut
    Bonjour, après de nombreuse modification le code compile presque mis a part une erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ld.exe                                  cannot find -lcmtd.lib
    Après une bonne heure de recherche sur le net je ne trouve pas de solution à ce problème.

  12. #12
    Membre du Club
    Inscrit en
    Juillet 2008
    Messages
    117
    Détails du profil
    Informations forums :
    Inscription : Juillet 2008
    Messages : 117
    Points : 58
    Points
    58
    Par défaut
    Bonjour, j'ai enfin un code qui compile, je le met, ça pourra peut être aider du monde. Encore merci Médinoc.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    #include <stdio.h>
    #include <stdlib.h>
    #include <objbase.h>
    #include <initguid.h>
    #include "OmniPage15.h"
    #include "OmniPage15_i.h"
    
    int                 main()
    {
        HRESULT         hr;
        IApplication    *MyApp;
        IProcess        *MyProc;
        BSTR            MyKey;
        long            *Error = NULL;
    
        MyKey = SysAllocString("test");
        if ((hr = CoInitialize(NULL)) == S_OK)
        {
            if ((hr = CoCreateInstance(&CLSID_Application, NULL,
                        CLSCTX_INPROC_SERVER, &IID_IApplication, &MyApp)) == S_OK)
            {
                MyApp->lpVtbl->Login(MyApp, MyKey, MyProc);
                MyProc->lpVtbl->CreateDocument(MyProc, Error);
            }
            SysFreeString(MyKey);
            CoUninitialize();
        }
        return 0;
    }

  13. #13
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 381
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 381
    Points : 41 582
    Points
    41 582
    Par défaut
    Bonjour,
    1. Il manque les Release().
    2. MyProc n'est jamais initialisé.
    3. La plupart du temps, tu devrais utiliser les macros SUCCEEDED() et FAILED() au lieu de comparer directement à S_OK.

    Code C : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    #include <stdio.h>
    #include <stdlib.h>
    #include <objbase.h>
    #include <initguid.h>
    #include "OmniPage15.h"
    #include "OmniPage15_i.h"
     
    int main(void)
    {
    	HRESULT         hr;
    	IApplication    *MyApp = NULL;
    	IProcess        *MyProc = NULL;
    	BSTR            MyKey;
    	long            *Error = NULL;
     
    	MyKey = SysAllocString("test");
    	hr = CoInitialize(NULL);
    	if(SUCCEEDED(hr))
    	{
    		hr = CoCreateInstance(&CLSID_Application, NULL,
    		 CLSCTX_INPROC_SERVER, &IID_IApplication, &MyApp);
    		if(SUCCEEDED(hr))
    		{
    			/* Il doit manquer un truc ici pour initialiser MyProc! */
    			MyApp->lpVtbl->Login(MyApp, MyKey, MyProc);
    			/* Cette ligne plantera! */
    			MyProc->lpVtbl->CreateDocument(MyProc, Error);
     
    			MyProc->lpVtbl->Release(MyProc);
    			MyApp->lpVtbl->Release(MyApp);
    		}
    		SysFreeString(MyKey);
    		CoUninitialize();
    	}
    	return 0;
    }

  14. #14
    Membre du Club
    Inscrit en
    Juillet 2008
    Messages
    117
    Détails du profil
    Informations forums :
    Inscription : Juillet 2008
    Messages : 117
    Points : 58
    Points
    58
    Par défaut
    Merci pour la correction Médinoc, en ce qui concerne le MyProc j'essais de comprendre le .h pour voir comment ça fonctionne, donc encore des modifications a venir.

    Merci pour tout encore une fois.

Discussions similaires

  1. [Toutes versions] Structure avec fonction : possible?
    Par EvaristeGaloisBis dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 23/04/2012, 10h24
  2. help : fonction table avec curseur dedans
    Par yolane dans le forum Développement
    Réponses: 1
    Dernier message: 18/08/2008, 13h09
  3. Probleme avec structures et fonctions
    Par isaac727 dans le forum Débuter
    Réponses: 2
    Dernier message: 31/03/2008, 23h01
  4. Réponses: 2
    Dernier message: 12/05/2007, 01h57
  5. [VStudio 6] pb avec fonctions dans une DLL
    Par MogDeChNord dans le forum MFC
    Réponses: 8
    Dernier message: 08/01/2004, 08h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo