Solved

Debugging a DLL in the VB6 IDE

Posted on 2004-04-04
9
1,850 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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
 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

691 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