如何将const char *转换为C# [英] How to convert const char* to c#

查看:497
本文介绍了如何将const char *转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用c ++ dll文件来执行某些功能,
我无法使用此功能:

Hi,
I''m using a c++ dll file in order to execute some functions,
I''m blocked in this function :

BOOL CLIENT_CapturePicture(
  LONG       hPlayHandle,
  const char *pchPicFileName
);



我正在尝试此代码,但它不起作用:



I''m trying this code but it''s not working :

[DllImport("dhnetsdk.dll", CharSet = CharSet.Ansi)]
public static extern bool CLIENT_CapturePicture
    (long hPlayHandle,
    [MarshalAs(UnmanagedType.LPStr)]
    string pchPicFileName);



请帮帮我:)& thx



Please Help me :) &thx

推荐答案

好,我找到了解决方案,将c ++代码中的
OK, I find the solution, it''s to consider
long

视为

int

在C#中,谢谢:-O

in c#, Thanks :-O


我认为您需要
I think you need the Marshal.StringToHGlobalAnsi Method.
:)


它可以正常工作,但不能正确地检查字符串参数
It work, but not correctly, the string parameter
string pchPicFileNam

,我得到的输出文件的名称类似于€mÕ":confused :, Are还有其他建议

is not examined correctly, I get an output file that have a name like "€mÕ":confused:, Are there other suggestion please


这篇关于如何将const char *转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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