Results 1 to 12 of 12

Thread: [RESOLVED] API's

  1. #1

    Thread Starter
    Fanatic Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    790

    Resolved [RESOLVED] API's

    Whenever I used an API in the past, someone has told me I needed one. Sometimes I got the code, sometimes, I figured out how to use the API, after it was given to me.

    The question is, how would I know before asking when I would an API?

    Thanks

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: API's

    Well you need to use APIs when you want to do something that the language you are using does not directly support or is to slow. There are many cases where you can use an API but you could also use native VB functions to do the task, There are other cases where you just can't do it without using an API be it the Windows API or a 3rd party API built specifically for interacting with the 3rd party software.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: API's

    I assume when you say "API" you are talking about calling into non-ActiveX libraries, because even using a VB TextBox you make use of its API.

    When you need something that VB's intrinsic statements, functions, controls, and no ActiveX library provides you may have to bite the bullet and make low level API calls. Sometimes even when there is a friendly wrapper library, you might need expanded access to the underlying lower-level library. So you use the low level API.

    Or the issue might be performance, flexibility, etc.

    Often there are COM libraries that lack a complete set of features to be ActiveX, such as a type library. Or an ActiveX library might contain class members that require an unsupported data type. You might have to call helper APIs to get access to those objects if you can't or don't want to write an appropriate type library.

    Or you might be too cheap to acquire a license for a VB-friendly ActiveX library to do the job.


    But all of this is pretty obvious, isn't it? Or are you asking about "web service" APIs?

  4. #4

    Thread Starter
    Fanatic Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    790

    Re: API's

    I am not looking at web service APIs. I am not looking for any specific API. I am trying to understand how I determine if I need an API, and if so, how I can find the appropriate one.

  5. #5
    Hyperactive Member
    Join Date
    Jul 2020
    Posts
    370

    Re: API's

    Quote Originally Posted by AccessShell View Post
    I am trying to understand how I determine if I need an API, and if so, how I can find the appropriate one.
    A simple example: if you want to use MSComm to work with RS-232 over a three-wire line, you will face the problem of waiting for a client's response. Using Win32 API functions will solve this problem.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: API's

    Huh?

    The MSComm control works fine for that. You just have to Use The Events, Luke!

  7. #7
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,055

    Re: API's

    its basically all trial and error. You run into a problem, you search the web for answers. Most general things have been solved with examples by now. If you cant find a VB specific solution, then start searching how other languages have done it and that will show you which api to use. Dont worry about it to much. The api will reveal themselves to you as you need them. There are to many and they are to nuanced to just sit down and study to know off hand. Even once you know them, you will just keep an archive of code to do task X when you need it and not pay attention to the inner details after that.

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: API's

    Quote Originally Posted by Argus19 View Post
    A simple example: if you want to use MSComm to work with RS-232 over a three-wire line, you will face the problem of waiting for a client's response. Using Win32 API functions will solve this problem.
    As stated above the MSComm control works fine if you use it right. I've did lots of serial comm stuff over the years and the only thing I needed to use something else on was when I needed to support various protocols such as x,y and z modem for file transfers. In those cases I use a different OCX that makes it easy to do those things. I have never found a need to use any low level API calls for serial comm apps.

  9. #9

    Thread Starter
    Fanatic Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    790

    Re: API's

    This was a hypothetical question. I don't need a specific API right now. I just wanted to find a better way of determining if I needed one.

  10. #10
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: API's

    Quote Originally Posted by dilettante View Post
    Huh?

    The MSComm control works fine for that. You just have to Use The Events, Luke!
    I agree that MSComm control is one of the harder controls to emulate as it spawns a seprate worker thread to intercept input and raise events on the main thread which is very hard to do with win32 API and plain VB6.

    With API calls one might try the better version of overlapped I/O on the serial ports which comes with another bag of problems with buggy drivers on these ubiquitous cheap USB-to-COM dongles. Then there is the Remote Desktop client which can "virtualize" local serial ports and bring one more bag of incompatibilities.

    cheers,
    </wqw>

  11. #11
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: API's

    You use API when you need to do something that the VB6 itself don't have buit-in support for.
    How to know if you need an API? First you would need to know VB6 well, what it can do without resorting to APIs.

    So, first you have to have a need, a need to do somehting. Then: can this be done with pure Vb6? If yes, then no API is needed. If no, then try to find how it can be done with APIs. How? Read a book, for example, Dan Applemans's Visual Basic Programmer's Guide to the Win32 Api or search the forum for how to do "your current need" for some solution that someone already posted.
    You can also browse Allapi for studying different APIs, what they can do and how to use them, with examples.

  12. #12
    Hyperactive Member
    Join Date
    Jul 2020
    Posts
    370

    Re: API's

    Quote Originally Posted by wqweto View Post
    With API calls one might try the better version of overlapped I/O on the serial ports which comes with another bag of problems with buggy drivers on these ubiquitous cheap USB-to-COM dongles.
    USB-to-RS-485 ? Connection timeout problems? Have to use a timer?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width