?
Solved

Debugging a DLL in the VB6 IDE

Posted on 2004-04-04
9
Medium Priority
?
1,855 Views
Last Modified: 2007-12-19
Hi,

I'm creating a VBA Library DLL using VB6, and need help in using the VB6 IDE to debug the code.

I have created a new project -- ActiveX DLL -- and entered the code into a class module.

I'm having two problems:

1.  I have one class module that uses the WinAPI :

Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
    "GetOpenFileNameA" (pOpenFileName As OPENFILENAME) As Boolean

and I'm getting the following error:

========================================
Constants, fixed-length strings, arrays, user-defined types, and Declare statements not allowed as Public members of an object module
========================================

I  have 3 public Declare statements, and about 10 Public Const statements.  This code worked fine in the Excel VBA environment.

How do I set it up in the VB DLL project?


2.  How do I debug the DLL?

I created a test Sub to test my code, but when I press F5 the IDE acts as if it is running, but the code doesn't execute in the Sub.


My environment:
VB6 SP5
Win 2000 Pro SP3

TIA.
0
Comment
Question by:apollois
[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
  • 3
  • 2
  • +1
9 Comments
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 10754267
Hi
>and I'm getting the following error:
You cannot diclare the win API in the class modules. Diclare it in the module.

To debug your Dll add a new project (Standard exe) and initiate your dll in this project. Do not forget to make it as a startup project. Press F8 to debug it.

Thx

Karc

0
 
LVL 10

Author Comment

by:apollois
ID: 10754300
Thanks for the reply Karc.

I'm new to this, so you need to give me more details please.

How do I:
1.  Initiate the DLL in the new project?
2.  Make it as a startup project?

0
 
LVL 10

Author Comment

by:apollois
ID: 10754330
Now that I have added a Standard EXE Project, and created a Project Group,  how will this affect the DLL?

When I make the DLL, does it include the EXE project?

Also, according to MS MSDN, when I create a VBA Lib DLL, I have to put all the code in  class modules.  Is it going to be a problem with the WinAPI delcare staements being in a normal module?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Accepted Solution

by:
KarcOrigin earned 2000 total points
ID: 10754357
Hi,



>Make it as a startup project?

1. Open your Dll project in VB.
2. After opening it goto File menu and click on "Add project" and select the standard EXE project.
3. Now select this project on the Project plane (Generally right hand side, which shows all the project files) and right click on it.
4. You will get a popup menu. Select "Set as Startup".
Now if you press F8 the standard EXE form will appear on the screen. I think this is the answer of your second question

>Initiate the DLL in the new project?
1. Now Open the form which you have by default in your EXE project.
2. Goto Project menu and click on references
3. Select your Dll reference from the list
4. Now initiate your Dll project in the Standard EXE project -
Eg: Dim obj as new YourDll
Call the method as
obj.yourMethod()
5. Press F8 or put the break point in your dll project and press F5

I hope it will help you
Thx

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 10754381
There is not need for a separate module, just change this:
Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
    "GetOpenFileNameA" (pOpenFileName As OPENFILENAME) As Boolean

To:
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
    "GetOpenFileNameA" (pOpenFileName As OPENFILENAME) As Boolean
0
 
LVL 10

Author Comment

by:apollois
ID: 10754401
acperkins,

Thanks.

What about the Const statements?

Is it better to put the Declare Function in a normal module or a class module?


Karc,

Thanks for the details -- very helpful.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 10754430
>>What about the Const statements?
Is it better to put the Declare Function in a normal module or a class module?<<
It really depends on the scope.  If they are only used in one module than IMHO there is no point in declaring them as Public in a module.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 10756890
>>2.  How do I debug the DLL?

In order to debug your dll, you don't have to put all into 1 group. The main idea is set your dll to binary compability.

From Project menu->properites->component tab->binary compatiblility

Make sure you run your dll first before run your app from IDE
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 10788903
<ThinkingOutAloud>
   Sometimes I wonder why I even bother.
</ThinkingOutAloud>
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…
Suggested Courses

777 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