上位机开发--C#调用C做的库dll

void Swap(int* a, int* b)
{
    int c = *a;
    *a = *b;
    *b = c;
}

https://www.cnblogs.com/notnolyblogs/p/6015933.html
错误1 Swap首字母大写!
错误2 原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。
参考:https://blog.csdn.net/jacke121/article/details/78617972
  [DllImport("test.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
  可以了!!
  
        private void button1_Click(object sender, EventArgs e)
        {
            int a = 1;
            int b = 2;

            unsafe
            {
                Swap(&a, &b);
        }}
        debug看到执行了 !!!!
        
进阶:
危胜中的des解压以后 注销table.h里面//extern static BoolType SubKey[16][48];     

+++++++++++++++++++

cmd

cd C:\MinGW\bin

gcc -shared -o DES.dll DESalgorithm.c

问题 可以KEIL加载吗?

 

++++++++++++++++++   
然后gcc -shared -o DES.dll DESalgorithm.c(在目录下启动CMD 在目录下放置3个文件)
出来了dll
第一步加入:
  public partial class Form1 : Form
    {

        [DllImport("DES.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void PlayDes(byte[] MesOut, byte[] MesIn);

        [DllImport("DES.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void SetKey(byte[] KeyIn);
第二部:调用1
  public Form1()
        {
            InitializeComponent();
            byte[] pwd = new byte[8];
            pwd[0] = pwd[1] = pwd[2] = pwd[3] = pwd[4] = pwd[5] = pwd[6] = pwd[7] = 0xFF;
            SetKey(pwd);
        }
        第二部:调用2
        private void button1_Click(object sender, EventArgs e)
        {
            byte[] IN = new byte[8];
            byte[] OUT =new byte[8];
            IN[0] = IN[1] = IN[2] = IN[3] = IN[4] = IN[5] = IN[6] = IN[7] =0X11;
            unsafe
            {
                PlayDes(OUT,IN);
            }

        }
        看到结果正确!!!!!!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值