Link to home
Start Free TrialLog in
Avatar of withanat
withanat

asked on

VB Declarations for Client Access API

Can you give me the VB5 declaration for the following C prototype ?

unsigned int  cwbRC_GetParm(char     *program,
                                                       unsigned short      index,
                                                       unsigned short     *type,
                                                       unsigned long      *length,
                                                       unsigned char     **parameter);

         
ATTENTION to **parameter  
(double pointer) my favourite
                                                            Thanks            
       
Avatar of dirtdart
dirtdart

Unfortunatly, that won't be possible.  The int and char type themselves don't convert to VB, and there are no unsigned types currently supported by VB.  Not to mention that VB doesn't supply pointers, although a single pointer can be made to work.  If you'd like, I can translate it into something that will work.
Now I don't think all is lost here. VB allows for passing by reference (though if your passing a string out of VB you would pass it by value, and a string is a string in VB whether it holds one character or dozens). The short data type is compatible with the integer data type in VB (though couldn't say for sure as to the "unsigned" issue - but it still might work). I say play around with it before you throw in the towel. This is REALLY on the fly... but maybe something like this:

sub cwbRC_GetParm(byval program as string,
                   index as integer,
                   byref type as integer,
                   byref length as long,
                   byval parameter as string) as integer
end sub
oops... byval on the "index as integer" parameter
You're half right, dpms.  You can pass byref.  That's what I meant when I said "a single pointer can be made to work."  However, your declaration above will not work.  The C int type is not compatible with the Visual Basic Integer type, and the C char type is not compatible with a Visual Basic String.  If you got the above declaration to even call without crashing both programs, all you would get in return is total garbage.
Avatar of withanat

ASKER

I have no trouble with unsigned int, long or string etc. There are other declarations that use them.
My problem is with ** (double pointer). Last parm


ASKER CERTIFIED SOLUTION
Avatar of dirtdart
dirtdart

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree the double pointer is tricky and that a single pointer would have to be used. But I still hold my ground that the "short" type in C is compatible with the integer type in VB, but I did have to clarify about the "unsigned" part of the parameter.
Short does convert to Integer.  But I'm not sure what you're going to get when dealing with unsigned.  Personally, I haven't had any luck converting to types that aren't completly supported.  But if you know how to make it work, that's great.
Below is a table I copied off the MSDN. I myself have successfully passed an integer from VB to a short in C.
According to what I've gone back and read in MSDN, the unsigned
short should also work. Hope this helps..........


The following table shows the data-type equivalencies for both 16- and 32-bit Windows.
 
Visual Basic data type      
Size of variable      16-bit Windows data types      32-bit Windows data types
                  
                  int, short, WCHAR
Integer      2 bytes            WORD, HWND, HANDLE,         short, WCHAR
                                          
                                          
Long      4 bytes            long, LPSTR                int,HWND,                                                        long, HANDLE
                                                    LPSTR       

If your DLL code uses the int data type with arguments either passed in or returned to Visual Basic code, you must change those arguments to use the short data type.