Redian新闻
>
a question about C++.net class library
avatar
a question about C++.net class library# DotNet - 窗口里的风景
w*w
1
in .NET, i defined a function in C++ class library for file open
int open(char* filename) {blah...}
Now i want to use it in C#, add reference from this DLL. C# asks:
open(sbyte*)
how to use this function in C#, where to convert a string to sbyte* ?
thanks.
avatar
y*t
2
it is not safe code, i think.

【在 w**w 的大作中提到】
: in .NET, i defined a function in C++ class library for file open
: int open(char* filename) {blah...}
: Now i want to use it in C#, add reference from this DLL. C# asks:
: open(sbyte*)
: how to use this function in C#, where to convert a string to sbyte* ?
: thanks.

avatar
w*w
3
the problem is how to convert it. it is impossible for everyone to rewrite the
previous code, i suppose .NET should be able to handle it.

【在 y****t 的大作中提到】
: it is not safe code, i think.
avatar
s*i
4
try this:
//in C#, make a sbyte array, say
//sbyte[] sArray = .....
unsafe
{
fixed(byte *fileName=sArray) className.open(fileName);
}
This should work. Remember to enable 'unsafe blocks" in Visual Studio to
compile correctly.
Working with sbyte is actually not very convinient. If you can recompile your
C++ with "/J" (default char unsigned: Yes), your expected input becomes
"byte*" instead of "sbyte*". This way, you can try this:
//using System.Text
.....
ASCIIEncoding encoding=new ASCIIEncod

【在 w**w 的大作中提到】
: in .NET, i defined a function in C++ class library for file open
: int open(char* filename) {blah...}
: Now i want to use it in C#, add reference from this DLL. C# asks:
: open(sbyte*)
: how to use this function in C#, where to convert a string to sbyte* ?
: thanks.

avatar
w*w
5
thanks a lot!! The second method works. I had troubles to convert sbyte, so i
didn't try first one, but it looks fine as well.

【在 s*i 的大作中提到】
: try this:
: //in C#, make a sbyte array, say
: //sbyte[] sArray = .....
: unsafe
: {
: fixed(byte *fileName=sArray) className.open(fileName);
: }
: This should work. Remember to enable 'unsafe blocks" in Visual Studio to
: compile correctly.
: Working with sbyte is actually not very convinient. If you can recompile your

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。