Probe into VB and VC Communication (1)

xiaoxiao2021-03-13  184

In use

VB

transfer

VC

written

DLL

When you can realize some

VB

Can not be implemented or difficult to implement, but because

VB

versus

VC

The data type between the data is not always correct, so when the parameter is passed, the type is required to be converted. Below I will see how to achieve it through a gradual advancement method.

VB

versus

VC

Communication between.

First, look at a simple example.

Program in the VC:

Extern "C" _Declspec (DLLEXPORT) Void ReadString (Void)

{

// Function function

}

Compile this VC program into a DLL program for VB calls (assuming to generate commication.dll)

Programs in VB:

........................

Private Declare Function ReadString LIB "CommCICITION.dll" ()

........................

Call readstring

Here, we have implemented a simple communication, which writes a DLL in the VC, then call this DLL in VB, but in this communication, actually there is no data between them, only It is VB to call the DLL, so that the function readstring () function in Commicion.dll is executed. This communication implementation is very simple, so his function is very simple, but our requirements must not stop here.

Let us now implement an example of using the DLL to process data in the VB, and return the processing result to the VB program:

Program in the VC:

Extern "C" _Declspec (DLLEXPORT) BOOL ReadString (Bool Receive)

{

IF (Receive == True)

Return True;

Else

Return False;

}

Programs in VB:

........................

Private Declare Function ReadString LIB "Commication.dll" (Byval Send As Boolean) AS Boolean

........................

Dim Result As Boolean

Dim send as boolean

Send = false

Result = readstring (Send)

IF results

Msgbox "The return value is 'true'"

Else

Msgbox "The Return Value IS 'FALSE'"

END IF

During this communication process, we still have a very simple pass process. In the DLL, the received parameters return to the VB call program, although it is simple, but it has been implemented The data between VB and DLL is passed here. It is important to note that the data type between them, the keyword used by the Boolean data in the VC is Boolean, and the keyword used in the VC is Bool.

Since the data type between VB and VC does not have the same keyword, for convenience, the keywords used in VC and VB are listed below for convenience:

Conditions of declaration in the data type VB in C

Atom BYVAL VARIABLE AS INTEGER results for the INTEGER Type Bool Bool Bool Bool BYTE BYTE BYTE Type of Expression CHAR BYTE Type of Expression COLORREF BYVAL Variable as long result for long-type expression DWORD BYVAL VARIABLE AS long result is a long-type expression hWnd, HDC, HMENU BYVAL VARIABLE AS long result is a long-type expression, etc. The Windows handle Int, uint byval variable as long result is LONG Type Expression Long Byval Variable As Long Result For the LONG Type of Expression LPARM BYVAL VARIABLE AS Long Results For the LONG Type The LPDWORD VARIABLE As long result is the expression of the long type LPINT, LPUINT VARIABLE AS long result is a long type Expression LPRECT VARIABLE AS TYPE Customized Types Any variable LPSTR, LPCSTR BYVAL VARIABLE AS STRING Results for String Types LPVOID VARIABLE AS Any Any variable (using Byval when delivering strings) LPWORD VARIABLE AS INTEGER Results NULL As Any or ByVal Nothing or ByVal variable As Long ByVal type Integer expression LRESULT ByVal variable As Long Long result is an expression of type 0 or & VBNullString SHORT ByVal variable As Integer Integer result is an expression of type VOID Sub procedure is not Use Word Byval Variable AS Integer Results for Integer Types The expression wparam Byval Variable as long result is a long-type expression

Ok, now we have established a basic communication mode, and achieve two simple communication processes. This takes a break, then take a look at how to achieve more complex communications! (to be continued)

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

New Post(0)