How to dynamically Call DLL Functions in ActiveX Controls

Source: Internet
Author: User
Tags constant definition

 

 

First useAtl com AppWizard generates a project named PosActiveX. when the project is generated, the system will ask you whether to generate a DLL or EXE. Of course it is DLL. After the generation, add an interface called IPosCtrl. Of course, it must be used on the Web. Therefore, the generated interface must be small, so select Lite Control. After the interface is added, the implementation method is required. First, you must initialize the interface. Therefore, add an interface method called Init (short nCom) to complete the function of loading DLL and DLL, and open the comport for operations on the POS machine; another method is ModifyPosDT (BSTR bstrDT), and EmptyPos (). Finally, you need to close the open comport-Quit () when you don't want it (). The CPosCtrl class is also generated when the IPosCtrl interface is generated. Generally, the implementation methods are written in the class, while the interface only outputs the method you want to output in the class. Therefore, the following methods are written in the class:

 

InitDll () ---- load the DLL library and its functional functions;

ExitDll () ---- detach the DLL library. If you do not detach the library after use, the memory is occupied. So it is indispensable.

SetPosDateTime (char * pchDT) --- set the time of the POS machine.

ClearPos () ---- clear records from the POs server.

 

I wrote these methods in the class.

 

The interface methods I want to output are as follows:

Init (short nCom) ---- the initial interface to prepare for calling.

Quit () ---- call the exit interface when exiting the program.

ModifyPosDT (BSTR bstrDT) ---- set the POs server time.

EmptyPos () ---- clear the POS data.

 

 

// PosCtrl. cpp: Implementation of CPosCtrl

 

# Include "stdafx. h"

# Include "PosActiveX. h"

# Include "PosCtrl. h"

 

//--------------------------------------------------------

// Constant definition used by Police. dll

//--------------------------------------------------------

# Define Com_UpRecord 1

# Define com_up1_elen 2

# Define Com_UpSimpleDataLen 3

# Define Com_UpSimplePunishLen 4

# Define Com_UpGeneralDataLen 5

# Define Com_UpGeneralPunishLen 6

 

# Define Com_EmptyPolice 7

# Define Com_EmptySimpleData 8

# Define Com_EmptySimplePunish 9

# Define Com_EmptyGeneralData 10

# Define Com_EmptyGeneralPunish 11

 

# Define Com_DownRecord 0x80

# Define Com_DownStreetCodeLen 0x81

# Define Com_DownBlackListLen 0x82

# Define Com_DownPeccancySimpleLen 0x83

# Define Com_DownPeccancyGeneralLen 0x84

# Define Com_DownDateTime 0x85

# Define Com_Exit 0x86

# Define Com_Init 0x87

 

# Define Err_UpSimpleDataLen 0

# Define Err_UpSimplePunishLen 1

# Define Err_UpGeneralDataLen 2

# Define Err_UpGeneralPunishLen 3

# Define err_upcancelen 4

# Define Err_UpRecord 5

# Define Err_DownStreetCodeLen 6

# Define Err_DownSimplePeccancyCodeLen 7

# Define Err_DownGeneralPeccancyCodeLen 8

# Define Err_DownBlackList 9

# Define Err_DownDateTime 10

# Define Err_EmptyData 11

# Define Err_GetCode 12;

 

# Define Const_Terminator 0x20

 

# Pragma data_seg ("mydata ")

 

Static HINSTANCE DLLInst = NULL; // dynamic library handle

 

# Pragma data_seg ()//

 

HANDLE hCom; // COM serial port HANDLE

 

//------------------------------------------------------

// POLICE. DLL dynamic library function definition

//------------------------------------------------------

HANDLE (_ stdcall * Init_comm) (LPSTR str); // initialize the communication port

BYTE (_ stdcall * Exit) (HANDLE hCom); // close the communication port

BYTE (_ stdcall * Protocol) (HANDLE hCom, BYTE cmd, BYTE len, BYTE * _ dt, BYTE * prlen, BYTE * prdt); // communication Protocol

BYTE (_ stdcall * Pipe_control) (HANDLE hCom, BYTE mode); // multiple control typedef

BYTE (_ stdcall * Dev_escape) (HANDLE hCom); // disconnect multiple channels

 

 

//---------------------------------------------

Related Article

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.