Getting IP Address using UPnP InvokeAction not returning anything, help?

流过昼夜 提交于 2019-12-20 05:50:46

问题


Basically, when i use vb.net or c#.net to do this, it works perfectly, but when i use vb6, it doesn't work, in my for loop where the relevant service in the relevant device is captured, here is the code that returns no result...

      ' serv is properly declared and instantiated by the for loop.
      Dim xins(0)
      Dim xouts(0)

      MsgBox ("Starting..." & serv.ServiceTypeIdentifier & vbCrLf & serv.id & vbCrLf & serv.LastTransportStatus) ' all this shows correctly.

      serv.InvokeAction "GetExternalIPAddress", xins, xouts

      MsgBox (xouts(0)) ' this should print the ExternalIP, but prints an empty string.

Basically, xouts(0) should contain the IP address, but it doesn't (is an empty string instead, no error or exception is raised).

all the other upnp.dll related stuff works, ie: retreiving devices list and getting the services in each device etc... no probs, just InvokeAction doesn't seem to be working on the service i am trying to use it on (which is of type "WANIPConnection:1" in the device of type "WANConnectionDevice:1")...

here is the interface details for reference: http://msdn.microsoft.com/en-us/library/aa382237(VS.85).aspx

i tried to get the return value from InvokeAction (which is shown as the last argument in the interface declaration at the link i just provided, thats mainly for C/C++ users, in .NET and VB6, the last argument is the return value) and even couldn't get that to work, can provide code on how i did that if needed, but i'm happy to just run it straight out without looking for the return value, as that is just defined by this list here: http://msdn.microsoft.com/en-us/library/aa381160(v=VS.85).aspx and the actual data i'm looking for is supposed to be in xouts array, specifically xouts(0), does anyone have any leads on what this could be?

firewall issue maybe? i'm running in elevated mode and upnp is enabled on device (router).

Update: vie noticed that the action is actually being run/executed but the out argument array (or ByRef argument in VB) is not being updated with the data, which suggests markj comments about interop issues being a good lead.


回答1:


This is pretty straightforward. Those parameters are meant to be Variants that contain an array with one element, index = 0.

Dim xins As Variant, xouts As Variant
:
:
ReDim xins(0), xouts(0)
serv.InvokeAction "GetExternalIPAddress", xins, xouts
MsgBox xouts(0)

I've been using this for some time with no problems.




回答2:


The documentation you linked says xins and xouts should be an empty array on calling: you could try changing the definition to

Dim xins() As Variant
Dim xouts() As Variant

If that doesn't work you could even try

Dim xins As Variant
Dim xouts As Variant


来源:https://stackoverflow.com/questions/4022939/getting-ip-address-using-upnp-invokeaction-not-returning-anything-help

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!