我用C#调用一个DLL. 不多说了,把代码给大家看吧. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class WSAQUERYSET
{
public Int32 dwSize = 0;
public String szServiceInstanceName = null;
public IntPtr lpServiceClassId;
public IntPtr lpVersion;
public String lpszComment;
public Int32 dwNameSpace;
public IntPtr lpNSProviderId;
public String lpszContext;
public Int32 dwNumberOfProtocols;
public IntPtr lpafpProtocols;
public String lpszQueryString;
public Int32 dwNumberOfCsAddrs;
public IntPtr lpcsaBuffer;
public Int32 dwOutputFlags;
public IntPtr lpBlob;
} 然后:
WSAQUERYSET qsRestrictions;
Int32 dwControlFlags;
Int32 valHandle = 0;
qsRestrictions = new WSAQUERYSET();
qsRestrictions.dwSize = Marshal.SizeOf(typeof(WSAQUERYSET));结果执行qsRestrictions.dwSize = Marshal.SizeOf(typeof(WSAQUERYSET))时出错。
未处理的“System.NotSupportedException”类型的异常出现在 mscorlib.dll 中。
请问这是怎么回事?
public class WSAQUERYSET
{
public Int32 dwSize = 0;
public String szServiceInstanceName = null;
public IntPtr lpServiceClassId;
public IntPtr lpVersion;
public String lpszComment;
public Int32 dwNameSpace;
public IntPtr lpNSProviderId;
public String lpszContext;
public Int32 dwNumberOfProtocols;
public IntPtr lpafpProtocols;
public String lpszQueryString;
public Int32 dwNumberOfCsAddrs;
public IntPtr lpcsaBuffer;
public Int32 dwOutputFlags;
public IntPtr lpBlob;
} 然后:
WSAQUERYSET qsRestrictions;
Int32 dwControlFlags;
Int32 valHandle = 0;
qsRestrictions = new WSAQUERYSET();
qsRestrictions.dwSize = Marshal.SizeOf(typeof(WSAQUERYSET));结果执行qsRestrictions.dwSize = Marshal.SizeOf(typeof(WSAQUERYSET))时出错。
未处理的“System.NotSupportedException”类型的异常出现在 mscorlib.dll 中。
请问这是怎么回事?
这个方法也试了,还是那个错误。
未处理的“System.NotSupportedException”类型的异常出现在 mscorlib.dll 中。
这个参数必须是structure
你给的是Class
当然会报错
详情请参见
http://msdn2.microsoft.com/en-us/library/y3ybkfb3.aspx
=======》
什么意思?
http://topic.csdn.net/t/20060813/12/4946167.html我的程序片段就是那里的,在C#windows应用程序里可以运行。进到智能设备里就不行了。
.NET Framework 精简版平台调用服务与 .NET Framework 全功能版有以下差异: 没有 Unicode 到 ANSI 的字符串转换
当字符串对象传递给本机方法时,公共语言运行库传递一个指向该对象中包含的 Unicode 字符串的指针。如果基础本机服务需要 ANSI 字符串,则本机组件需要执行转换。 不封送复杂对象
.NET Framework 精简版公共语言运行库不能封送结构内的对象。不过,如果结构包含简单类型,而且非托管代码符合该结构,则可以封送它们。 不返回托管结构
如果本机函数返回一个指向结构的指针,公共语言运行库不将其封送为托管结构。这种情况下,托管代码必须访问不安全上下文中的非托管数据。
看了一片关于c#写蓝牙通讯模块的。
http://it.sohu.com/20050331/n224948889.shtml那我该怎样封送呢?