Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

How to use Visual Studio to debug a C/C++ dynamic library called by a PowerBuilder 2019 application – PB Docs 2022 – PowerBuilder Library

How to use Visual Studio to debug a C/C++ dynamic library called by a PowerBuilder 2019 application – PB Docs 2022

How to use Visual Studio to debug a C/C++ dynamic library called
by a PowerBuilder 2019 application

Background

This article aims to give an instruction on how to use Visual
Studio to debug a C/C++ dynamic library that is called by a PowerBuilder
2019 application.

Here we will show you:

  • How to create a C/C++ dynamic library.

  • How to call this DLL in PowerBuilder application.

  • How to debug the DLL called by the PowerBuilder
    application.

Description

Let’s take Visual Studio 2017 as an example to create a C/C++
dynamic library NewDLL.dll, which contains two functions:

  • Add: Accepts two int parameters.

  • ComputerName: Accepts a string parameter.

In addition, we will create a simple application with PowerBuilder
2019 to call this NewDLL.dll.

How to create a simple C/C++ dynamic
library

1. Start Visual Studio 2017. Select File -> New -> Project
to create a NewDLL project

    Select Dynamic-Link Library (DLL) from the listed
items.

tr_083.jpeg

2. Open the pre-compiled header file pch.h.

    Add export interface code as shown below:

tr_084.png

3. Modify the source file pch.cpp corresponding to the
pre-compiled header file.

    Add export interface implementation code as shown
below:

tr_085.png

4. Add a def file to declare the export interface function.

    Right-click the current NewDLL project and select Add ->
New Item from the pop-up menu.

    Select Module-Definition File (.def) from the listed
items.

tr_086.png

tr_087.png

5. Modify this def file and add the export interface
functions.

tr_088.png

Create a PowerBuilder application to call
this C/C++ dynamic library

1. Create a new PB application. Add a window and declare local
external functions in it as shown below:

tr_089.png

2. Add an Add button and a ComputerName button on the current
window to call the functions from the DLL.

tr_090.png

tr_091.png

At this moment, you can deploy the application into an exe file or
directly run the application in PowerBuilder IDE to check the execution
of the current functions.

Use Visual Studio to debug the DLL called by the PowerBuilder
application

In most circumstances, when we compile a DLL for PowerBuilder
applications, the most troubling part is to debug the functions from the
DLL.

So going forward, we will show you how to use the debug
function.

Note: In most cases, users cannot use Visual Studio to debug the
DLL called by the PowerBuilder application because the corresponding pdb
file is not copied to the same PowerBuilder application directory after
compiling the DLL.

For example, when debugging the NewDLL.dll called by PowerBuilder
application, the corresponding NewDLL.pdb file should be copied to the
same PowerBuilder application directory. Please also note that such
NewDLL.pdb file is not necessary when deployed to the end users.

tr_092.png

Debug by Attach to Process

1. Open the current application with PowerBuilder IDE and run the
application to see the application window.

tr_093.png

2. Open the current NewDLL project with Visual Studio 2017 and set
the corresponding breakpoints.

    As shown in the screenshot below, set breakpoints on the 9th
and the 14th lines of the code in the pch.cpp file.

tr_094.png

3. In Visual Studio 2017, select menu Debug -> Attach to
Process….

tr_095.png

4. In the Attach to Process window, attach the current
PowerBuilder 2019 process.

    Then in the process list, select PB190.exe, click the Attach
button to start the monitoring. 

tr_096.png

5. Click the Add or ComputerName button in the PowerBuilder
application to call the functions Add or ComputerName in
NewDLL.dll.

When you click the Add or ComputerName button in the PowerBuilder
application, the PowerBuilder application will call the Add or
ComputerName function in NewDLL.dll and Visual Studio 2017 will
automatically capture and call the current function and the execution of
code will pause at the breakpoint. At this moment, you can do
independent debugging in Visual Studio 2017.

tr_097.png

tr_098.png

Debug using the command

1. First we need to deploy the current application in PowerBuilder
to generate the exe program.

tr_099.png

2. In Visual Studio 2017, right-click on the current project and
select Properties.

tr_100.png

3. In the pop-up Properties window, add the path of the current
exe file compiled by PowerBuilder application to the Command
property.

    Click the OK button to confirm the current settings.

tr_101.png

4. Set the breakpoints for corresponding functions.

tr_094.png

5. Execute the local Windows Debug function.

    Press the F5 key to start the local debug function.

tr_102.png

6. On the application window, click the Add or ComputerName
button.

    Click the Add or ComputerName button to call the Add or
ComputerName functions in NewDLL.dll.

tr_103.png

7. At this moment, Visual Studio 2017 will automatically capture
the functions called and the execution of code will pause where you set
the breakpoints.

tr_097.png

Please note that it is not possible to launch the PowerBuilder
2019 process automatically if the pb190.exe path is set directly in the
Command property of Visual Studio 2017’s project properties to perform
the debugging. PowerBuilder 2019 has disabled this feature for security
reasons.


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x