zoukankan      html  css  js  c++  java
  • 互操作性——使用C/C++类型的非托管函数基础

    1、使用微软的C运行库msvcrt.dll提供的方法和Win32 API提供的函数进行平台调用
    代码如下:

        class Program
        {
            //微软的C运行库msvcrt.dll提供的puts方法
            [DllImport("msvcrt.dll")]
            static extern int puts(string msg);
    
            [DllImport("msvcrt.dll")]
            static extern int _flushall();
    
            //Win32 API提供的函数进行平台调用
            [DllImport("user32.dll", EntryPoint = "MessageBox")]
            public static extern int MessageBox(int hwnd, string lpText, string lpCaption, int wType);
    
            static void Main(string[] args)
            {
                puts("hello world test!");
                _flushall();
                MessageBox(0, "Hello world Test!", "Title is here", 0);
            }      
        }
    

    2、工具的使用。要查看DLL中包含的函数信息,可以用的工具有:Depends.exe、dumpbin.exe、PE Explorer等

    使用dumpbin的形式如下:

     3、使用EntryPoint字段对函数进行重命名

            [DllImport("NativeLib.dll",EntryPoint="PrintMsg")]
            public static extern void PrintMsgRename(string msg);
    

    PrintMsg必须与非托管的函数名一致,PrintMsgRename就是重命名的函数名。

  • 相关阅读:
    Java静态方法中使用注入类
    Java FTP辅助类
    Java SFTP辅助类
    MyBatis学习总结——批量查询
    MyBatis学习总结—实现关联表查询
    Redis集群搭建与简单使用
    SQL管理工具
    MySQL锁机制
    MySQL权限管理
    yii框架下使用redis
  • 原文地址:https://www.cnblogs.com/linlf03/p/2189422.html
Copyright © 2011-2022 走看看