[英]C# P/Invoke embedded VB6 DLL resource: ActiveXObject “Unable to find an entry point named 'FunctionName' in DLL 'DLLName'.”
我正在尝试为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();
}
}
}
DllImport / P / Invoke函数用于包含“旧C样式” dll文件,因此可以从库中导出简单的简单函数
这是列出的调用方法,可能的功能类型为: http : //msdn.microsoft.com/de-de/library/system.runtime.interopservices.callingconvention.aspx
COM完全不同,请参见: http : //en.wikipedia.org/wiki/Component_Object_Model
COM dll通常导出的唯一功能是DllRegisterServer,DllUnregisterServer,您可以首先使用P / Invoke函数来调用该函数。 COM dll文件将自己注册到注册表中。 那么应该可以创建一个COM对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.