我正在尝试为 VB6 DLL 创建一个 C# 包装器 DLL,然后在网页中将该包装器用作 ActiveXObject,但在调用 ClassTesting() 时出现此错误:
无法在 DLL 'VB6DLL' 中找到名为 'ClassTest' 的入口点。
应用程序将 DLL 导出到临时目录,然后将其加载到内存中。DLL的结构可以描述为:
VB6DLL.dll -> 公共类“VB6.cls” -> 公共函数“ClassTest()”。
C#代码如下:
namespace SystemDeviceDriver
{
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IDeviceDriver
{
[DispId(1)]
string ClassTesting();
}
[Guid("655EE123-0996-4c70-B6BD-7CA8849799C7")]
[ComSourceInterfaces(typeof(IDeviceDriver))]
public class DeviceDriver : IDeviceDriver
{
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("VB6DLL", CharSet = CharSet.Unicode)]
static extern string ClassTest();
public DeviceDriver()
{
//Write the VB6DLL to a temp directory
string dirName = Path.Combine(Path.GetTempPath(), "SystemDeviceDriver." + Assembly.GetExecutingAssembly().GetName().Version.ToString());
if (!Directory.Exists(dirName))
{
Directory.CreateDirectory(dirName);
}
string dllPath = Path.Combine(dirName, "VB6DLL.dll");
File.WriteAllBytes(dllPath, SystemDeviceDriver.Properties.Resources.VB6DLL);
//Load the library into memory
IntPtr h = LoadLibrary(dllPath);
Debug.Assert(h != IntPtr.Zero, "Unable to load library " + dllPath);
}
public string ClassTesting()
{
return ClassTest();
}
}
}