2011-12-18 49 views
0

我想使用的OpenCV作爲here,和我被困在一個時刻,我得到PInvoke的,即:DLL PInvoke的與Windows Mobile C++庫移植到C#

DLL.cpp

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

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"); 
    } 

我認爲,這可能與目標體系結構問題(在我的VS 2008項目)。當我使用'任何CPU'它編譯&運行,但拋出Pinvoke,當我將它設置爲'Windows Mobile 6專業SDK(ARMV4I)'它編譯但不想部署,我得到了這個在輸出窗口:

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 ========== 

請問具體ARMV4I事?我的手機上有ARM920T。我可以/應該編輯這個工作嗎?


編輯:

只是要清楚的PInvoke點:

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

和異常消息是:

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:

好了,現在它真的很奇怪。我改變了一些東西。我已經將openCV的dll添加到項目屬性的部署列表中,以便我可以看到它們正在複製部署,並且我手動將所有dll複製到了PC上的exe目錄。

我也改變了一些在DLL項目的部署選項,這樣的DLL文件被複制到正確的目錄(自動)電話及....

現在我有運行時錯誤(當試圖訪問從DLL中的函數 - OpenCV的):

到設備的遠程連接已丟失

+0

OpenCV是本地代碼。你需要一個專門針對你的處理器的版本。 – 2011-12-18 11:12:33

+0

此版本是爲Windows移動處理器而設計的(我使用的是我在開始提到的網站中的版本 – Patryk 2011-12-18 15:29:09

+0

pinvoke編組似乎不同意看到實際的異常消息將幫助我們幫助您診斷問題 – 2011-12-18 15:32:50

回答

0

由於我沒有看到我後我的答案(雖然我仍然有任何答案問題與此)

的問題可以通過添加目錄來解決到哪些DLL應該部署到:在

Project-> Properties -> Deployment -> Remote Directory

,正確指定文件:

Project-> Properties -> Deployment -> Additional Files

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