| |

VerySource

 Forgot password?
 Register
Search
View: 2115|Reply: 5

Questions about calling C ++ BUILDER dynamic link library

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-27 21:40:01
| Show all posts |Read mode
I believe that many people have raised such questions, but it seems that they have not received a substantive answer.

First: I wrote and generated a dynamic link library XXX.dll in VC, and exported a class CXXXClass,
The dynamic link library provides both XXX.lib and xxx.h header files

Question: How to call the dynamic link library in C ++ Builder through static and dynamic methods, hoping to provide a simple example.
Reply

Use magic Report

0

Threads

27

Posts

24.00

Credits

Newbie

Rank: 1

Credits
24.00

 China

Post time: 2020-3-1 12:15:01
| Show all posts
1 This problem is troublesome because the examples are not good
2 windows own dll is called by bcb without problem
  But the vc dll is not necessarily very smooth.
  
  If you want to dynamically call a dll written in vc, there is generally no problem.
  
  If you want to statically call a dll written in vc, you need to use borland's tools to create the dll's lib.
  This tool is Coff20mf.exe, in the CB bin folder.
  If the lib generated by vc is vc_dll.lib
  Execute Coff20mf.exe vc_dll.lib vc_dll.new
  Delete the vc_dll.lib file
  Change the name of vc_dll.new to vc_dll.lib
  Add it to the project and use vc_dll.dll statically

3 If it doesn't work, it's a function alias
  Have to use impdef.exe to generate vc_dll.def
  Manually change vc_dll.def
  Use implib.exe to return to vc_dll.lib

The premise is that you have mastered using dynamic and static methods to call cb's own dll.
Reply

Use magic Report

0

Threads

14

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-3-5 10:30:02
| Show all posts
Static call
1 Use BCB's command line tool implib to carry out the DLL generated by VC, and grow a lib file.
2 Add the exported file to the BCB project
3 Declaring functions in BCB

extern "C" __declspec (dllexport) DWORD __stdcall AR_WNetAddConnection2
(
  LPNETRESOURCE lpNetResource, // connection details
  LPCTSTR lpPassword, // password
  LPCTSTR lpUsername, // user name
  DWORD dwFlags // connection options
);
// ------------------------------------------------ ---------------------------

extern "C" __declspec (dllexport) DWORD __stdcall AR_WNetCancelConnection2
(
  LPCTSTR lpName, // resource name
  DWORD dwFlags, // connection type
  BOOL fForce // unconditional disconnect option
);
// ------------------------------------------------ ---------------------------

4 BCB can start calling

Edit3-> Text = AR_WNetAddConnection2 (&nr, "u1", "u1", CONNECT_PROMPT);
Edit2-> Text = AR_WNetCancelConnection2 ("X:", CONNECT_UPDATE_PROFILE, false);
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-21 11:30:01
| Show all posts
HINSTANCE hInst;
hInst = LoadLibrary("DLLSAMP.DLL");
(FARPROC&)ShowImage=GetProcAddress(hInst,"ShowImage");
ShowImage();
FreeLibrary(hInst);
Reply

Use magic Report

0

Threads

16

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-28 15:30:01
| Show all posts
Support the owner, favorite
Reply

Use magic Report

0

Threads

5

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-28 21:00:02
| Show all posts
A bit difficult
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list