Solved

Debugging a DLL in the VB6 IDE

Posted on 2004-04-04
9
1,835 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

911 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

26 Experts available now in Live!

Get 1:1 Help Now