为 64 位操作系统包装 32 位 dll,以便与 regsvr32.exe 一起使用
我们目前正在将网站从 Windows 2003(32 位)转移到 Windows 2008(64 位),但遇到了问题。
我们的一个网站使用支付网关汇丰CPI,它需要注册一个DLL(regsvr32.exe),然后在经典的asp网站中使用该DLL。 问题是该 DLL 是 32 位 DLL,因此它不会在 Windows 2008 操作系统中注册。
有没有一种方法可以将这个 32 位 dll 包装在 ac#.net 项目中,以便公开它的方法并可以在操作系统中注册?
任何帮助将非常感激。
We are currently transferring our websites from Windows 2003 (32-bit) to Windows 2008 (64-bit) and have hit a problem.
One of our website use the payment gateway HSBC CPI which requires a DLL to be registered(regsvr32.exe), this DLL is then used inside a classic asp website. The problem is the DLL is a 32-bit DLL and so it will not register with the the Windows 2008 operating system.
Is there a way we can wrap this 32 bit dll in a c#.net project so that it's methods are exposed and can be registerd with the OS?
Any help would be very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 C:\Windows\SysWOW64 文件夹中的 regsvr32.exe 注册 DLL。
但是,由于您无法混合 64/32 位代码,因此您必须创建一个在 x86 中运行的 C# 服务(请参阅项目属性、平台目标),然后您可以通过 WCF 从 x64 Web 应用程序中使用该服务。
一个更简单的选择是向 HSBC 索要 x64 dll。
You can register the DLL with regsvr32.exe from the C:\Windows\SysWOW64 folder.
However since you can't mix 64/32bit code you'd have to create a C# service running in x86 (see the project properties, platform target) that you can then use from your x64 web app via WCF.
An easier option would be to ask HSBC for a x64 dll.
如果您想注册使用 VC++ 或 Visual Basic 6.0 创建的 32 位 COM dll,则必须按照以下步骤操作,而不对代码进行任何更改。 它也不需要完成任何编译,而且您也不必在 WOW 模式下运行 IIS。 几年前我遇到过这个问题,我解决了这个问题,它对我来说效果很好。
场景:
假设您有一个由供应商提供的第 3 方 32 位 COM DLL。 该 DLL 在 32 位操作系统上工作正常,当您转移到 x64 环境时,即使您尝试通过 regsv32 注册它,它也无法工作。
另外让我假设 DLL 的名称是“ASXUpload.DLL”。 我将在下面提供的解决方案中使用这个名称。
解决方案
请按照以下步骤操作:
首先,如果您已经在 x64 操作系统中注册了 DLL,请取消注册 DLL。 为此,只需在运行命令“regsvr32 /u”中键入以下内容,例如“regsvr32 /u C:\MyDLL\ASXUpload.DLL”。 如果您已经从 x64 操作系统中注销了 DLL,则无需运行此步骤。
还要确保您没有将 DLL 保存在 Windows 文件夹中,该文件夹通常为 C:\Windows。 对于本示例,我已将 DLL 保存在以下文件夹 C:\MyDLL 中。
现在我们需要使用 Microsoft 的组件服务添加 COM+ 组件。 要启动组件服务,请转至控制面板/管理工具/组件服务。 进入组件服务后,深入查看计算机、我的电脑、COM+ 应用程序。 然后右键单击COM+应用程序并选择“新建”-> “应用程序”。
在“欢迎使用 COM 应用程序安装向导”屏幕上,单击“下一步 >”。
单击“创建空应用程序”按钮。
输入名称。 由于我的 DLL 名称是 ASXUpload.dll,因此我输入的名称为“ASXUpload”。 当询问“库或服务器”时,选择“服务器”。
点击“下一步>” 按钮,然后选择“此用户”。
输入用户或单击“浏览”选择用户。 单击“浏览”更安全,可以确保使用正确的域和拼写。 输入密码并确认密码。 警告,如果需要,请务必包含域/用户名。 单击“完成”。 (注意:我们推荐“此用户”,否则,必须有人登录到服务器才能运行 DLL。)。 就我而言,我选择了域管理员帐户。 您还可以添加服务帐户。 如果您不确定,请咨询您的系统管理员。
现在将出现“添加应用程序角色”屏幕。 不要添加任何内容,只需单击“下一步>” 按钮。
现在出现“将用户添加到角色”屏幕。 不要添加任何内容,只需单击“下一步>” 按钮。
现在您将在组件服务 -> 下看到它 计算机 -> 我的电脑 -> COM+应用程序-> 您将看到新添加的应用程序。 在此示例中,应用程序名称为“ASXUpload”。 现在,通过单击“+”图标向下钻取新添加的应用程序“ASXUpload”,您将看到“组件”。
现在右键单击“组件”,然后选择“新建组件”。 在“欢迎使用 COM 应用程序安装向导”屏幕上,单击“下一步 >”。
单击“安装新组件”,然后选择您要注册的 DLL。 在这种情况下,它将是“C:\MyDLL\ASXUpload.DLL”。
选择 DLL 后,您将看到它会显示找到的组件。 单击“下一步>” 按钮继续,最后点击“完成”按钮完成。
现在是棘手的部分。 右键单击您添加的应用程序,您将在“组件服务”->“组件服务”下找到该应用程序。 计算机 -> 我的电脑 -> COM+ 应用程序。 就我而言,应用程序名称是“ASXUpload”。 右键单击应用程序后,选择“属性”。 应用程序属性窗口将打开。 单击“安全”选项卡。 在“安全”选项卡中,确保“授权”部分下的“强制执行此应用程序的访问检查”复选框未被选中。
在“安全级别”部分下,选择单选按钮“仅在进程级别执行访问检查”。 安全属性不会包含在对象上下文中。 COM+ 安全调用上下文将不可用。”
确保未选中“应用限制策略”选项。
将“模拟级别”设置为“匿名”
如果您想从 Web 应用程序访问 DLL,请确保添加 IUSR 和 IWAM 帐户。 为此,请转至 COM+ 应用程序 -> 应用程序名称(在本例中为 ASXUpload)-> 角色 -> 创建所有者-> 用户。 右键单击用户并添加 Internet Information Server 使用的 IUSR 和 IWAM 帐户。
还要对保存 DLL 的文件夹设置 NTFS 权限。 在本例中,我将 DLL 保留在文件夹 C:\MyDLL 中。 现在右键单击文件夹“MyDLL”并转到安全选项卡,然后添加 IUSR 和 IWAM 帐户。
这就是您需要做的全部事情,并且您应该能够使用该 DLL。
我曾在过去在生产环境中工作过的两个不同组织中使用过该技术两次,并且它的工作没有任何问题。 我首先在 2005 年尝试过此方法,然后在 2008 年再次使用它。
如果您遇到任何问题,请告诉我。
If you want to register the 32-bit COM dll created using VC++ or Visual Basic 6.0 then you have to follow the steps below without making any changes in the code. It also does not require any compilation to be done and also you do not have to run the IIS in WOW Mode. I have faced this issue few years back and I resolved this issue and it works fine for me.
Scenario:
Let me assume that you have a 3rd party 32-bit COM DLL provided by a vendor. The DLL works fine on 32bit Operating system and the moment you move to a x64 environment it does not work even though you have tried to register it through regsv32.
Also let me assume that the name of the DLL is "ASXUpload.DLL". I will use this name in the solution which I am providing below.
Solution
Please follow the steps below:
First of all if you have already registered the DLL in x64 Operating System the unregister the DLL. To do that just type the following in the run command "regsvr32 /u " something like "regsvr32 /u C:\MyDLL\ASXUpload.DLL". If you have already unregistered the DLL from the x64 OS then no need to run this step.
Also make sure that you have not kept your DLL inside the Windows folder which is normally C:\Windows. For this example I have kept the DLL in the following folder C:\MyDLL.
Now we need to add the COM+ Components using Component Services of Microsoft. To start Component Services, go to Control Panel / Administrative Tools/ Component Services. Once inside component Services, drill down into Computers, then My Computer, then COM+ Applications. Then Right-click on COM+ Applications and choose "New" -> "Application".
At "Welcome to the COM Application Install Wizard" screen, click “Next >”.
Click on “Create an Empty Application” button.
Enter the name. Since my DLL name is ASXUpload.dll so I have typed in the name as “ASXUpload”. When asked "Library or Server", select “Server”.
Click “Next >” button and then choose “This User”.
Enter the User or click Browse to select the user. Clicking Browse is safer, to ensure that the correct domain and spelling are used. Enter the password and confirm the password. Warning, be sure to include the domain/username if required. Click on “Finish”. (Note: We recommend "This User", otherwise, someone must be logged onto the server in order for DLL to run.). In my case I have chosen the domain administrator account. You can also add a Service Account. If you are not sure please consult with your system administrator.
Now “Add Application Roles” screen will appear. Do not add anything just click on the “Next >” button.
Now “Add Users to Role” screen appear. Do not add anything just click on the “Next >” button.
Now you will see that under Component Services -> Computers -> My Computer -> COM+ Application -> you will see the newly added application. In this example the application name would be "ASXUpload". Now drill down the newly added application “ASXUpload” by clicking the “+” icon and you will see “Components”.
Now right-click on “Components” and then choose “New Component”. At "Welcome to the COM Application Install Wizard" screen, click “Next >”.
Click on “Install new component(s)” and now select the DLL which you want to register. In the case it would be “C:\MyDLL\ASXUpload.DLL”.
Once you select the DLL you will see that it will show you the components found. Click on the “Next >” button to proceed and finally hit the “Finish” button to complete.
Now is the tricky part. Right click on the application you have added which you will find under Component Services -> Computers -> My Computer -> COM+ Application. In my case the application name is “ASXUpload”. After you right click on the Application select “Properties”. The application properties window will open up. Click on the “Security” tab. In the Security tab make sure that under “Authorization” section the checkbox “Enforce access checks for this application” is unchecked.
Under “Security Level” section select the radio button “Perform access checks only at the process level. Security property will not be included on the object context. COM+ security call context will not be available.”
Make sure that option “Apply restriction policy” is unchecked.
Set “Impersonate Level” to “Anonymous”
If you want to access the DLL from web Application then make sure that you add the IUSR and IWAM account. To do this go to COM+ Application -> Application Name (In this case it will be ASXUpload) -> Roles -> CreateOwner -> Users. Right click on the Users and add the IUSR and IWAM account used by Internet Information Server.
Also set the NTFS permission on the folder where you kept the DLL. In this case I have kept the DLL inside the folder C:\MyDLL. Now right click on the folder “MyDLL” and go to the security tab and then add the IUSR and IWAM account.
This is all you need to do and you should be able to consume the DLL.
I have used this technique twice in two different organizations I have worked in the past on the Production Environment and it works without any issues. First I tried this in the year 2005 and then I used it again in 2008.
Let me know if you are facing any issues.
我们在 HSBC Cpi 接口上也遇到了同样的问题。
汇丰银行不提供 .Net 包装器和 COM 包装器
无法从 64 位应用程序调用。
这使得从 64 位服务器(可能是
覆盖 25% 的新生产服务器)实际上是不可能的。
我们查看了列出的一些方法,但它们似乎
很多工作。 最后,经过一番混乱之后,我们
提出了我们自己的实现,看起来像
这。
使用以下Java代码获取中间哈希
然后使用以下.net代码计算哈希
We hit the same problems with the HSBC Cpi interface.
HSBC don't supply a .Net wrapper, and the COM wrapper
can not be called from a 64bit app.
This makes deploying it from on a 64 server (which probably
covers 25% of new production servers) practically imposible.
We looked at some of the approaches listed, but they seemed like
a lot of work. In the end after a bit of messing around we
came up with our own implementation, which looks something like
this.
Use the following Java code to get the intermediate hash
Then use the following .net code to calcualte the hash