c的函数是否可在c#中使用?

来源:百度知道 编辑:UC知道 时间:2024/06/28 09:06:52
c或C++的函数是否可在c#中使用?如果不能具体是那些?

可以使用,但是要额外添加一些代码
比如在C++常用的WritePrivateProfileString等API在C#中也是可以使用的,示例如下:

[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

然后你就可以使用它了
比如:

StringBuilder tmpValue = new StringBuilder(256);

GetPrivateProfileString("Server", "ServiceUrl", "", tmpValue, 256, "C:\1.ini");