带元帅的System.AccessViolationException

时间:2019-04-19 04:17:31

标签: c# c++ .net marshalling

从c#调用非托管函数时遇到一些问题。 在方法调用期间,我将面对System.AccessViolationException。 我真的不知道为什么会这样。你能告诉我我的错误在哪里。

仔细研究一下,我发现了一个有关类型映射错误的提示,并尝试了不同的参数类型,但这无济于事。

C#方法调用

const tryParseXml = function(src) {
    /* returns an XMLDocument, or null if `src` is malformed */

    let key = `a`+Math.random().toString(32);

    let parser = new DOMParser;

    let doc = null;
    try {
        doc = parser.parseFromString(
            src+`<?${key}?>`, `application/xml`);
    } catch (_) {}

    if (!(doc instanceof XMLDocument)) {
        return null;
    }

    let lastNode = doc.lastChild;
    if (!(lastNode instanceof ProcessingInstruction)
        || lastNode.target !== key
        || lastNode.data !== ``)
    {
        return null;
    }

    doc.removeChild(lastNode);

    let errElemCount =
        doc.documentElement.getElementsByTagName(`parsererror`).length;
    if (errElemCount !== 0) {
        let errDoc = null;
        try {
            errDoc = parser.parseFromString(
                src+`<?`, `application/xml`);
        } catch (_) {}

        if (!(errDoc instanceof XMLDocument)
            || errDoc.documentElement.getElementsByTagName(`parsererror`).length
                === errElemCount)
        {
            return null;
        }
    }

    return doc;
}

C ++功能代码

var result = delegates.CalculateGHDelegate(16, 68, true, true, error, 25);

public delegate int CalculateGHDelegate(int labId, int ghId, bool isFailStep2,
 bool isHandleStep2, string errorText, int errorTextLength);

0 个答案:

没有答案