从vbscript访问64位dll [英] Accessing 64 bit dll from vbscript

查看:67
本文介绍了从vbscript访问64位dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

jam

推荐答案

请按照以下步骤操作:

1)使用以下代码创建一个名为ClassLibrary1.dll的类库:

1) Create a Class Library named ClassLibrary1.dll with this code:

namespace ClassLibrary1
{
   [System.Runtime.InteropServices.ComVisible(true)]
   [System.Runtime.InteropServices.ProgId("ClassLibrary1.Class1")]
   public class Class1
    {
      public void f1()
      {
         System.Windows.Forms.MessageBox.Show(System.IntPtr.Size.ToString());
      }
    }
}

2)在项目"属性的构建"选项卡中,设置平台目标" = x64,并确保注册COM互操作"复选框是 已选中(我们将在步骤6中手动为64位注册dll)

2) In Project properties, Build tab, set Platform Target = x64 and ensure that "Register for COM Interop" checkbox is NOT checked (we will register the dll manually for 64-bit in step 6)

3)在项目"属性的签名"选项卡中,使用新的或现有的.snk文件对程序集进行签名

3) In Project properties, Signing tab, sign the assembly with a new or existing .snk file

4)构建dll

5)打开具有管理员权限的命令提示符

5) Open a Command Prompt with admin rights

6)执行此操作以将dll注册为64位COM组件:

6) Execute this to register the dll as a 64-bit COM component:

" C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ regasm.exe" /codebase< path> \ classlibrary1.dll"

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe" /codebase "<path>\classlibrary1.dll"

您应该收到一条消息类型注册成功"

You should get a message "Types registered successfully"

7)使用以下代码创建一个test.vbs脚本:

7) Create a test.vbs script with this code:

Dim o
Set o = CreateObject("ClassLibrary1.Class1")
Call o.f1

8)使用64位VBScript(使用文件夹system32来执行;对于32位,则使用  syswow64文件夹):

8) Execute it with the VBScript 64-bit (which uses the folder system32; for 32-bit it would use the folder  syswow64):

您应该获得一个值为8的MessageBox,这意味着dll的指针大小为64位

You should get a MessageBox with the value 8, which means that the pointer size of the dll is 64 bit


这篇关于从vbscript访问64位dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆