views:

66

answers:

1

I need to pass an empty Array of Variants to a DLL written in C (and available on all Windows versions), and the C code (which I have no control over and cannot edit) will populate the Empty Array of Variants with its some return values.

Bascially, when I try this - the ByRef Array is always empty when it should contain the results of the function/sub call (if I do the exact same thing in .NET, it works).

I'm thinking I need to do a custom declaration so VB knows how to call the C function, or?

Here is how the C sub/function is declared. Given this, what do I need to do in order to ensure C is able to use my Empty Array properly and I in tern get my results back?

HRESULT InvokeAction(
  [in]       BSTR bstrActionName,
  [in]       VARIANT varInActionArgs,
  [in, out]  VARIANT *pvarOutActionArgs,
  [in, out]  VARIANT *pvarRetVal
);

More information about this function: http://msdn.microsoft.com/en-us/library/aa382237(VS.85).aspx

Thanks

+3  A: 

From http://msdn.microsoft.com/en-us/library/aa381230(VS.85).aspx:

Dim returnVal
Dim outArgs(1)
Dim args(1)
args(0) = 3
returnVal = service.InvokeAction("GetTrackInfo", args, outArgs)
'return Val now contains the track length
'and outArgs(0) contains the track title
Dim emptyArgs(0)
returnVal = service.InvokeAction("Play", emptyArgs, emptyArgs)
'returnVal indicates if the action was successful

Just how you get and instance of service is not clear from this example though.

Patrick McDonald
@patrick, thank you for your post, the issue is, when i pass the argument as per the specs, the outArgs are always empty (however, the action does execute, just the outArgs aren't received). so i figured this was an interop issue between C and VB6, i've tried passing the arguments in several different ways, do you think i need to do a "Private Sub Declare InvokeAction ... Lib "upnp.dll" ... " or something to that effect to make it work? i already have the service from a for each loop, and everything else in upnp.dll (services/devices etc) all work correctly, just getting the outArgs don't...
Erx_VB.NExT.Coder
+ no exceptions are raised either, outArgs is unchanged on response.
Erx_VB.NExT.Coder
just to add, even if i do use retVal and seek a return variable, that is also empty, just like outArgs, every single time. i've tried this on several invokable actions now. i've even tried starting a new/blank project, re-addings the references, etc... to no avail. also, it works perfectly when i do it in vb.net or c#, as per the specs, not an issue at all.
Erx_VB.NExT.Coder
I'm not sure you could use Private Declare... as it seems to be a COM function, it might be worth trying to pass the outArgs ByRef, eg service.InvokeAction("GetTrackInfo", args, ByRef outArgs)
Patrick McDonald
when i try: service.InvokeAction("GetTrackInfo", args, ByRef outArgs) in VB6 i get a compile time error, is the ByRef keyword usable when calling the function? i've always used it where i'm declaring the function, but never used it when calling, if you could use it during call and override the declared functions behaviour that would be cool. however, i gave it a try both as "ByRef outArgs" and as "outArgs ByRef" and neither worked, the line just went Red and i got the typical VB6 error dialog box :)
Erx_VB.NExT.Coder
Oops it's been a long time since I wrote Any VB6 so am starting to make up new syntax sorry :)
Patrick McDonald