Solved

Debugging a DLL in the VB6 IDE

Posted on 2004-04-04
9
1,832 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
  • 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
 
LVL 5

Accepted Solution

by:
KarcOrigin earned 500 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now