请问COM调用中,BSTR类型的在C#中传进去的值为STRING类型,但是在COM跟踪中为什么总是空值,分不够可以再加?谢谢各位 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 static void Main(string[] args) 2 { 3 string str = "Hello world"; 4 IntPtr bstr = Marshal.StringToBSTR(str); 5 IntPtr p = bstr; 6 char * c; 7 while (p != (IntPtr)((long)bstr + sizeof(char) * str.Length)) 8 { 9 c = (char*)p;10 Console.WriteLine(*c);11 p = (IntPtr)((long)p + sizeof(char));12 }13 Marshal.FreeBSTR(bstr);14 } TO:avisnet(第十维度) 编译通不过,提示错误 1 指针和固定大小缓冲区只能在不安全的上下文中使用 E:\Dicos_code\PDA\code\PrintTest\PrintTest\POSPrint.cs 92 15 PrintTest project properties->build->allow unsafe codestatic void Main(string[] args){ string str = "Hello world"; IntPtr bstr = Marshal.StringToBSTR(str); IntPtr p = bstr; unsafe { char* c; while(p != (IntPtr)((long)bstr + sizeof(char) * str.Length)) { c = (char*)p; Console.WriteLine(*c); p = (IntPtr)((long)p + sizeof(char)); } } Marshal.FreeBSTR(bstr);} 数据库中如何返回多行记录的行号? catch (Exception ex) 一个简单的数据库语法问题 “<” 字符 老是提示“<:” windows installer C# 在强数据类型的数据集中,是否可以自定义查询的填充条件? GJJ:这2个存储语句怎么都错了?怎么改正? 在C#里怎么插入flash? 如何将txt(多列)导入到gridview或者listview中 有没有人知道怎样解决下面的问题啊! 求string类型和ASC码的转换如A到B。。。急
2 {
3 string str = "Hello world";
4 IntPtr bstr = Marshal.StringToBSTR(str);
5 IntPtr p = bstr;
6 char * c;
7 while (p != (IntPtr)((long)bstr + sizeof(char) * str.Length))
8 {
9 c = (char*)p;
10 Console.WriteLine(*c);
11 p = (IntPtr)((long)p + sizeof(char));
12 }
13 Marshal.FreeBSTR(bstr);
14 }
错误 1 指针和固定大小缓冲区只能在不安全的上下文中使用 E:\Dicos_code\PDA\code\PrintTest\PrintTest\POSPrint.cs 92 15 PrintTest
{
string str = "Hello world";
IntPtr bstr = Marshal.StringToBSTR(str);
IntPtr p = bstr;
unsafe
{
char* c;
while(p != (IntPtr)((long)bstr + sizeof(char) * str.Length))
{
c = (char*)p;
Console.WriteLine(*c);
p = (IntPtr)((long)p + sizeof(char));
}
}
Marshal.FreeBSTR(bstr);
}