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

  • 相关阅读:
    你绝对想不到R文件找不到(cannot resolve symbol R)的原因
    你绝对想不到R文件找不到(cannot resolve symbol R)的原因
    如何安装gulp
    简单实现IE9及以下对placeholder的兼容性
    vue 新闻列表滚动效果
    2018数据技术嘉年华-金融峰会·重庆站即将起航!
    高手过招:用SQL解决环环相扣的刑侦推理问题(罗海雄版本)
    实战课堂:为什么更换存储之后一切正常但RAC集群启动不了?
    MySql避免重复插入记录方法(ignore,Replace,ON DUPLICATE KEY UPDATE)
    Druid数据库连接池和Druid内置监控系统简单介绍
  • 原文地址:https://www.cnblogs.com/liszt/p/1931826.html
Copyright © 2011-2022 走看看