简体   繁体   中英

Call C++ dll from C# dll and get nothing

I am developing a C# dll for Revit(a software for Civil Engineering), and the C# dll calls the function from unmanaged C++ dll that was developed by myself. When the function compareMarkedPointsWithBIMModel_ in the unmanaged C++ dll is called, nothing is got, it seems that the function in the unmanaged C++ dll does not execute.


Here are the details:


in the unmanaged C++ dll

extern "C" __declspec(dllexport) void compareMarkedPointsWithBIMModel_(
char* a_,
const double* list,
int listLength) {

std::vector<std::vector<double>> b; 
for (int i = 0; i < listLength / 6; i++)
{
    std::vector<double> cc;
    for (int j = 0; j < 6; j++)
    {
        cc.push_back(list[i * 6 + j]);
    }
    b.push_back(cc);
}

std::string a = a_; 

CompareMarkedPointsWithBIMModel cmpb(a, b);
cmpb.readMarkedPoint3DInfo();
cmpb.computeAB();
cmpb.computeRT();
cmpb.computeDeviation();
system("pause");

}

in the C# dll

[DllImport("Test_OpenCV.dll")]
    public static extern void compareMarkedPointsWithBIMModel_(
        string st1,             
        ref double list_,     
        int listLength_);       

    public Result Execute(
        ExternalCommandData commandData,
        ref string messages,
        ElementSet elements)
    {                       
        string smallImagesPath =        
            "C:/D/Bundler04ForReconstruction/results/result_DF510";            
        double[] list;
        int listLength;
        setList1(out list, out listLength);           

        compareMarkedPointsWithBIMModel_(
            smallImagesPath,
            ref list[0],
            listLength);

        return Result.Succeeded;
    }        

    public void setList1(out double[] list, out int listLength)
    {
        /// realize of the function         

    }

I have searched the Internet for solutions, but got no useful solutions. I have also tried to call the unmanaged C++ dll (especially the function) in a C# console project, and it works! It is strange. Also, the platforms for the unmanaged C++ dll and C# dll are all x64. So, why the function not execute, is there anything wrong? Thank you in advance.

Do you get an exception? Is the unmanaged DLL using COM? If so, call it in a MTA thread (just run it in a background task), since it's working in a console application, this might be the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM