各位:
厂家提供了一个dll,需要用regsvr32先注册,然后再调用。
我按照说明,先用regsvr32注册了dll,用VB的话调用没有问题,但用c#调用就报异常。
具体如下:
接口方法说明:
1、Login(网络服务器, 数据库名字, admin的密码, 返回的错误信息)
作用:登陆系统,调用其它方法前必须先调用它
返回值:0 - 成功,1 - 密码不正确,2 - 人员不存在
VB代码(测试通过):
Sub test()
Dim obj As Object
Dim sErr As String
Set obj = CreateObject("OperatorManager.OperManager", sErr)
s = obj.Login("127.0.0.1", "test2", "admin", sErr)
MsgBox s
MsgBox sErr
Set obj = Nothing
End Sub
c#代码(报异常):运行到oType.InvokeMember("Login", System.Reflection.BindingFlags.InvokeMethod, null, o, parts);
时报异常"调用的目标发生了异常"
System.Type oType = System.Type.GetTypeFromProgID("OperatorManager.OperManager");
object o = System.Activator.CreateInstance(oType);
string[] parts = new string[4];
parts[0] = "127.0.0.1";
parts[1] = "test2";
parts[2] = "admin";
oType.InvokeMember("Login", System.Reflection.BindingFlags.InvokeMethod, null, o, parts);
MessageBox.Show(parts[3]);
异常详细信息为:
未处理 System.Reflection.TargetInvocationException
Message=调用的目标发生了异常。
Source=mscorlib
StackTrace:
在 System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
在 System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
在 System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
在 TestService.Form3.button1_Click(Object sender, EventArgs e) 位置 E:\TestService\Form3.cs:行号 62
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 TestService.Program.Main() 位置 E:\TestService\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Runtime.InteropServices.COMException
Message=灾难性故障 (异常来自 HRESULT:0x8000FFFF (E_UNEXPECTED))
Source=""
ErrorCode=-2147418113
InnerException: