We help IT Professionals succeed at work.

Passing array from eVB into eVC DLL

SuperSy
SuperSy asked
on
I have a DLL written in eVC3.0, which works well with other eVC3.0 applications.  However, I now need to make the DLL work with eVB3.0 applications, with minimum modifications on DLL code.  
The DLL receives a pointer to a BYTE array and fills the first 10 to 30 bytes of the array before returning.  However, I don't know how to pass a "byte array" from eVB to DLL.  I tried passing a string, but didn't work well (because of UNICODE maybe?)  I tried to pass a Variant, but I don't know how to process it in eVC.  

So, how can I do this?  How can I use eVC DLL to return several bytes of information to an eVB program?  Essentially, show me how I can use foo() below from eVB app (not regular VB, where you can pass MyByteArray(0) as ByRef parameter and get things done) so that it can change an array in the eVB app.  

void foo(char* pBuffer)
{
    for (int i = 0; i < 20; i++)
        pBuffer[i] = 100;
}

I hope I don't have to go through the ActiveX deal, but for now, anything that works will be appreciated.  
Comment
Watch Question

Commented:
HOWTO: Pass Arrays Between Visual Basic and C
http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q207931

HOWTO: Return Array to VB from VC++ DLL or OLE Server
http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q177218

How To Pass Binary Data Between an ActiveX Control and VB
http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q154172

Author

Commented:
Thanks chensu.  

I have been to the three webpages and have been trying to find a way to implement this thing one way or another but have not succeeded in doing so yet.  

The first link does not really show me how to deal with SAFEARRAY inside C code and besides, it seems that I cannot declare an array parameter in eVB.  

The second one shows you how to return (kinda) but doesn't tell me how to receive an array from eVB, which you want to package with goodies and send back home to eVB.  

The third seem the most probable and closest to my goal, but one problem I have is that when I pass an "array" from eVB, somehow when I receive it in eVC Buffer.vt is 12, not "VT_ARRAY | VT_UI1" = 0x2011 or something larger than 12.  The declare statement in eVB looks like:

Declare Function FxnName Lib "LibName" (ByRef ByteArrayVar, ByRef SomeLongVar As Long) As Byte
I tried "ByRef ByteArrayVar as Byte" but that didn't work either...

Commented:
12 is VT_VARIANT, meaning that it is a VARIANT itself. Check that VARIANT to see if it is a SAFEARRAY.

Author

Commented:
Yes ... since I passed the "array" through "ByRef ByteArrayVar" (note: no explicit type info = default in eVB = Variant, I think), it reaches the other side as a Variant.  

Anyway, how can I "Check that VARIANT to see if it is a SAFEARRAY"?  After all, it thinks it is a Variant, regardless of what data it holds.  

When I ignored that and checked its Dimension, it was not 1 but 216 --- probably garbage.  I fear that I must do something before I pass it, no?

Author

Commented:
Yes ... since I passed the "array" through "ByRef ByteArrayVar" (note: no explicit type info = default in eVB = Variant, I think), it reaches the other side as a Variant.  

Anyway, how can I "Check that VARIANT to see if it is a SAFEARRAY"?  After all, it thinks it is a Variant, regardless of what data it holds.  

When I ignored that and checked its Dimension, it was not 1 but 216 --- probably garbage.  I fear that I must do something before I pass it, no?

Author

Commented:
Oops... did the refresh.  

Commented:
Buffer.pvarVal->vt

Author

Commented:
Sorry for being away, got a different project and had to stick to it.  

<< Buffer.pvarVal->vt >>

What about it?  This should be the "VT_ARRAY | <anything>" value?  

Commented:
I think so.
1. can u pass it by ref as variant.
2. define a variant variable in the fucntion and put this value in that.
3. set the variant variable to string type and i think u have got the string.

Author

Commented:
Thank you all for your support.  

However, I am really getting nowhere with this thing, and I now wish to close this thread.  Who should I give the points to...?  Unless no one wants to give me a good final answer, I believe chensu will get the point, although probably not full grade.  

If anybody wants to give me a good final answer, please make it within the next few days.  Thanks.  

Author

Commented:
I was going to give out a C:Average instead of B:Good, since (a) the problem was not solved, first of all, and (b) the follow up was not very deep-digging (if you know what I mean).  I appreciate the help from chensu a lot --- but it would have been unsatisfactory if I received the same response from a paid customer service.  

In my general grading, A:Excellent is what exceeds my expectation from a paid customer service, B:Good will be what meets my expectation from a paid customer service, and C:Average will be anything below.  Since this is NOT a paid customer service, however, I decide to give out B this time.  

Thank you all for your time and effort.  I wish I was able to utilize the help a little more.  

Explore More ContentExplore courses, solutions, and other research materials related to this topic.