03-05-2010 06:01 PM
I'm stymied in trying to create a function panel window with a parameter that is an array of strings.
I see where I can select an input parameter type of char * [] which is an array of type pointer to char that should do the trick.
I want to allow the user to specify exactly 12 strings in this array.
But, I can't see how to accomplish this using the function panel editor. I'd like to avoid having to define a function with 12 parameters, each one a string.
If it helps, I don't really intend to use the function panel as such, I am creating it only to capture the function signature so that I can create a type library for a DLL that includes this function. So maybe it's enough just to design it to use an input parameter of type char * [] even though it puts a simple numeric entry box on the panel, which couldn't really be used to enter 12 strings.
Thanks for any help on this.
Menchar
03-08-2010 04:01 PM
Hi menchar,
Independently of the function panel, you first have to to decide what the signature of the C function should be. Are you planning on using char ** (or char *[]) as the function prototype? If so, obviously you can't prevent users from passing arrays longer than 12 strings. But even if you did something like this:
typedef char *mytype[12];
void myfunc (mytype a)
{
...
}
...you still could not prevent users from passing longer arrays. If they declared the variable that they're passing in statically, as mytype, then that variable would automatically be limited to 12 elements. But the compiler does not prevent them from simply passing some random char ** to the function, in which case the buffer that it's pointing to can be of any length. The bottom line is, you'll have to enforce the length yourself inside the function.
If you end up using a typedef as the parameter, you can still use it in the function panel signature as long as you add the typedef explicitly to the function panel (Options>>Data Types). Note that you don't add the type definition, just the name of the type. That's all the function panel needs.
As far as the function panel's input control is concerned, it isn't really a numeric control, by default. You could certainly use numeric controls, for other parameter data types, but in this case you would be using a generic input control, which allows users of the function panel to enter a variable name or an expression. Realistically speaking, this is what they will be passing to the function anyway, since you can't pass an array as a literal. If you do want to have a fancier type of input control, you can define a customization handler for this parameter. This can look like a dialog with 12 string controls if you like. If you're interested in this option, you attach the handle to the function panel by right-clicking on the input control and selecting "Customize Control". (Of course, you'd have to implement the dialog in a separate DLL first...
)
Luis
03-08-2010 05:30 PM - edited 03-08-2010 05:31 PM
Thanks for the reply, Luis.
It looks to me then, that if I create a generic input control that's of type char * [] that it will go into the type library properly such that a VB6 client will be able to call the function without using an explicit declaration of the function prior to its use?
Thanks again,
Menchar
03-09-2010 01:55 PM
Ah, well, if your goal is to expose a C DLL that can be called from VB, and you want to pass arrays as parameters, then things aren't quite so simple.
VB doesn't really support C arrays. It supports safe arrays, which is a VB/COM data type. If this were not an array of strings, you could also expose iterator functions that would allow the clients to pass individual elements of the array, rather than the full array. Unfortunately, VB doesn't support C strings either, so even in that case you'd have to deal with COM data types for the string itself.
I think your best bet is to create an ActiveX server in CVI (Tools>>Create ActiveX Server) which will handle the required type conversions between C and COM. If you haven't done this before, there are a few exampls in samples\activex\servers that you can look at.
Luis
03-09-2010 02:01 PM
Luis -
Thanks for the response.
We've successfully passed strings and singly dimensioned arrays of ints in both directions VB6 <-> CVI DLL, using a type library.
What's a little bit different here is an array of strings, and it could be that won't work.
We'll just have to see what happens.
Thanks again,
Menchar