• <bdo id='HjuvZ'></bdo><ul id='HjuvZ'></ul>
    <legend id='HjuvZ'><style id='HjuvZ'><dir id='HjuvZ'><q id='HjuvZ'></q></dir></style></legend>

    1. <small id='HjuvZ'></small><noframes id='HjuvZ'>

    2. <i id='HjuvZ'><tr id='HjuvZ'><dt id='HjuvZ'><q id='HjuvZ'><span id='HjuvZ'><b id='HjuvZ'><form id='HjuvZ'><ins id='HjuvZ'></ins><ul id='HjuvZ'></ul><sub id='HjuvZ'></sub></form><legend id='HjuvZ'></legend><bdo id='HjuvZ'><pre id='HjuvZ'><center id='HjuvZ'></center></pre></bdo></b><th id='HjuvZ'></th></span></q></dt></tr></i><div id='HjuvZ'><tfoot id='HjuvZ'></tfoot><dl id='HjuvZ'><fieldset id='HjuvZ'></fieldset></dl></div>

      1. <tfoot id='HjuvZ'></tfoot>

        PInvoke 和字符**

        PInvoke and char**(PInvoke 和字符**)

        <i id='3URRB'><tr id='3URRB'><dt id='3URRB'><q id='3URRB'><span id='3URRB'><b id='3URRB'><form id='3URRB'><ins id='3URRB'></ins><ul id='3URRB'></ul><sub id='3URRB'></sub></form><legend id='3URRB'></legend><bdo id='3URRB'><pre id='3URRB'><center id='3URRB'></center></pre></bdo></b><th id='3URRB'></th></span></q></dt></tr></i><div id='3URRB'><tfoot id='3URRB'></tfoot><dl id='3URRB'><fieldset id='3URRB'></fieldset></dl></div>
          <bdo id='3URRB'></bdo><ul id='3URRB'></ul>

              <tbody id='3URRB'></tbody>

            1. <small id='3URRB'></small><noframes id='3URRB'>

              • <legend id='3URRB'><style id='3URRB'><dir id='3URRB'><q id='3URRB'></q></dir></style></legend>
                  <tfoot id='3URRB'></tfoot>
                  本文介绍了PInvoke 和字符**的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我从某人那里得到了这个程序集,我想在我的 c# 应用程序中使用它.

                  I got this assembly from someone which I'd like to use in my c# application.

                  标题如下所示:

                  int __declspec(dllimport) s2o(WCHAR* filename, char** out, int* len);
                  

                  我设法让它部分工作,使用:

                  I managed to get it partly working, using:

                  [DllImport("s2o.dll", EntryPoint = "?skn2obj@@YAHPA_WPAPADPAH@Z", CallingConvention = CallingConvention.Cdecl)]
                  public static extern int s2o(
                      [MarshalAs(UnmanagedType.LPWStr)]
                      string filename,
                      ref char[] @out,
                      ref int len
                  );
                  

                  然后这样称呼它:

                  char[] result = null;
                  int length = 0;
                  s2o("filepath", ref result, ref length);
                  

                  它似乎部分起作用,因为长度"实际上得到了一个值.不幸的是,结果"保持为空.

                  It seems to work partly, because 'length' actually gets a value. Unfortunatly, 'result' stays null.

                  我应该怎么做才能让它工作?

                  What should I do to get this working?

                  好的,我设法开始工作,将 char[] 替换为 IntPtr,然后像 Nick 建议的那样调用Marshal.PtrToStringAnsi":

                  Ok I managed to get to to work by replacing the char[] with a IntPtr and then calling 'Marshal.PtrToStringAnsi' like Nick suggested:

                  string result = Marshal.PtrToStringAnsi(ptr);
                  

                  但是,由于同一答案中的评论,我有点担心内存使用情况.程序集中没有提供其他方法,所以我该如何清理?

                  However, because of the comments in that same answer I'm a little worried about memory usage. There are no other methods provided in the assembly so how can I clear things up?

                  推荐答案

                  看看 Marshal.PtrToStringAnsi 方法.

                  或者正如 Centro 在对您问题的评论中所说,PtrToStringAuto 可能更合适.

                  Or as Centro says in the comment to your question, PtrToStringAuto may be more appropriate.

                  复制所有字符直到第一个来自非托管 ANSI 的空字符字符串到托管字符串,并加宽每个 ANSI 字符转换为 Unicode.

                  Copies all characters up to the first null character from an unmanaged ANSI string to a managed String, and widens each ANSI character to Unicode.

                  另请注意,您可能负责释放从该函数返回的内存.

                  Also note that you may be responsible for freeing the memory returned from this function.

                  这篇关于PInvoke 和字符**的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
                  Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
                  Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
                  How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
                  how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
                  JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)
                    <tfoot id='9xdCN'></tfoot>
                      • <i id='9xdCN'><tr id='9xdCN'><dt id='9xdCN'><q id='9xdCN'><span id='9xdCN'><b id='9xdCN'><form id='9xdCN'><ins id='9xdCN'></ins><ul id='9xdCN'></ul><sub id='9xdCN'></sub></form><legend id='9xdCN'></legend><bdo id='9xdCN'><pre id='9xdCN'><center id='9xdCN'></center></pre></bdo></b><th id='9xdCN'></th></span></q></dt></tr></i><div id='9xdCN'><tfoot id='9xdCN'></tfoot><dl id='9xdCN'><fieldset id='9xdCN'></fieldset></dl></div>

                            <bdo id='9xdCN'></bdo><ul id='9xdCN'></ul>

                            <small id='9xdCN'></small><noframes id='9xdCN'>

                            <legend id='9xdCN'><style id='9xdCN'><dir id='9xdCN'><q id='9xdCN'></q></dir></style></legend>

                              <tbody id='9xdCN'></tbody>