简体   繁体   English

找不到 pinvoke dll 'kernel32'

[英]cannot find pinvoke dll 'kernel32'

i want to use ini file in my program using windows CE device.我想在使用 Windows CE 设备的程序中使用 ini 文件。 and i got the exception "cannot find pinvoke dll 'kernel32'" what should I do to solve this?我得到了异常“找不到 pinvoke dll 'kernel32'”我应该怎么做才能解决这个问题? please help me!请帮我!

string Path = "c:\\Settings.ini";
        [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);

    public string Read(string Section,string Key,string Value)
    {
        StringBuilder sb = new StringBuilder();
        GetPrivateProfileString(Section, Key, Value, sb, 32, Path).ToString();           // Error occured!!
        return sb.ToString();
    }

it works at vs2017 but not vs2008.它适用于 vs2017 但不适用于 vs2008。 please.请。 give me your answer!给我你的答案!

Firstly首先

Your version of Visual Studio will not normally make one difference to the compatibility of a Windows API call.您的Visual Studio版本通常不会对Windows API调用的兼容性产生任何影响。

Secondly其次

You are calling an Windows API that is not supported in Windows CE您正在调用Windows CE不支持的Windows API

Thirdly第三

INI files are an old technology and replaced largely by config files, this is the way the world has moved INI文件是一项古老的技术,主要被配置文件取代,这就是世界移动的方式

Lastly最后

If you really have the need to read and write INI files, just download a Nuget that supports it out of the box (which doesn't rely on the Windows APIs) and save your self a lot of trouble如果你真的需要读写INI文件,只需下载一个支持它的开箱即用的Nuget (不依赖Windows APIs),省去你自己很多麻烦

Michael Randall makes some very valid points in his answer, though in case you are editing files from older programs, an ini handler can still be useful, and for simple human-readable config files, ini does remain handy, in my opinion; Michael Randall 在他的回答中提出了一些非常有效的观点,尽管如果您正在编辑旧程序中的文件,ini 处理程序仍然有用,并且对于简单的人类可读的配置文件,在我看来,ini 确实很方便; I find xml to be awful to actually open in a text editor to change settings, and registry settings are the exact opposite of portable.我发现 xml 在文本编辑器中实际打开以更改设置非常糟糕,而注册表设置与可移植完全相反。

So, if all you need is an ini handler, I wrote a small free library for that a couple of years ago, to handle the files of an old game that used ini format for all its settings and missions.因此,如果您只需要一个 ini 处理程序,几年前我为此编写了一个小型免费库,以处理使用 ini 格式进行所有设置和任务的旧游戏的文件。

You can download it here:您可以在这里下载:
http://nyerguds.arsaneus-design.com/project_stuff/2013/nyerguds.ini/ http://nyerguds.arsaneus-design.com/project_stuff/2013/nyerguds.ini/

Mirror:镜子:
http://www.mediafire.com/file/ldebjkppf59j13r/nyerguds.ini.zip http://www.mediafire.com/file/ldebjkppf59j13r/nyerguds.ini.zip

Note that unlike most ini implementations, which just search the line and return the value, this loads the entire file into memory and translates all contents to objects, and keeps track of what is modified, so while it is useful for small configuration files, it is not advised to use it for larger data handling.请注意,与大多数仅搜索行并返回值的 ini 实现不同,这会将整个文件加载到内存中并将所有内容转换为对象,并跟踪修改的内容,因此虽然它对于小型配置文件很有用,但它不建议将其用于较大的数据处理。 A while back, some people used it in an online play system to scan the contents of a whole bunch of game maps that were in an ini-based format, and that turned out to be pretty slow.前阵子,有人用它在在线游戏系统中扫描一大堆基于ini格式的游戏地图的内容,结果证明速度很慢。

Also note that it is text-encoding aware , and defaults to UTF-8, so if you are actually reading some old program's setting, you may need to set it to load as Windows-1252, or, in case of DOS programs, DOS-437.另请注意,它支持文本编码,并且默认为 UTF-8,因此如果您实际上正在阅读某些旧程序的设置,则可能需要将其设置为加载为 Windows-1252,或者,如果是 DOS 程序,则为 DOS -437。 Since I was working with DOS files when making this, there is a static preset shortcut to DOS-437 called ENCODING_DOS_US offered by the class.由于我在制作此文件时使用的是 DOS 文件,因此类提供了一个静态预设快捷方式,称为ENCODING_DOS_US到 DOS-437。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM