c# The type or namespace name ‘DllImport’ could not be found
The type or namespace name ‘DllImport’ could not be found” when calling the system library in C#, the code is as follows.
namespace DeployAssist.Util
{
public class IniFileHelper
{
private string strIniFilePath; // ini configuration file path
//returns 0 for failure, non-zero for success
[DllImport("kernel32", CharSet = CharSet.Auto)]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
//Returns the length of the obtained string buffer
[DllImport("kernel32", CharSet = CharSet.Auto)]
private static extern long GetPrivateProfileString(string section, string key, string strDefault, StringBuilder retVal, int size, string filePath);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern int GetPrivateProfileInt(string section, string key, int nDefault, string filePath);
Solution:
1: Be sure to use system. Runtime. Interopservices
2: [dllimport (“XXX”)] needs to be used in a class
Similar Posts:
- Transcoding of system.web.httputility.urlencode in C #
- A brief summary of hash calculation in resource packaging of unity
- [Problems with the use of internal classes] No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclo
- Log system reconstruction of unity3d
- [Solved] UserInfo()’ in ‘com.example.gmall.cart.pojo.UserInfo’ cannot be applied to ‘(long, java.lang.String)’
- Get the time value from the database and report an error: Java sql. Timestamp cannot be cast to java. lang.Long
- MYSQL Error: Out of sort memory, consider increasing server sort buffer size; nested exception is java.sql.SQLException: Out of sort memory, consider increasing server sort buffer size
- HDFS: How to Operate API (Example)
- Warning: The serializable class * does not declare a static final serialVersionUID
- Nacos-client Call Error: failed to create cache dir [How to Solve]