2

I am working on an old VB6 app and have recently added the Siemens OPC component. When running in VB6 debugger I have no problems.

I then created a deployment package (Siemens OPC dlls included in the package) and deployed the app on the same PC. I then get the following error message when accessing the OPC object:

'Method ~ of object ~ failed'

Can anyone suggest what might be causing this or what I can do to get more information?

UPDATE I am aware of other questions around this error message. What is puzzling me here is that there are no problems when using the VB debugger. The problems occur after deployment - even on the same machine. I would have thought that all the components remain registered and available.

CODE

Public Sub InitialiseOPC(ServerIP As String, OpcServerName As String, BaseAddress As String)
    On Error GoTo ProcError
    IsInitialised = False

    Set MyOpcServer = New OPCServer
    Dim LocalServers

    LocalServers = MyOpcServer.GetOPCServers(ServerIP)
    ....

The error occurs when GetOPCServers is called. This is the first time the OPC component is accessed.

Is there any way to trace what VB is doing at this time (e.g. dll loading) ?

UPDATE

I tried deploying the Siemens dlls to the application folder instead of the default locations and this error message no longer appears.

paul
  • 13,312
  • 23
  • 81
  • 144

1 Answers1

4

Method ~ of object ~ failed is generated when an exception (SEH) is thrown during a late-bound call. VB6 makes the effort to "wrap" each late-bound call to catch such unexpected behavior.

In your case most probably a VC component is trying to load a dependent DLL or COM object and fails but does not handle the failure gracefully. Instead it tries to call a method on the empty reference and bombs with an Access Violation or similar exception.

Community
  • 1
  • 1
wqw
  • 11,771
  • 1
  • 33
  • 41
  • +1 Thanks. Any idea why the loading might fail when running in the EXE but not in debug? Can I get more trace information? – paul Jan 11 '12 at 10:42
  • 2
    Try to locate method call that fails to get an idea what's happening. Loading a DLL can fail if file is not found in current folder or global path variable. – wqw Jan 11 '12 at 11:11
  • I just added an update with code. The dlls are installed to the default locations - c:\windows and c:\program files\common files\siemens\opc. All dlls used by the project are installed to the default locations. Would you suggest installing everything to the local folder? – paul Jan 11 '12 at 13:35
  • I tried deploying the Siemens dlls to the application folder and *that* problem has disappeared - on to the next one now :-( – paul Jan 11 '12 at 13:59
  • I'm not sure this is a valid fix, but a problem detour that may break any other applications using these DLLs if this application is removed. Assuming these are COM DLLs, your VB6 program is probably hijacking the component registration to point to your "private" copies of the DLLs. This can have additional confusing consequences on a UAC system. Were these DLLs ever properly registered in their original locations? – Bob77 Jan 13 '12 at 14:13