Page 1 of 1

Call DLL Function

Posted: Tue Sep 27, 2016 2:02 am
by SITL
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 =====================

Re: Call DLL Function

Posted: Tue Sep 27, 2016 11:48 am
by FrancescoT
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

Re: Call DLL Function

Posted: Wed Sep 28, 2016 12:15 am
by SITL
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

Re: Call DLL Function

Posted: Mon Oct 03, 2016 4:52 am
by SITL
Dear Francesco Toscano,

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

Regards
SITL

Re: Call DLL Function

Posted: Mon Oct 03, 2016 11:58 am
by FrancescoT
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

Re: Call DLL Function

Posted: Tue Jul 31, 2018 3:49 am
by StarMessage
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