开发者

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

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 argu开发者_如何学JAVAment 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.


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜