Use VC + + to write dll for PowerBuilder

Source: Internet
Author: User

When using VC + + to write a DLL for PowerBuilder, pay attention to the following 2 points: calling convention

C + + functions have _stdcall, _cdecl, _fastcall, and many other calling conventions, the calling convention is used to describe the order of the stack of function parameters and who (the function itself or the caller) to modify the stack.
When you write a DLL for a PB call, you use the _stdcall calling convention, as follows:

extern "C" _declspec (dllexport) int _stdcall GetInt (char* name) {...}

DEF file

In the project that generates the DLL, use the exports in the Def file to specify the function to be exported to prevent the function name from appearing incorrectly.


For example, a DLL would output the following two functions:
extern "C" _declspec (dllexport) int _stdcall readcard (char* str);
extern "C" _declspec (dllexport) char* _stdcall getip (int id);


The Def file is written as follows (project name is test):
LIBRARY "TEST"
DESCRIPTION ' TEST Windows Dynamic Link Library '
Exports
; Explicit exports can go
GetIP @1
Readcard @2


When you compile the build DLL, you make the following declaration when you want to invoke the GetIP function in PB:
Function string getip (int tid) library ("TEST.dll");

You can then call the function in the following code.

PB declared functions in the form of the original VC + + in line with the function.
Note that the DEF file name needs to be the same as the DLL project name. For example, if the DLL project is named Test, the Test.def is created.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.