Bonjour,je souhaite appeler une méthode C# 2.0 à partir du code C Standard.
SVP Comment procéder?
J'ai lu le tuto:
http://nico-pyright.developpez.com/t...2005/interop2/
Je n'y trouve pas mon compte !
Merci
Bonjour,je souhaite appeler une méthode C# 2.0 à partir du code C Standard.
SVP Comment procéder?
J'ai lu le tuto:
http://nico-pyright.developpez.com/t...2005/interop2/
Je n'y trouve pas mon compte !
Merci
Il me semble qu'il y avait un autre tuto spécialement pour COM Interop.
En gros, tu fais un assembly COM-Visible qui implémente une interface COM-Visible (qui utilise l'attribut InterfaceType). Puis, tu fais la même interface avec les macros en C DECLARE_INTERFACE et compagnie (parce que ça ira plus vite que retrouver l'interface C à partir de la Type Library générée), et tu appelles ta classe en tant qu'objet COM...
SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.
"Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
Apparently everyone. -- Raymond Chen.
Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.
Tiens, j'ai retrouvé un morceau de code à moi, avec un vieux lien:
Si jamais ça peut t'aider...
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
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 //Exemple de COM Interop en C++ sur le bloc de nico-pyright. //http://blog.developpez.com/index.php?blog=140&title=un_exemple_simpliste_de_com_interop_avec&more=1&c=1&tb=1&pb=1 //Corrigé et Traduit en C le 2008-02-12 Ma pour Jayceblaster #define COBJMACROS #include <windows.h> #include <stdio.h> #include <tchar.h> HRESULT faire_quelquechose_avec_objet(IDispatch *pDisp) { HRESULT hr; //Recherche de la méthode Print OLECHAR *methodName = OLESTR("Print"); DISPID dispid; hr = IDispatch_GetIDsOfNames(pDisp, &IID_NULL, &methodName,1, GetUserDefaultLCID(), &dispid); if(FAILED(hr)) _tprintf(_T("GetIDsOfNames() failed with HRESULT 0x%08lX.\n"), hr); else { //Appel de la méthode Print DISPPARAMS param; param.cArgs=0; param.rgvarg=NULL; param.cNamedArgs=0; param.rgdispidNamedArgs=NULL; hr = IDispatch_Invoke(pDisp, dispid, &IID_NULL, GetUserDefaultLCID(), DISPATCH_METHOD, ¶m, NULL, NULL, NULL); if(FAILED(hr)) _tprintf(_T("Invoke() failed with HRESULT 0x%08lX.\n"), hr); else { _putts(_T("OK!")); } } return hr; } int com_tmain(void) { HRESULT hr; int ret = EXIT_FAILURE; hr = CoInitialize(NULL); if(FAILED(hr)) _tprintf(_T("CoInitialize() failed with HRESULT 0x%08lX.\n"), hr); else { //Recherche de la classe de l'objet. CLSID clsID; hr = CLSIDFromProgID(OLESTR("assembly.MaClasse"), &clsID); if(FAILED(hr)) _tprintf(_T("CLSIDFromProgID() failed with HRESULT 0x%08lX.\n"), hr); else { //Création de l'objet IDispatch *pDisp = NULL; hr = CoCreateInstance(&clsID, NULL, CLSCTX_ALL, &IID_IDispatch, (void**)&pDisp); if(FAILED(hr)) _tprintf(_T("CoCreateInstance() failed with HRESULT 0x%08lX.\n"), hr); else { hr = faire_quelquechose_avec_objet(pDisp); if(SUCCEEDED(hr)) ret = EXIT_SUCCESS; IDispatch_Release(pDisp), pDisp=NULL; } } CoUninitialize(); } return ret; }
SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.
"Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
Apparently everyone. -- Raymond Chen.
Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.
Partager