How do I pass an Array (By Reference, in VB6) to a C\C++ *.dll subroutine?

烂漫一生 提交于 2019-12-10 19:50:41

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/4035599/how-do-i-pass-an-array-by-reference-in-vb6-to-a-c-c-dll-subroutine

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