通过包装器 dll 访问 Web 服务中的 X64 静态库

Accessing X64 Static library in webservice through Wrapper dll

本文关键字:X64 静态 服务 Web 包装 dll 访问      更新时间:2023-10-16

我有一个静态库X64位。我创建了一个包装器并通过控制台应用程序执行,它工作正常。当我使用相同的包装器 dll 并尝试通过 Web 服务公开方法时,出现错误。

代码片段:包装纸

#include "Header.h"
#include "sonobox.hpp"
namespace MyWin32DLL
{
    MyWin32ClassOne::MyWin32ClassOne()
    {
        varone = 123;
    }
   __declspec(dllexport) int MyWin32ClassOne::getoutput()
        {
                    uikey=GetKey();
        }
        return uikey;
    }
} 

WEb服务:-

public class WebService1 : System.Web.Services.WebService
    {
        [DllImport("Win32Project2.dll", CharSet = CharSet.Unicode)]
        public static extern int getoutput();
        [WebMethod]
        public int HelloWorld()
        {          
           return getoutput();
        }
    }

错误:-无法加载文件或程序集"****"或其依赖项之一。尝试加载格式不正确的程序。

拜托嘻嘻!

此错误的最常见原因是位数不匹配。该过程为 32 位,故障程序集为 64 位。反之亦然。如果是这样,那么您有两种可能的解决方案:

    使用 32 位
  1. 版本的静态库生成程序集的 32 位版本。
  2. 确保 Web 服务在 64 位进程中执行。