小编Den*_*hev的帖子

将指向class的指针传递给C#中的非托管c ++代码

我在dll中有一个c ++导出的函数:

int MyMethod(ulong pid, MyStruct* struct);
Run Code Online (Sandbox Code Playgroud)

MyStruct被描述为类:

class MyStruct
{
public:
uchar   nVersion;
uchar   nModuleType;
uchar   nMachine64;
uchar   nReserved;
ulong  data1;
ulong  data2;
ulong  data3;
};
Run Code Online (Sandbox Code Playgroud)

我正在尝试将此函数导入到我的C#代码中,如下所示:

[DllImport("mydll.dll", EntryPoint = "#24")]
private static extern int _MyMethod(long pid, ref MyStruct struct);
Run Code Online (Sandbox Code Playgroud)

C#中的类:

[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
stuct MyStruct
{
    public byte nVersion;
    public byte nModuleType;
    public byte nMachine64;
    public byte nReserved;
    public ulong data1;
    public ulong data2;
    public ulong data3;
}
Run Code Online (Sandbox Code Playgroud)

我得到了System.AccessViolationException:

MyStruct struct = new MyStruct();
_MyMethod(4728, ref struct);
Run Code Online (Sandbox Code Playgroud)

怎么了? …

c# c++ unmanaged marshalling

5
推荐指数
1
解决办法
1821
查看次数

Qt:字段类型不完整

无法编译我的课程。正在获取错误:错误:字段“文件名”的类型不完整

如果我改变QString filenameQString *filename,错误熄灭..但我需要QString filename

process.h:

#ifndef PROCESS_H
#define PROCESS_H

#include <QString>

class Process
{
public:
    int pid;
    QString filename;
    Process(int pid, QString filename);
};

#endif // PROCESS_H
Run Code Online (Sandbox Code Playgroud)

process.cpp:

#include "process.h"

Process::Process(int pid, QString filename)
{
    this->pid = pid;
    this->filename = filename;
}
Run Code Online (Sandbox Code Playgroud)

怎么了?

c++ qt

5
推荐指数
2
解决办法
1万
查看次数

Angular:错误错误:ExpressionChangedAfterItHasBeenCheckedError:检查后表达式已更改

怎么了?在控制台中收到以下错误:

AboutComponent.html:1 ERROR 错误:ExpressionChangedAfterItHasBeenCheckedError:检查后表达式已更改。以前的值:'空:未定义'。当前值:'null:[object Object]'。

import { AfterViewInit, Component} from '@angular/core';

export class Test {

}

@Component({
  selector: 'app-about',
  template: `
    {{asd}}
  `
})
export class AboutComponent implements AfterViewInit {

  asd: Test;

  ngAfterViewInit(): void {
    this.asd = new Test();
  }
}
Run Code Online (Sandbox Code Playgroud)

angular

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

c++ ×2

angular ×1

c# ×1

marshalling ×1

qt ×1

unmanaged ×1