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
    */
    }
    }
    }

  • 相关阅读:
    纹理mag filter不能取GL_XXX_MIPMAP_XXXX
    (转)No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=arm64, VA 解决办法
    轻松制作儿童趣味算术软件
    批处理设置IP地址
    安卓手机文件管理器简单横向评比
    Linux基础和网络管理上机试题
    值得收藏的批处理程序
    王垠:完全用Linux工作
    XINU安装程序.exe一键配置好XINU实验环境
    很全面的WinRAR实用技巧系列
  • 原文地址:https://www.cnblogs.com/liszt/p/1931826.html
Copyright © 2011-2022 走看看