avoid P/INVOKE or COM Interop if possible
i was debugging this activex control used in my current project when i bumped into this wrapper class for an interop with kernel32.dll methods. after browsing the documentation, it says that the following functions are provided for win16 support. how come the developer used the following functions? maybe he is trying to reuse his code that he got from a vb6 project.
[DllImport("KERNEL32.DLL", EntryPoint="GetPrivateProfileSection")]
protected internal static extern int
GetPrivateProfileSection(string lpAppName, string lpReturnedString ,long nSize,string lpFileName);
[DllImport("KERNEL32.DLL", EntryPoint="GetPrivateProfileString")]
protected internal static extern int
GetPrivateProfileString(string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);
[DllImport("KERNEL32.DLL", EntryPoint="WritePrivateProfileSection")]
protected internal static extern int
WritePrivateProfileSection(string lpAppName, string lpString, string lpFileName);
[DllImport("KERNEL32.DLL", EntryPoint="WritePrivateProfileString")]
protected internal static extern int WritePrivateProfileString(string lpApplicationName, string lpKeyName, string lpString, string lpFileName);
in .NET, you have to avoid COM interop and PINVOKEs as much as possible. MS tried to provide a .NET interface to most of the windows API and it is seldom that you will need to resort to these kind of method calls. As I found out, the above functions are used just to read and write files. .NET is now using configuration files for an application configuration and they have provided the System.Configuration.ConfigurationSettings class for this.