Bonjour tout le monde,


J'ai commencer un projet bibliothèques de classe (VS 2008 Prof ed / Excel 2007). Pour les fonctions qui prennent des paramètre simples (double, int...), ça ne pose pas de problème. En revanche quand je veux passer un tableau, ça compile sans problème mais l'appel depuis Excel ne fonctionne pas.

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
 
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
 
 
namespace ClassLibrary1
{
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ComVisible(true)]
    public class Functions
    {
        public Functions()
        {
        }
 
        public double bete(double a, double b)
        {
 
            return a*b;
        }
 
        [ComRegisterFunctionAttribute]
        public static void RegisterFunction(Type type)
        {
 
            Registry.ClassesRoot.CreateSubKey(
 
              GetSubKeyName(type, "Programmable"));
 
            RegistryKey key = Registry.ClassesRoot.OpenSubKey(
 
              GetSubKeyName(type, "InprocServer32"), true);
 
            key.SetValue("",
 
              System.Environment.SystemDirectory + @"\mscoree.dll",
 
              RegistryValueKind.String);
        }
 
        [ComUnregisterFunctionAttribute]
        public static void UnregisterFunction(Type type)
        {
 
            Registry.ClassesRoot.DeleteSubKey(
 
              GetSubKeyName(type, "Programmable"), false);
        }
 
        private static string GetSubKeyName(Type type,
 
          string subKeyName)
        {
 
            System.Text.StringBuilder s =
 
              new System.Text.StringBuilder();
 
            s.Append(@"CLSID\{");
 
            s.Append(type.GUID.ToString().ToUpper());
 
            s.Append(@"}\");
 
            s.Append(subKeyName);
 
            return s.ToString();
 
        }
 
    }
}
j'ai trouvé le code là:
http://www.quantnet.com/forum/showthread.php?t=2509

Pour passer un tableau en paramètres MSDN:
http://msdn.microsoft.com/fr-fr/library/hyfeyz71%28VS.80%29.aspx

En gros ça fonctionne avec des chiffres mais pas avec un tableau.
(le projet est générer sans problème mais l'appel dans excel renvoie: "valeur!"

Quelqu'un a une idée?

Merci