Re,
finalement, j'ai voulu aller plus loin et ca ne marche plus.
Le pointeur de fonction C est un moyen d'afficher un texte en provenance de ma dll pour la trace de ce qui se passe.
Je me suis donc dit que ca pouvait etre interessant d'utiliser.
J'ai donc utilisé le code suivant :
Code :
- class Program
- {
- public delegate void DisplayDelegate(string Data, int Len);
- [DllImport("DriverDll.dll", EntryPoint = "_CardDetect", CallingConvention = CallingConvention.Cdecl)]
- static extern int CardDetect(bool Debug, DisplayDelegate callback);
- [DllImport("DriverDll.dll", EntryPoint = "_CardDriver", CallingConvention = CallingConvention.Cdecl)]
- static extern int CardDriver(bool Debug, DisplayDelegate callback);
- static void Main(string[] args)
- {
- DisplayDelegate callback = Display;
- int ret = CardDetect(false, callback);
- Console.WriteLine(ret);
- }
- static void Display(string data, int Len)
- {
- Console.WriteLine(data);
- }
- }
|
et lorsque je l'execute, je passe bien dans la methode Display avec la bonne chaine de caractere mais en ressortant, je recupere l'erreur suivante :
System.AccessViolationException was unhandled
Message=Tentative de lecture ou d'écriture de mémoire protégée. Cela indique souvent qu'une autre mémoire est endommagée.
Source=TestLectureCarte
StackTrace:
à TestLectureCarte.Program.CardDetect(Boolean Debug, DisplayDelegate callback)
à TestLectureCarte.Program.Main(String[] args) dans D:\VM_DATA\Visual Studio 2010\Projects\TestLectureCarte\TestLectureCarte\Program.cs:ligne 24
à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
InnerException:
alors que si je passe null à la place du delegate,tout se passe bien.
Une idée ?
v.