[Today's programming diary, use VC compiled DLL instances in VB]

zhaozj2021-02-16  64

18:07 2003-12-3 Today, I used the VC to edit a dynamic link library (DLL) - A.dll, and then copy it below the Windows / System / Directory, then established a VB program And declare the function add () in A.DLL in the program, implement two additional additional operations. The implementation process is as follows: 1. Establish a DLL to open the VC, create an API-based DLL. ---- 1. In File-> New-> Projects Select "Win32 Dynamic-Link Library" in Project Name Enter "A" OK ---- 2. In File-> New-> Files Select C Source File, enter A.cpp in File, press OK ---- 3. Select the Text file in File-> New-> Files. Enter ah in File, press OK ---- 4. In File-> New-> Files Select the Text file, enter a.def in the file, press OK ---- 5. Source file:

Code

//---------------------------//a.cpp#include WinAPI Int Add (int A, int b) { Return (A B);} // ------------------------- // a.hwinapi int Add (int A, int B ); // -------------------------- // a.deflibrary "a"; pointing out the DLL name Description 'a Windows Dynamic Link Library '; uses the use of the DLL (this sentence is optional) exports add; the name of the export function

------ 6. Compiled into a.dll

------ 7. Copy A.dll to Windows / System / Directory

Second, establish a VB program

Enter in Form1

Code

Option ExplicitPrivate Declare Function add Lib "a.dll" (ByVal a As Integer, ByVal b As Integer) As IntegerPrivate Sub Command1_Click () Text3.Text = Str (add (Val (Text1.Text), Val (Text2.Text)) ) End Sub

The program interface is as follows:

I have encountered in the programming process:

After copying A.dll into the program directory (I didn't copy A.dll to the Windows / System / Directory), run the program, and the result is wrong! As shown below:

Later I copied A.dll to E: Put, will

Code

Private Declare Function Add lib "a as integer" (BYVAL B AS Integer) AS INTEGER Change to Private Declare Function Add lib "E: /A.DLL" (ByVal A As Integer) AS Integer

, Run the program again, it is successful!

I don't know why this is why it is, the DLL file you need to call the DLL must be one of the following three directories:

(1) System directory of Windows: / windows / system;

(2) Any directory indicated by PATH in DOS; (3) The directory where the program is located.

I don't know why I am in the case of meeting the third condition.

================================================================================★

21:36 2003-12-3

Tonight, I went to the library to read the book, I finally understood why the afternoon proceedings will be wrong.

The most important reason is because the program is still in the debug stage when pressing the F5 executing procedure, so it can't find it.

To a.dll, I think of this, I will put the program make as an application, and finally everything is normal. I am very happy

Comfort

==========================

The earliest of this article

http://www.thugx.com/main/index.php?showtopic=3250

==========================

转载请注明原文地址:https://www.9cbs.com/read-21907.html

New Post(0)