日期:2014-05-18  浏览次数:20713 次

vb.net转C#
谁可以帮我把这几个方法转一下C#
VB.NET code
    Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32

    Public Function WriteINI(ByVal sSection As String, ByVal sKey As String, ByVal sValue As String, ByVal sFileName As String) As Long
        WriteINI = WritePrivateProfileString(sSection, sKey, sValue, sFileName)
    End Function





------解决方案--------------------
[DllImport("kernel32.dll")]
public static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

public static void WriteINI(string Section, string Key, string Val, string FilePath)
{
WritePrivateProfileString(Section, Key, Val, FilePath);
}
------解决方案--------------------
记得给几分我Y

给你个地址,以后不用问别人了.

http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx
------解决方案--------------------
C# code
[DllImport("kernel32.dll")] 
        public static extern long WritePrivateProfileString(string section, string key, string val, string filePath); 

  public static void WriteINI(string Section, string Key, string Val, string FilePath) 
        { 
          WritePrivateProfileString(Section, Key, Val, FilePath); 
        }

------解决方案--------------------
楼主就是要在C#中调用API函数吧?
改写如下:

[DllImport("kernel32.dll"), EntryPoint="WritePrivateProfileStringA"] 
public static extern long WritePrivateProfileString(string section, string key, string val, string filePath); 

public long WriteINI(string Section, string Key, string Val, string FilePath) 

return WritePrivateProfileString(Section, Key, Val, FilePath); 
}


详细请参考
http://dev.csdn.net/article/75/75553.shtm