views:

59

answers:

2

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  A: 

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
MarkJ
@MarkJ, thank you for your post. i have tried both of them before, but just to make sure, i have tried them again after your post and the first suggestiong produced an "invalid procedure call" and the second declaration method caused a "type mismatch", both on the InvokeAction line. i see that it really wants a properly dimensioned array, but its just not returning the results in the xouts array, or even throwing an exception... what do you think?
Erx_VB.NExT.Coder
@Erx_VB It's beyond me. Ideally I think we need a COM expert to look at this, I guess none of them have noticed the question. I think VB6 doesn't support all the possible variations of a COM SAFEARRAY, that might be the problem. You could look at Matt Curland's book *Advanced Visual Basic 6 Power Techniques*. It is [free online](http://www.scribd.com/doc/35223728/Advanced-Visual-Basic-6-Power-Techniques-for-Everyday-Programs-9780201707120-24922) and has some good advanced discussion of SafeArrays. Alternatively you could just create your own wrapper in VB.Net/C# and make it COM visible...
MarkJ
Thank you for your information, do you think this could be solved by customizing a .tlb file and referencing that instead or do you think it's much more deeply seeded than that. As currently I am using a .tlb to use this dll in vb6 to remove unsigned long and make it a normal long for vb to understand.
Erx_VB.NExT.Coder
@Erx_VB I really don't know whether you could solve it by customizing a .tlb file. I don't know exactly what the problem is.
MarkJ
@Erx_VB I just noticed you've essentially asked this question again with a more general title. Usually this is frowned on but in this case I think it's a cunning plan! I've upvoted your [second question](http://stackoverflow.com/questions/4035599/how-do-i-pass-an-array-by-reference-in-vb6-to-a-c-c-dll-subroutine), let's hope someone knowledgeable stops by and answers it!
MarkJ
@MarkJ, thanks for your understanding, but after you gave me some leads, i was able to narrow down what I was looking for and asked a new question based on your leads/ideas, it contributes to the same problem but is a new question which follows a different resolution path/pattern and is essentially a different question (i hope lol). + upvoted :)
Erx_VB.NExT.Coder
A: 

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.

Bob Riemersma
@Bob, is there any reason that you can think of why it would not work for a particular computer? because i see code samples (in vbscript and vb6) where it does work, and i'm doing the same thing, yet it doesn't. +i'm not an amateur programmer, i know what i'm doing, yet it completely escapes me why its being picky for me. tried new project in vb6, not working, i will try another computer though, if you are interested i will report back on my findings from another computer.
Erx_VB.NExT.Coder
The only thing that comes to mind is that this isn't supported until XP SP2 as far as I can recall. I've tested logic like that above on XP SP3; Vista Gold, SP1, and SP2; and Windows 7. The Windows machine must have the UPnP infrastructure installed, the software firewall must allow the traffic through, and the NAT device must have UPnP enabled. There is incomplete Type info in the XP version of UPnP.dll but you can still get this subset of UPnP functionality to work using the VBScript callbacks. I'm not sure why it doesn't work for you.
Bob Riemersma
There is a simple working example here that might be worth looking at: http://www.vbforums.com/showthread.php?t=592823
Bob Riemersma