今天给各位分享c语言调用c的dll文件路径的知识,其中也会对c如何引用dll文件进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
1、c语言怎么调用dll文件2、C语言调用dll3、如何用C#调用C编写的dll4、C# 中如何调用DLL文件?
c语言怎么调用dll文件
(1)编写程序时,你要包含(#include “什么.h”) dll文件作者提供 的 头文件(.h文件) 。
程序里,便和普通函数调用一样,去调用它的函数。
(2)程序编译时,你要链接 dll文件作者提供 的 (.lib文件) 库文件。
当然,你可以在源程序里把.lib 名字 写上,编译时自动去链接,例子:
#pragma comment (lib, “什么.lib”)
(3)执行时,要有 .dll 文件. 放在当前文件夹或系统文件夹里。
C语言调用dll
这个相对路径是你当前代码存放的位置.
实际应用中相对路径比绝对路径实用多了.
比如你可以再代码路径上再创建一个文件夹,命令dll,里面放所有的dll文件
那么你此时路径”.\\dll\\test.dll”
你可以发给我,我帮你看看
如何用C#调用C编写的dll
使用C#生成dll文件并调用
一、创建dll文件:
例如生成一个md5编码判断状态的文件,即,输入一个字符串(string A)和一个32位md5编码(string B),判断此字符串A对应的32位md5编码是否与B相等,如果相等返回true,否则返回false。
打开VS 2005,“文件”–》“新建”–“项目”,选择“Windows 控件库”,命名后点击“确定”,在“UserControl1.cs”中输入以下代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Text;
using System.Security.Cryptography;
namespace md5
{
public partial class Program : UserControl
{
#region MD5 32位加密:GetMd5Str32
/// summary
/// 32位MD5加密
/// /summary
/// param name=”strSource”待加密字串/param
/// returns加密后的字串/returns
public static string GetMd5Str32(string strSource)
{
byte[] bytes = Encoding.ASCII.GetBytes(strSource);
byte[] hashValue = ((System.Security.Cryptography.HashAlgorithm)System.Security.Cryptography.CryptoConfig.CreateFromName(“MD5”)).ComputeHash(bytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i 16; i++)
{
sb.Append(hashValue[i].ToString(“x2”));
}
return sb.ToString().ToUpper();
}
#endregion
#region 核对md5编码是否一致:CheckMd5String()
/// summary
/// 核对md5编码是否一致
/// /summary
/// param name=”ConvertString”/param
/// returns如果一致返回true,否则返回false/returns
///
public static bool CheckMd5String(string str1, string str2)
{
string md5String = str1; //需要验证的字符串
string md5DbString = str2; //需要核对的32位md5编码
int result = string.Compare(md5.Program.GetMd5Str32(str1), md5DbString, true);
if (result == 0)
{
return true;
}
else
{
return false;
}
}
#endregion
}
}
修改“UserControl1.Designer.cs”中的命名空间为“md5”,方法为“Program”,即可生成dll文件。
在…\bin\Debug文件假下,可以找到相应的dll文件。
二、部署dll流程:
首先把dll文件放到应用程序…\bin\Debug\下;
然后在解决方案中添加引用:右键鼠标–添加引用–浏览–选择dll放置路径后点击“确定”。
注意:要在应用文件头处使用using md5;命令。
测试应用程序代码,如下:Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using md5;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string str1 = textBox1.Text.ToString();
string md5String = textBox2.Text.ToString();
textBox3.Text = md5.Program.GetMd5Str32(str1);
textBox4.Text = md5.Program.CheckMd5String(str1, md5String).ToString();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
三、注意点:
1、在C#应用程序开发过程中,加载dll文件时,报错“未能加载文件或程序集“md5, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。系统找不到指定的文件。”,请指点一下是什么原因?
解决:这是因为加载dll的路径问题,正确加载方式为:在“解决方案”的“引用”文件上右击鼠标,选择“添加引用”—》在“浏览”选项卡中添加引用(注意:自己定义的dll文件不能在“.NET”选项卡中添加。)
C# 中如何调用DLL文件?
C# 中如何调用DLL文件的方法是:
有命名空间则引入命名空间,dll里面,是a命名空间,有一个b类,然后有一个无参数静态方法c
那么调用方法就是a.b.c()。
然后是非托管dll
需要添加dll的名称,以及方法,也就是你所用到的dll的每个方法都需要添加一次,
[DllImport(“msvcrt.dll”)]
public static extern int puts(string c);
c语言调用c的dll文件路径的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于c如何引用dll文件、c语言调用c的dll文件路径的信息别忘了在本站进行查找喔。