Отследите зависимости DLL для обертывания собственного C++ DLL к.NET

... так как удаление Student.number не работает

Student не имеет свойства number, поэтому удалять нечего. Объекты, созданные с помощью new Student, делают. Например:

function Student(name, sclass, year, number, submissionYear)
{
    this.name = name;
    this.sclass = sclass;
    this.year = year;
    this.number = number;
    this.submissionYear = submissionYear;
}

var s = new Student();
console.log("number" in s); // true
delete s.number;
console.log("number" in s); // false

Если вы хотите создать версию Student, которая создает объекты без number свойство, это возможно , но это плохая идея:

function Student(name, sclass, year, number, submissionYear)
{
    this.name = name;
    this.sclass = sclass;
    this.year = year;
    this.number = number;
    this.submissionYear = submissionYear;
}

function NumberlessStudent() {
    Student.apply(this, arguments);
    delete this.number;
}
NumberlessStudent.prototype = Object.create(Student.prototype);
NumberlessStudent.prototype.constructor = NumberlessStudent;

var n = new NumberlessStudent();
console.log("number" in n); // false

или предпочтительно в ES2015 + с [ 118] синтаксис:

class Student {
    constructor(name, sclass, year, number, submissionYear) {
        this.name = name;
        this.sclass = sclass;
        this.year = year;
        this.number = number;
        this.submissionYear = submissionYear;
    }
}

class NumberlessStudent extends Student {
    constructor(...args) {
        super(...args);
        delete this.number;
    }
}

const n = new NumberlessStudent();
console.log("number" in n); // false

Это плохая идея, потому что установка наследования таким образом, экземпляры подкласса (NumberlessStudent) должен иметь свойства экземпляров суперкласса (Student).

5
задан Remoun 24 April 2009 в 15:43
поделиться

4 ответа

Вы можете взглянуть на mergebin , инструмент, позволяющий объединять неуправляемые и управляемые библиотеки DLL в одну сборку. System.Data.SQLite использует этот подход.

6
ответ дан 14 December 2019 в 01:16
поделиться

Ну, вы можете просто добавить команды для автоматического копирования необходимых DLL в правильный выходной каталог, как часть сборки обработать. Это делается в Visual Studio путем перехода к свойствам проекта.

Проект -> Свойства MyProjectName ... -> События сборки

Добавьте команды для копирования необходимых файлов в $ (TargetPath), и вы готово.

Другой вариант - просто установить текущий рабочий каталог вашего проекта (когда вы запускаете его только из Visual Studio) в каталог, в котором находятся все необходимые библиотеки DLL. Вам все равно придется вручную копировать файлы при внешнем выполнении программы, но это немного облегчит разработку.

0
ответ дан 14 December 2019 в 01:16
поделиться

Похоже, у вас есть две конкретные проблемы:

  1. Как скопировать нативный код dll до начала сборки
  2. Как динамически определить зависимости нативного кода, которые необходимо скопировать в случае их изменения.

Для 1) вы можете использовать шаг перед сборкой в ​​вашем C # проект для вызова пользовательской утилиты для копирования правильных файлов.

Похоже, 2) уже был дан ответ здесь, на переполнении стека .

0
ответ дан 14 December 2019 в 01:16
поделиться

I'm currently having a very similar problem.

One big step too meet my goal was to copy the Native .DLL into the output directory by a pre-built step in the C++/CLI project and add the linker option

/ASSEMBLYLINKRESOURCE:"$(OutDir)\Native.dll"

This writes into the resulting assembly that there is a file "Native.dll" that belongs to the assembly. Now all projects referencing that project/assembly will also copy the Native.dll around! (It should also go into the GAC if you put you're assembly there - I didn't check that).

Okay, you still have to add all depending native.dll's. I also don't know if the native DLL is found on run-time if you load the assembly via Assembly.LoadFrom() from a very different path (this is something I have to solve for my problem because our C++/CLI wrapper assembly is needed by the Visual Studio designer).

I hope this helps you a bit for you're problem.

EDIT:

Further investigations showed that the Wrapper .DLL always finds the native .DLL...that's the good thing. The bad thing is that the Visual Studio Designer copies the needed assemblies to a temporary directory (somewhere inside the user directory) when you open a form. When it copies the assemblies it ignores the linked resources and by this the native .DLL!

3
ответ дан 14 December 2019 в 01:16
поделиться
Другие вопросы по тегам:

Похожие вопросы: