【问题标题】:Hello world VB.NET class library, called from PHPHello world VB.NET 类库,从 PHP 调用
【发布时间】:2012-06-14 18:32:25
【问题描述】:

这是 AssemblyInfo.vb:

Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices

' General Information about an assembly is controlled through the following 
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.

' Review the values of the assembly attributes

<Assembly: AssemblyTitle("ClassLibrary1")> 
<Assembly: AssemblyDescription("")> 
<Assembly: AssemblyCompany("")> 
<Assembly: AssemblyProduct("ClassLibrary1")> 
<Assembly: AssemblyCopyright("Copyright ©  2012")> 
<Assembly: AssemblyTrademark("")> 

<Assembly: ComVisible(True)> 

'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("bd484c72-e166-4480-a1fd-71ab12e09e25")> 

' Version information for an assembly consists of the following four values:
'
'      Major Version
'      Minor Version 
'      Build Number
'      Revision
'
' You can specify all the values or you can default the Build and Revision Numbers 
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")> 

<Assembly: AssemblyVersion("1.0.0.0")> 
<Assembly: AssemblyFileVersion("1.0.0.0")> 

这是课程:

Public Class Class1
    Public Sub HelloWorld()
        MsgBox("hello, world")
    End Sub
End Class

在将 DLL 放入 regasm.exe 后,我尝试从 PHP 访问它。没有反应。

[编辑:现在通过 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe 运行它后,我遇到了一个强名称错误,我我现在正在工作。]

有没有人有可以通过 PHP 5 访问的 .NET DLL 的 Hello world 示例(如果我没记错的话,是“类库”的另一个词)?到目前为止,我是否在使用这种方法的正确道路上?

这是怎么做到的?感谢您的帮助。

这是 PHP 代码顺便说一句:

<?php
 $obj = new COM("ClassLibrary1.Class1");
 $output=$obj->HelloWorld();
 echo $output;
?>

【问题讨论】:

  • 为什么使用 COM?为什么不使用 DOTNET?
  • 如果您在帖子底部谈论我的 PHP 代码,谢谢!这看起来是错误的(不是吗?),并且在我开始将 COM 工作开始更多地转向 .NET 解决方案之后,我再也没有重新审视过。你建议应该是 DOTNET()?那我楼上的其他代码呢,可以吗,还是应该不同?感谢您的指导。
  • 是的,我不是 COM 程序集方面的专家,但在我看来,既然您有一个 .NET 项目,您可以尝试使用 DOTNET 加载 .NET 程序集。 php.net/manual/en/class.dotnet.php
  • 谢谢。将继续努力。

标签: php .net vb.net com com-interop


【解决方案1】:

PHP 在作为服务运行的 Web 服务器上运行是很正常的 -- 除非您经历了很多困难,否则这些无法与桌面交互,所以有您的MessageBox 无处可显示。

【讨论】:

    猜你喜欢
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-20
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多