Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic

What does this error mean in VB6?

Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic.

I keep getting it when i call a particular method of a dll that comes with windows xp and beyond (in system32 called upnp.dll)

like image 205
Erx_VB.NExT.Coder Avatar asked Oct 19 '10 06:10

Erx_VB.NExT.Coder


2 Answers

This is the declaration for FindByType() as retrieved from the type library:

    HRESULT FindByType(
                    [in] BSTR bstrTypeURI, 
                    [in] unsigned long dwFlags, 
                    [out, retval] IUPnPDevices** pDevices);

Note the 2nd argument, unsigned long. VB6 doesn't support unsigned types. It is not a problem in VB.NET or C#, they do support them.

This problem is fixable if you have the Windows SDK installed. You should have it if you have a recent version of Visual Studio. Use the Visual Studio Command Prompt, then:

  • run oleview.exe c:\windows\system32\upnp.dll
  • type Ctrl+A, Ctrl+C to copy the type library content
  • run notepad.exe, Ctrl+V. Search for "unsigned" and delete it. There are two.
  • save the file to a temporary directory with the name upnp.idl
  • run midl upnp.idl /tlb upnp.tlb
  • copy the generated upnp.tlb to your project directory

You can now add upnp.tlb instead of upnp.dll, you should no longer get the error. -

like image 84
Hans Passant Avatar answered Nov 07 '22 21:11

Hans Passant


Well, the error message means that you're calling a function that can't be bound by VB6, possibly due to it have parameters or a return value of a data type that VB6 doesn't support. I sometimes worked around issues like this by writing a simple C++ COM object that called the function and "translated" it to be VB6 compatible.

You can sometimes also get this error message due to various typos, but I think you've already discovered that with your search on google so I'm assuming you've already checked for that.

If you post your code (or at least the name of the function that you're having problems with) it's possible that you could get a better answer.

like image 3
Hans Olsson Avatar answered Nov 07 '22 20:11

Hans Olsson