2011-12-18 3 views
0

Je suis en train d'utiliser OpenCV comme here, et je suis coincé à un moment où je me PInvoke, à savoir:DLL Pinvoke avec Windows Mobile bibliothèques C++ portage vers C#

mon DLL.cpp

#define DLL_API __declspec(dllexport) 
//... 
DLL_API short processImage(const char* in_file, const char * out_file) 
//... 

ma form.cs

[DllImport("DLL", EntryPoint = "processImage")] 
     private static extern short _ProcessImage(byte[] in_file, byte[] out_file); 

     public static short binarizeImage(string in_file, string out_file) 
     { 
      return _ProcessImage(StringToASCIIByteArray(in_file), StringToASCIIByteArray(out_file)); 
     } 

    public static byte[] StringToASCIIByteArray(string str) 
    { 
     return Encoding.ASCII.GetBytes(str + "\0"); 
    } 

Je pense que cela pourrait être un problème avec l'architecture cible (dans mon projet VS 2008). Quand j'utilise 'Any CPU' il compile & mais lance Pinvoke, quand je le mets à 'Windows Mobile 6 Professionnel SDK (ARMV4I)' il compile mais ne veut pas se déployer et je l'ai dans la fenêtre de sortie:

1>------ Deploy started: Project: DLL, Configuration: Debug Windows Mobile 6 Professional SDK (ARMV4I) ------ 
1>The system cannot find the path specified. 
1> 
2>------ Deploy started: Project: smartDeviceOcr, Configuration: Debug Any CPU ------ 
2>Deploying 'D:\VS 2008 Projects\C++\SmartDevice\ocr\smartDeviceOcr\bin\Debug\smartDeviceOcr.exe' 
========== Deploy: 1 succeeded, 1 failed, 0 skipped ========== 

L'ARMV4I spécifique est-il important? J'ai ARM920T sur mon mobile. Est-ce que je peux/dois-je éditer ceci pour le faire fonctionner?


EDIT:

Pour être clair points Pinvoke à:

return _ProcessImage(StringToASCIIByteArray(in_file), StringToASCIIByteArray(out_file)); 

et le message d'exception est la suivante:

System.MissingMethodException was unhandled 
    Message="Cannot find the library DLL PInvoke 'DLL'." 
    StackTrace: 
    in smartDeviceOcr.Form1.binarizeImage(String in_file, String out_file) 
    in smartDeviceOcr.Form1.button1_Click(Object sender, EventArgs e) 
    in System.Windows.Forms.Control.OnClick(EventArgs e) 
    in System.Windows.Forms.Button.OnClick(EventArgs e) 
    in System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam) 
    in System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam) 
    in Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain) 
    in System.Windows.Forms.Application.Run(Form fm) 
    in smartDeviceOcr.Program.Main() 

EDIT2:

Ok maintenant c'est vraiment étrange. J'ai changé peu de choses. J'ai ajouté les dll d'openCV à la liste de déploiement dans les propriétés du projet afin que je puisse voir qu'ils sont copiés sur le déploiement et j'ai copié manuellement tous les dlls sur le répertoire exe sur le PC.

J'ai aussi changé quelques-unes des options de déploiement dans le projet DLL afin que les DLL sont copiés dans le répertoire approprié (automatiquement) au téléphone et ....

maintenant j'ai l'erreur sur l'exécution (lorsque essayant d'accéder à la fonction de la dll - OpenCV):

la connexion à distance à l'appareil a été perdu

+0

OpenCV est le code natif.Vous aurez besoin d'une version conçue pour cibler votre processeur. –

+0

Cette version a été conçue pour les processeurs mobiles Windows (j'utilise la version du site que j'ai mentionnée au début.) – Patryk

+0

Le marshaller pinvoke semble ne pas être d'accord, voir le message d'exception nous aiderait à diagnostiquer le problème –

Répondre

0

Comme je ne vois pas de réponses que je poste ma réponse (même si je dois encore problèmes avec ceci)

Le problème peut être résolu en ajoutant les répertoires auxquels dll doivent être déployés pour:

Project-> Properties -> Deployment -> Remote Directory

et spécifier correctement les fichiers dans:

Project-> Properties -> Deployment -> Additional Files

comme comme

highgui200.dll|$(SolutionDir)\opencv_winmo\dll|%CSIDL_PROGRAM_FILES%\smartDeviceOcr|0 
cv200.dll|$(SolutionDir)\opencv_winmo\dll|%CSIDL_PROGRAM_FILES%\smartDeviceOcr|0 
cxcore200.dll|$(SolutionDir)\opencv_winmo\dll|%CSIDL_PROGRAM_FILES%\smartDeviceOcr|0 
ml200.dll|$(SolutionDir)\opencv_winmo\dll|%CSIDL_PROGRAM_FILES%\smartDeviceOcr|0 
msvcr90.dll|$(BINDIR)\$(INSTRUCTIONSET)\|%CSIDL_PROGRAM_FILES%\smartDeviceOcr|0 
Questions connexes