簡體   English   中英

在C ++ / CLI中找不到入口點

[英]Unable to find an entry point in C++/CLI

請原諒我,盡管我試圖縮短它,但仍然很長。

我知道一些C#和C ++,但是正在學習CLI。 我有一個本機C函數,可以執行某些統計計算。 它具有1或2種嵌入式匯編語言指令-節省的最大速度是速度(例如消防水帶的飲用水)。 我沒有重寫它。 因此,我試圖將其放在dll中並從C#調用它。 因此是C ++ / CLI。

據我估計,以下代碼應該接近工作了[封送處理可能是錯誤的]。 經過廣泛的Stack_Overflow研究-順便說一句,我喜歡閱讀許多問題並且有一些不錯的答案-我已經了解了編譯的要點。 C#gui完成了它的工作,並且能夠為包裝器函數組合一個大概有效的參數列表。 然后這個運行時錯誤...

gui_proj.exe中發生了類型為'System.EntryPointNotFoundException'的未處理異常

附加信息:在DLL“ Wrapper_proj.dll”中找不到名為“ process_these_files”的入口點。

我將代碼簡化為基本要素(我認為)。 該dll是在gui項目中引用的。 對象瀏覽器似乎看到了入口點。 Dependency Walker搞砸了-真的是“ IESHIMS.DLL”嗎? Silurian Inspect_Exe說,它可以加載dll並顯示基本屬性,但無法顯示任何導入/導出。 [兩個項目都配置為64位]。 在構建之前,我先清潔溶液。

如何獲得被“ 找到 ”的切入點? 我需要封送文件名嗎? 或封送(空)結果數組?

gui_proj.cs中

// I've also tried CallingConvention.StdCall
[DllImport("Wrapper_proj.dll", SetLastError = true, CharSet = CharSet.Ansi, EntryPoint = "process_these_files", CallingConvention = CallingConvention.Cdecl)]

static extern void process_these_files( [In] int length, [In] String[] file_names, [Out] byte[] output_calcs, [Out] UInt64[] file_sizes);

private void Calcs_on_files_ThreadStart(object oo)
{
    List<int> fil_indices = new List<int>();
    List<string> fil_names = new List<string>();
    List<UInt64> fil_sizes = new List<UInt64>();

    foreach (DataGridViewRow rr in dgvFiles.SelectedRows)
    {
        fil_indices.Add(rr.Index);
        fil_names.Add( ((string)rr.Cells["Full_Name"].Value) );
        fil_sizes.Add( ((UInt64)((long)rr.Cells["File_Size"].Value)) ); // expected size
    }
    int jj = fil_names.Count;
    int kk = 32 * fil_names.Count;
    byte[] calc_results = new byte[kk]; // "byte" is equivalent to "uint8_t"
    UInt64[] siz_results = new UInt64[jj];
    string[] fil_arr = fil_names.ToArray();
    process_these_files( jj, fil_arr, calc_results, siz_results);
}

Wrapper_proj.h中

#include "stdafx.h"
#include <fstream>      // std::ifstream
...

// compiler supposedly defines *"_EXPORTS", though just being definitive here
#define Wrapper_proj_EXPORTS

#ifdef Wrapper_proj_EXPORTS
#define Wrapper_proj_API __declspec(dllexport) 
#else
#define Wrapper_proj_API __declspec(dllimport) 
#endif

namespace Wrapper_proj {
    // ++++ see note below
    public ref class wrap_it
    {
    public:
        // +++ see note below
        static  void process_these_files(
            int length, // each array has same length (varying sizes though, of 

course)
            array<System::String^>^ files,
            array<System::Byte>^ calcs,
            array<System::UInt64>^ fil_sizes);
    };
}

Wrapper_proj.cpp中

#include "stdafx.h"
#include "Wrapper_proj.h"

using namespace System;
using namespace System::Collections::Generic;
using namespace System::Runtime::InteropServices;
using std::ios;

namespace Wrapper_proj {

    void wrap_it::process_these_files(
        int arr_length,
        array<System::String^>^ files,
        array<System::Byte>^ calcs,
        array<System::UInt64>^ fil_sizes)
    {
...
    // call native calc. fcn. (that has asy. lang. instructions)
...
    };  // process_these_files
}   // end namespace

+++如果我嘗試以下聲明(在wrapper_proj.h中)“ static Wrapper_proj_API void process_these_files(”),則會得到

錯誤C3387:'process_these_files':__declspec(dllexport)/ __ declspec(dllimport)無法應用於托管類型的成員

錯誤C3395:'City_Hash_Lib :: City_Hash :: process_these_files':__declspec(dllexport)無法應用於具有__clrcall調用約定的函數

++++希望保留“ public ref Class”,但奇怪的是它似乎並沒有阻止dllexport。

Dumpbin / EXPORTS這樣說...

文件Wrapper_proj.dll的轉儲文件類型:DLL摘要3000 .data 2000 .nep 1000 .pdata 27000 .rdata 1000 .reloc 3000 .rsrc A000 .text

制作.def文件導出“ process_these_files”會產生錯誤C3387。

由於您使用的是C ++ / CLI,因此生成的圖像是.NET圖像。 您需要做的就是在C#文件中導入名稱空間,並在C#項目中使用適當的引用。

我嘗試了以下C#代碼:

using Callee;

namespace Caller
{
    class Program
    {
        static void Main(string[] args)
        {
            Byte[] calcs = new Byte[10];
            UInt64[] fil_size = new UInt64[10];
            String[] files = new String[1];
            files[0] = "file1";

            Class1.process_these_files(1, files, calcs, fil_size);

        }
    }
}

我確實必須使用Visual Studio中項目的設置來使鏈接器設置對齊。

我剛剛開始將示例代碼推送到GitHub。 您可以從https://github.com/kc1073/Samples下載整個項目

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM