Function or interface marked as restricted, or the

2019-01-15 20:01发布

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)

3条回答
女痞
2楼-- · 2019-01-15 20:24

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. -

查看更多
不美不萌又怎样
3楼-- · 2019-01-15 20:26

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.

查看更多
小情绪 Triste *
4楼-- · 2019-01-15 20:30

I got the same error but when I changed my array name the error went away.

"Map" apparently isn't an acceptable array name.

error code: map(day, min) = Trim(Str(Int(r / 1000)))

no error code: mapsymbol(day, min) = Trim(Str(Int(r / 1000)))

查看更多
登录 后发表回答