Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I convert a dll to a executable *.exe? 1

Status
Not open for further replies.

Kruzer

Programmer
Jun 16, 2000
117
US
It's been a while since I've used VB...

I have some VB code from a DLL that I would like to convert to an executable.

Do I create a main module in the source that references the DLL functions or create a new VB exe? How do I call the functions with in the DLL code from the VB exe code?

Thanks!

Dano
dan_kryzer@hotmail.com
What's your major malfunction
 
Create a new .exe project. Copy over the source files from your .dll project. In the main method, insert code to call your copied code.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
When I call the hello.exe say from a command line and pass in parameters, will Main() be called? Do I use a module or a class module? Inside the module code do I type in something like this:

Public Sub Main()

Dim args As String
args = GetCommandLineArgs()
' this should work right?
End Sub

With this module I would like to gather up the parameters when executing the file. I also found some code on MS's site describing the use of the command() function. The code below can be placed in the module so that when I type in "\\hello.exe hi" the argument returned will be "hi".

Public Function GetCommandLineArgs() As String()
' Declare variables.
Dim separators As String
Dim commands As String
Dim args() As String
separators = " "
commands = Microsoft.VisualBasic.Command()
args() = commands.Split(separators.ToCharArray)
'Return args

End Function





Dano
dan_kryzer@hotmail.com
What's your major malfunction
 
The code sample you have won't work because it is from VB.NET, not VB6. In VB6 you use the Command$ reserved word to access the command-line arguments.

Otherwise, you're correct - you create a public sub Main in a .bas module.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
pre-qualifier statement - I'm a Java developer now; started/learned VB in the beginning, now back at VB today. So I'm brushing up on my skills :) Need to make some code work with Active Directory and the existing code is in VB. So I need to execute some functions in VB that output strings that I need to use in some Java, fun...Thanks for all your help!

ok, I'm getting a "Invalid qualifier" on the bolded variable, how come?

Public Function GetCommandLineArgs() As String()
' Declare variables.
Dim separators As String
Dim commands As String
Dim args() As String
separators = ","
commands = Command()
args() = commands.Split(separators)
GetCommandLineArgs = args

End Function




Dano
dan_kryzer@hotmail.com
What's your major malfunction
 
Also, what is the equivalent in VB to Java's System.out.println() so I can test my args that are passed in?

Dano
dan_kryzer@hotmail.com
What's your major malfunction
 
Sorry, I'm not an expert on the Split command (I don't have the VB6 online help installed anymore -- had to remove it for disk space reasons).

But to see what's going on, there's two main techniques:
1. Use the Debug.Print statement to see stuff in the IDE command window. You can leave these in -- when you build the compiler ignores them.

2. Right-click on the variable you want to inspect, and select "add to watch" from the context menu.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
chiph,

I've been using the debug.print, works great! I would really like to know how to output strings/data to the command window. I would like to display errors, if any :), when the exe is called.

Thanks for all your help.

Dano
dan_kryzer@hotmail.com
What's your major malfunction
 
There's no console, like there is in Java. If your program has errors your user will typically get a messagebox that just gives them the description (there's no stack trace in VB6, either).

Error handling in VB6 is tedious at best. What you need to do in include an On Error Goto line in every method and function (by now you're probably saying "yuck", and you're right).
Code:
Public Function MyMethod(ByRef A As Long, ByVal B As String) As Boolean

  Dim oAdoConn As Connection
  Dim sErrMsg As String
  Dim lErrNum As Long

  On Error Goto MyMethod_ErrHandler
  MyMethod = False ' Assume failure

  Set oAdoConn = New Connection

  ' Do stuff with your connection

  MyMethod = True ' success!
  Goto MyMethod_Cleanup

MyMethod_ErrHandler:
  sErrMsg = Err.Description  ' save off err values in case
  lErrNum = Err.Number       ' something in errhandler chokes

  ' Log error somehow

  ' Fall through into cleanup

MyMethod_Cleanup:
  If Not oAdoConn Is Nothing Then
    If oAdoConn.State = adStateOpen Then
      oAdoConn.Close
    End If
    Set oAdoConn = Nothing
  End If

End Function
Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top