C#Marshal作为String属性 [英] C# MarshalAs a String property

查看:707
本文介绍了C#Marshal作为String属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要Marshal一个字符串属性,以便我可以将它传递给我的dll。



这是我到目前为止所得到的但不是当我尝试传递它时,错误是无法读取或写入受保护的内存。



不允许我传递 UnmanagedType .ByValTstr



注意:我已成功将字符串成功传递为字段但不是属性。

I need to Marshal a string property so that I can pass it to my dll.

This is what I've got so far but it doesn't work, error is can't read or write protected memory when I attempt to pass it.

Doesn't allow me to pass with UnmanagedType.ByValTstr.

Note: I've managed to pass my string successfully as a field but not property.

public string firstName { 
           
     [return : MarshalAsAttribute(UnmanagedType.BSTR, SizeConst=51)]get {
            return _firstName;
      }
     [param : MarshalAsAttribute(UnmanagedType.BSTR, SizeConst=51)]set {
            _firstName = value;
      }
}

推荐答案

这篇关于C#Marshal作为String属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆