InstallShield6.x call DLL functions created by C ++

zhaozj2021-02-16  35

Copyright Notice: You can reprint anything, please be sure to indicate the original source of the article by hyperlink http://xinyistudio.vicp.net/ and author information and this statement

the reason

--------------------------------

Recently, I brings some questions when writing installshield6.x, when verifying the serial number of the user, I need to compare the input string, installshield6.x is not case sensitive when comparing the string. (Ie, the case is not sensitive), and thus, it is impossible to determine whether the user's input is legal. I believe that many people have encountered such problems.

solve

--------------------------------

Quote a function in the DLL to verify that the user's input is legal, to explain that the DLL generated here is based on C or C language compiled, here I use VC as a DLL development environment. Basic ideas: Writing the DLL called by InstallShield, name strCompare.dll, the function name to be exported, Strcomp, compare the corresponding characters in the two strings, and distinguish the case. The STRComp code is as follows:

_Declspec (DLLEXPORT) BOOL APIENTRY STRComp (HWND HWND, LPSTR STR1, LPSTR STR2)

{

IF (hwnd == null || str1 == null || str2 == null)

{

MessageBox (NULL, "Enter Parameters Errors!", "Error Information", MB_ok | MB_ICONERROR);

Return False;

}

IF (strCMP (str3, str2) == error_success) // strcmp can distinguish between case characters

Return True;

MessageBox (hwnd, "sequence number error, the reason may be case wrong!", "Warning", MB_OK | MB_ICONWARNING;

Return False;

}

Please note that the beginning of the function I use _Declspec (please refer to MSDN) as a function to transfer the declaration, so it is necessary to use the strCompare.def file with the same name as the DLL file, the file content is as follows:

Strcompare.def: DECLARES The Module Parameters for the DLL.

Library "strcompare"

Description 'strcompare Windows Dynamic Link Library'

Exports

Explicit Exports Can Go Here

Strcomp

Participate in the completion of this file into the project, which will prohibit the compiler to output the exported function (different C compilers will output the exported functions). This step is very important. If you don't use the strcompare.def file, the exported strcomp function name cannot be identified by InstallShield, this export function looks like this:? Strcomp @@ yghpauhwnd __ @@ pad1 @ z,

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

New Post(0)