APIs, .dlls, and controls

I am new to the VB language (and OO languages in general), but not new to programming.  I am trying to figure out how to access .dlls, controls, and the such.  I have seen (using the APIViewer and similar) some of the items I am looking for, but I do not understand how I reference them.  For example, I included the declare statement for the GetComputerName function, then tried to use it - but received the FormName when I referenced the string parameter.  This is only one example.  I am trying to find out how to declare (how, where, etc) so I can put them in programs, but I also need to know how to reference them to get the results.  For this portion, I kind of need a "crash course" in the structure of these statements (declaring, calling, getting the results) - I guess.  I understand they are mostly returning Long values, but I think the string parameters (etc.) are the true results - unlike most functions I have ever defined where the function name is the result.

I am also curious about controls.  My understanding is that there are several control files out there that might help (but I thought .ocx files held controls and someone mentioned a scrrun.dll file which was suppose to contain some controls to help) - can someone clear this up a little.  I would like to know what controls are in a control file (so I know whether I need it or not), how to import it and then I assume I just reference its properties (which should be visible once the control is on the form).  Again, in the case of controls, I need a "how to" on controls not included on the standard toolbar (those I have figured out how to use) - I am trying to get to the REST of the available controls so I can use them.

I know this is kind of a long questions, but it should be fairly easy.  If you have an answer, please feel free to be detailed.  I have a lot of programming experience ranging from COBOL to True Basic to Pascal (and several languages in between).  I understand the programming concepts, but not the VB (yet).  I have looked in a few books to try and gain information about APIs and controls, but they really don't help (useful book suggestions would be appreciated also).  I would really appreciate if someone can give me a definitive "how to" for APIs and controls.  If you have some time to give a detailed answer, please help out.  Thanks.
Who is Participating?
BeedleGuisConnect With a Mentor Commented:
ok.. here it goes, starting with api's.  What you have already stated is pretty much correct, most have long return values that represent the success or failure.  And most of the time the real value you are looking for is the string, or structure you passed to it.  ex.

Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Sub Form_Load()
Dim strCompName As String * 255
GetComputerName strCompName, 254
MsgBox strCompName
End Sub

The only good way of telling exactly how the call works is to buy a good reference, such as the Visual Basic programmers guide to the Win32 API, written by Dan Appleman.  Comes with all the info and samples on a cd as well.  You can search MSDN KB for the API calls, but that's a real pain.

Control's: You can reference the none-standard controls by right clicking the tool box and then on components(also under the project menu).  The list is all the ocx's VB found on your hard drive.  Selecting one or more item's out of the list will add more options to your toolbox, which you can use the same as the standard control's.  Most control's(or components) have help files associated with them, allowing you to, in your code, type the name of the control, then .whateverevent/method you want to know about, then press F1 while your cursor is in the name of the event/method.

Hope this clears up some things for you.  If you have more questions, or would like know some specifics on api calls or controls, just let me know which one's your interested in and I'll be glad to post more answer's for you.

I'd suggest a book like "Visual Basic Programmer's guide to the Win32 API", published by ZD press. The API viewer really doesn't tell you anything about the sub or function.  You really need a reference book to find out data structures, passing & returning variables, etc.  

If you have some specific questions, I'll look them up for you. Try going to ZD presses website, you may be able to download some code from the books.
electrick: is that the Dan Appleman book?  if so, I agree, it's a very good reference.
To elaborate a little more on both subjects:
Api calls can be real delicate,(ie. in the example the string you pass must be a specific size, I used 255 because most computer names will not exceed that, then had to tell the function how big the string was, minus the null terminator). You can use a long variable ie: lngRetVal = GetComputerName(strCompName,254), to test if the function was succesful.  But, some return zero on failure, some return zero on success, which is why you need a good reference.  Here's what the Appleman book I mentioned earlier says about GetComputerName:

VB Declaration

Declare Function GetComputerName& Lib "kernel32" Alias "GetComputerNameA" _
(ByVal lpBuffer As String, nSize As Long)


Retrieves the name of this computer.

Use with VB

No problem.

Parameter      Type/Description
lpBuffer      String—String buffer to load with the computer name.
nSize      Long—The length of the buffer. This variable is loaded with the actual length of the computer name on return.
Return Value

Long—True (nonzero) on success, zero on error. Sets GetLastError.


Windows 95, Windows NT


Note that the nSize parameter is not passed by value. See Api32.txt for the value of the MAX_COMPUTER_NAME constant.


Dim s$
Dim dl&
Dim sz&
dl& = GetComputerName(s$, sz)

All of the material presented here is copyrighted by either Desaware or Macmillan. No part of this material may be used or reproduced in any fashion (except in brief quotations used in critical articles and reviews) without prior consent.
MAX_COMPUTERNAME_LENGTH is a const available from the api viewer by the way.  

most of the control's in your list are most likely packaged with VB(or at least MS), thus are included in the regular VB help files.  Some of the ocx's on your harddrive may not show up in the list, in which case you can use the browse button to add them manualy.  Some ocx's have more than one control, ie: MSCOMCTL.OCX, the MS Windows Common Controls.
I don't know who told you that a dll file hold's control's, but I believe they are mistaken.  ActiveX dll's may be referenced by your app(Project->References), but that is a different matter all together.

msonsteiAuthor Commented:
Thank you very much.  I am still trying to get the hang of it - any other pointers would be appreciated.  I have the WIN32 API book everyone was mentioning (borrowed from a friend who is also trying to figure some of this out).  Any suggestions on good books to LEARN VB, more geared toward a programmer with programming experience, but not much OO experience?

Thanks again for the help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.