当前位置:   article > 正文

WindowsServer2019下Php(php-7.4.3-Win32-vc15-x64) 调用C# .dll文件_php vc15

php vc15

WindowsServer2019下Php(php-7.4.3-Win32-vc15-x64) 调用C# .dll文件

生成.dll

类库选择:在VS2019中选择,这个是不包含.core的类库
在这里插入图片描述

类库属性中 > 使程序集COM可见
在这里插入图片描述为程序集签名
在这里插入图片描述
测试.dll

namespace EncryptHelperWin
{
    public class EncryptHelper
    {       
        public string Write()
        {
            return "Hello World! WriteFunc.";
        }
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

php相关配置

拷贝生成的.dll文件到php的ext目录
在这里插入图片描述

使用RegAsm.exe进行注册。
在这里插入图片描述

用gacutil.exe进行缓存
在这里插入图片描述

修改php.ini文件,添加extension=php_com_dotnet.dll
在这里插入图片描述

重起php,即可测试.dll功能。
编写测试用rsadll.php文件

<?php 
$r=new COM("EncryptHelperWin.EncryptHelper");
$s=$r->Write();
echo $s;
?>
  • 1
  • 2
  • 3
  • 4
  • 5

测试结果如下
在这里插入图片描述【测试时产生 “未注册类” 错误进行的操作。如无此错误不需要此步】使用RegAsm.exe /regfile EncryptHelperWin.dll 生成注册表文件。导入注册表。
在这里插入图片描述

更新.dll文件

替换新版本的.dll文件

namespace EncryptHelperWin
{
    public class EncryptHelper
    {       
        public string Write()
        {
            return "Hello World! WriteFunc.Testdll.123.OK";
        }
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

用gacutil.exe进行缓存
在这里插入图片描述

重启php。测试结果如下。
在这里插入图片描述

搜索查阅了很多资料,并动手进行了测试,最终成功。希望对您有所帮助。

参考内容:

  1. https://www.php.cn/php-ask-497189.html
  2. https://www.it1352.com/405511.html
  3. https://www.cnblogs.com/menyiin/p/4793292.html
  4. https://www.yisu.com/zixun/349169.html
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号