balu489
Flexera beginner

Dll calling function fails using Installscript

Hi,
Could anyone please help me out with this problem?

I'm facing a problem while calling a dll function using Installscript 2018. Following is my install script code.

The prototype is as follows:
prototype STRING encryption.encrypt(BYREF STRING, BYREF STRING );
prototype STRING encryption.decrypt(BYREF STRING, BYREF STRING );

//DLL Calling script OnFirstUIBefore
 szDLLName = SUPPORTDIR ^ "encryption.dll";    
    LongPathToShortPath(szDLLName);
    nResult = UseDLL (szDLLName);    
    MessageBox(szDLLName, INFORMATION);
   
    if (nResult = 0) then
        MessageBox ("UseDLL successful \n\n.dll file loaded.", INFORMATION);
    else
        MessageBox ("UseDLL failed.\n\nCouldn't load .dll file.", INFORMATION);
        abort;
    endif;

szEncryptoutput= encryption.encrypt(svString,szKey);
       MessageBox(szEncryptoutput, INFORMATION);
 
//The dll is getting loaded successfully. But it fails when executing at the point of szEncryptionput. Getting below issue.
Unhandled Exception
Error Number : 0x80040702
Description: Failed to load DLL: encryption
 

The dll was created in C++, following is the function details.

typedef std::string (*encrypt_fp)(std::string, std::string);
typedef std::string (*decrypt_fp)(std::string, std::string);

int main()
{
HINSTANCE hGetProcIDDLL = LoadLibrary("encryption.dll");

if (!hGetProcIDDLL) {
std::cout << "could not load the dynamic library" << std::endl;
return EXIT_FAILURE;
}

// resolve function address here
encrypt_fp encrypt = (encrypt_fp)GetProcAddress(hGetProcIDDLL, "encrypt");
if (!encrypt) {
std::cout << "could not locate the function" << std::endl;
return EXIT_FAILURE;
}

decrypt_fp decrypt = (decrypt_fp)GetProcAddress(hGetProcIDDLL, "decrypt");
if (!decrypt) {
std::cout << "could not locate the function" << std::endl;
return EXIT_FAILURE;
}

std::string msg = "asdfasdf";
std::string key = "mykey";

std::string abcd = encrypt(msg, key);

std::cout << "encrypt() returned " << abcd << std::endl;

std::cout << "encrypt() returned " << decrypt(abcd, key) << std::endl;

 
Labels (1)
0 Kudos
4 Replies
varul
Revenera
Revenera

Hi Balu489,

Try using SetDllDirectory and then try calling use dll and see it works or not, Refer below link for more details

https://docs.revenera.com/installshield24helplib/Subsystems/LangRef/helplibrary/LangrefUseDLL.htm

Hope it helps.

0 Kudos
balu489
Flexera beginner

Thanks, Varul for the quick response!.

I did follow the shared Url and set the SetDllDirectory path, now I'm getting an APPCRASH issue. Please find the attached image.

 

 

0 Kudos

Hi Balu489,

Thank you for your reply.

Could you please open a new support ticket (case) to track this issue? you can raise a ticket by sending e-mail to below address

You can email: support@revenera.com 

You can also reach out to the support team who will be able to help you with raising a new case

https://community.flexera.com/t5/Support-Information/Support-Contacts/ta-p/94720 

This will allow us to best track this issue so that we can best assist you.

Thank you for your patience and cooperation.

0 Kudos
ch_eng2
Occasional contributor

I don't know if this has already been discussed here, but depending on where your "svString" and "szKey" come from you may need to do some manipulation.  That is, if your strings are coming from user input (example: InstallShield dialog "Edit" controls) or files (example: .config file), InstallShield treats them as fixed-length 1024 character arrays - String[1024].  You can test this by adding a function to your C++ DLL that just writes the passed string to a new text file with some padding characters on either side (###{your_string}###) and call that instead.  Then look in the file and verify if the string has extra padding spaces which are not expected.

The workaround we have used in this case is to call the InstallScript function StrSub to trim the padding characters before sending it to the external DLL:

StrSub( svString, svString, 0, StrLengthChars( svString) );

HTH

0 Kudos