zoukankan      html  css  js  c++  java
  • 写入DLL文件

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;

    namespace WindowsApplication1
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }


    [DllImport("kernel32")]
    private static extern int GetPrivateProfileString
    (string section, //欲在其中查找条目的小节名称。这个字串不区分大小写。如设为vbNullString,就在lpReturnedString缓冲区内装载这个ini文件所有小节的列表
    string key, //欲获取的项名或条目名。这个字串不区分大小写。如设为vbNullString,就在lpReturnedString缓冲区内装载指定小节所有项的列表
    string def, //指定的条目没有找到时返回的默认值。可设为空("")
    StringBuilder retVal, //指定一个字串缓冲区,长度至少为nSize
    int size, //指定装载到lpReturnedString缓冲区的最大字符数量
    string filePath);//初始化文件的名字。如没有指定一个完整路径名,windows就在Windows目录中查找文件
    /*
    例子:
    *
    * section: [111]
    * key: 123=huze
    * huze是键入的值
    */
    [DllImport("kernel32")]
    private static extern long WritePrivateProfileString(
    string section, //要在其中写入新字串的小节名称。这个字串不区分大小写
    string key, //要设置的项名或条目名。这个字串不区分大小写。用vbNullString可删除这个小节的所有设置项
    string val, //指定为这个项写入的字串值。用vbNullString表示删除这个项现有的字串
    string filePath);//初始化文件的名字。如果没有指定完整路径名,则windows会在windows目录查找文件。如果文件没有找到,则函数会创建它
    private void button1_Click(object sender, EventArgs e)
    {
    textBox1.Text = ReadIniReg("111", "123");
    }
    public static string ReadIniReg(string Section, string Key)
    {
    StringBuilder retVal = new StringBuilder(0xff);
    GetPrivateProfileString(Section, Key, "", retVal, 0xff, Application.StartupPath + "\\123.dll");
    return retVal.ToString();
    }
    public static void WriteintReg(string Section, string Key, string Value)
    {
    WritePrivateProfileString(Section, Key, Value, Application.StartupPath + "\\123.dll");
    }

    private void button2_Click(object sender, EventArgs e)
    {
    WriteintReg("111", "123", this.textBox2.Text);
    WriteintReg("222", "234", this.textBox3.Text);
    /* [111]
    * 123=huze
    * [222]
    * 234=mengzi
    */
    }
    }
    }

  • 相关阅读:
    将Apache2.4手动安装成Windows的服务
    [译文]PHP千年虫(y2k compliance)
    Apache2.4 authz_core_module模块使用
    Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.错误
    [转载]开启debug调试模式
    thinkphp 去掉URL 里面的index.php
    在WINDOWS下安装PEAR
    php5.5.15注释问题PHP Deprecated: Comments starting with '#' are deprecated in *.ini 警告解决办法
    Maven 与 IntelliJ IDEA 的完美结合
    JavaRebel 2.0 发布,一个JVM插件
  • 原文地址:https://www.cnblogs.com/liszt/p/1931826.html
Copyright © 2011-2022 走看看