Call DLL Function

Post specialized setup scripts you have created here.
SITL
Posts: 114
Joined: Tue Sep 27, 2016 12:31 am

Call DLL Function

Postby SITL » Tue Sep 27, 2016 2:02 am

Hi Francesco Toscano,

Your answers to other questions helped me to get started, Appreciate.
I'm calling two Dll functions (VC++), one works and other one fails. see if you can help me.

CASE I : This one works.
Function prototype :
extern "C" __declspec(dllexport) WORD UpdateLicenseKey1()
{
return 22;
}

And this is how I'm calling from InstallAware -

~InstallAware Clipboard Data~
~Call DLL Function~
~{784B4EB7-116D-4EA4-99BA-B80D1BB4A619}~
~F:\VC2010\InstallerTest\Debug\InstallerTest.dll,UpdateLicenseKey1,word,DWORDVALUE,$~
~mIDEFunc.dll\mEXEFunc.dll~

Result : No issue, works as expected
===========================================End of CASE I ==================
CASE II : This one doesn't work - Getting EXTERNALEXCEPTION

Function prototype :
extern "C" __declspec(dllexport) BOOL UpdateLicenseKey(char* key)
{
return TRUE;
}
And this is how I'm calling from InstallAware -

~InstallAware Clipboard Data~
~Call DLL Function~
~{DC68A8D9-1EA2-4C49-9501-151909EB3DBF}~
~F:\VC2010\InstallerTest\Debug\InstallerTest.dll,UpdateLicenseKey,bool,LicenseKeyStatus,"pointer to string",$NewKeyValue$,$~
~mIDEFunc.dll\mEXEFunc.dll~

Result - EXTERNALEXCEPTION

========== End of CASE II =====================

FrancescoT
Site Admin
Posts: 4860
Joined: Sun Aug 22, 2010 4:28 am

Re: Call DLL Function

Postby FrancescoT » Tue Sep 27, 2016 11:48 am

Dear SITL,

your second DLL call looks correct ... supposing you declared your "NewKeyValue" variable before to use "Call DLL Function" and that such variable has been initialized to some value.

Hope this helps you.

Regards
Francesco Toscano
InstallAware Software Support

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE

SITL
Posts: 114
Joined: Tue Sep 27, 2016 12:31 am

Re: Call DLL Function

Postby SITL » Wed Sep 28, 2016 12:15 am

Dear Francesco Toscano,

Appreciate your reply,
I have decalared and properly initialised the variable NewKeyValue.
In fact I'm displaying the value in the debugger. and tried all the different ways and methods of calling and exporting function.
I tried DWORD and LONG as well (because some times string may cause problems due to some other reasons).
Only passing parameters is not Working.

Can you give me some function prototypes ? I'll use the same and see how it goes.
I feel the problem with function prototype and the way you export.

Regards
SITL

SITL
Posts: 114
Joined: Tue Sep 27, 2016 12:31 am

Re: Call DLL Function

Postby SITL » Mon Oct 03, 2016 4:52 am

Dear Francesco Toscano,

No success, Tried different methods :o :?
Guide me, I'm almost stuck.

Regards
SITL

FrancescoT
Site Admin
Posts: 4860
Joined: Sun Aug 22, 2010 4:28 am

Re: Call DLL Function

Postby FrancescoT » Mon Oct 03, 2016 11:58 am

Dear STL,

Your Function prototype "extern "C" __declspec(dllexport) BOOL UpdateLicenseKey(char* key)" looks correct, but probably there is something else wrong with your DLL.

Did you try to call your DLL from a test C++ application? ... you can even debug it.

Personally I don't use "__declspec" with my DLLs and I prefer to Export from a DLL Using DEF Files.
https://msdn.microsoft.com/en-us/library/d91k01sh.aspx

If you want I can send you a "dummy dll" sample via DEF file... just send me an email to; support@installaware.com.

Regards
Francesco Toscano
InstallAware Software Support

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE

StarMessage
Posts: 3
Joined: Thu Jul 26, 2018 1:32 am

Re: Call DLL Function

Postby StarMessage » Tue Jul 31, 2018 3:49 am

This is an old question but it is a constant bother to all developers calling functions from DLLs.
I tried to call a DLL from Installaware so I am pretty sure the problem described here is a calling convention problem.
According to my observations, Installaware calls DLL functions only by the __stdcall calling convention. It does not offer the __cdecl calling convention.
This is quite ok, because the Windows API mostly uses __stdcall.
Now, as a developer you will not notice the difference if the function does not take parameters (your first sample that works ok).
If the function takes arguments (your non-working sample) then it will most probably crash.

Therefore, the DLL function prototype should be
extern "C" __declspec(dllexport) BOOL __stdcall UpdateLicenseKey(char* key)
OR
If you export by DEF file, the function will be exported as stdcall. It will also have a un-mangled function name.

I recently updated my dll to work with installaware.
Here are my prototypes.
https://github.com/starmessage/libSoftM ... er-C-Api.h
(Scroll down to the REMed section)

See also the description of this __cdecl, vs __stdcall
https://www.starmessagesoftware.com/new ... -analytics


Return to “Sample Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest