Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

APIs, .dlls, and controls

Posted on 1999-07-23
5
Medium Priority
?
323 Views
Last Modified: 2010-04-30
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.
0
Comment
Question by:msonstei
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 

Expert Comment

by:electrick
ID: 1527033
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.
0
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1527034
electrick: is that the Dan Appleman book?  if so, I agree, it's a very good reference.
0
 
LVL 2

Accepted Solution

by:
BeedleGuis earned 400 total points
ID: 1527035
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.

Regards
0
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1527036
To elaborate a little more on both subjects:
API's:
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:
****************************8
GetComputerName

VB Declaration

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

Description

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.

Platform

Windows 95, Windows NT

Comments

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

Example

Dim s$
s$ = String$(MAX_COMPUTERNAME_LENGTH+1, Ø)
Dim dl&
Dim sz&
sz& = MAX_COMPUTERNAME_LENGTH+1
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.  

Controls:
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.

0
 

Author Comment

by:msonstei
ID: 1527037
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

704 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