Solved

VB Declarations for Client Access API

Posted on 1998-02-15
9
237 Views
Last Modified: 2012-06-27
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            
       
0
Comment
Question by:withanat
  • 4
  • 4
9 Comments
 
LVL 5

Expert Comment

by:dirtdart
ID: 1457210
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.
0
 

Expert Comment

by:dpms
ID: 1457211
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
0
 

Expert Comment

by:dpms
ID: 1457212
oops... byval on the "index as integer" parameter
0
 
LVL 5

Expert Comment

by:dirtdart
ID: 1457213
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.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:withanat
ID: 1457214
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


0
 
LVL 5

Accepted Solution

by:
dirtdart earned 50 total points
ID: 1457215
The only way to get a double pointer from VB would be to change the C declaration to accept a single pointer.  Then pass the parameter from VB ByRef.  Once you get it into the dll, you will have to create a pointer from that pointer and use that as your parameter.
0
 

Expert Comment

by:dpms
ID: 1457216
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.
0
 
LVL 5

Expert Comment

by:dirtdart
ID: 1457217
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.
0
 

Expert Comment

by:dpms
ID: 1457218
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.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now