Marek
Posts: 24
Joined: Mon Dec 28, 2009 9:25 am

Exception from DisplayRegistrationStr in Trial.dll

The problem concerns the Advanced Installer 12.7.
Execution of the function DisplayRegistrationStr always generates an exception.

I am using the example in topic 'Integrate Licensing support in C++ applications' (http://www.advancedinstaller.com/user-g ... using.html).

Sample C++ code below:

Code: Select all

void CMFCApplication1Dlg::OnBnClickedButton1()
{
	HMODULE hModule = ::LoadLibrary(L"Trial.dll");
	if(hModule == NULL)
		return; // Missing Trial DLL;

	typedef UINT(__stdcall * TrialFcn)(LPCSTR, HWND);
	TrialFcn displayRegProc = reinterpret_cast<TrialFcn>(::GetProcAddress(hModule, "DisplayRegistrationStr"));
	if(displayRegProc == NULL)
	{
		::FreeLibrary(hModule);
		return; // Missing Trial DLL;
	}

	// Return values:
	// "0" - the application is registered (a valid license key was found/entered);
	// "2" - the application is in trial mode;
	int ret = displayRegProc(aKeyCode, (HWND)this->GetSafeHwnd());
	::FreeLibrary(hModule);
}
Visual Studio Ouput window

Code: Select all

First-chance exception at 0x0F0649A2 (Trial.dll) in MFCApplication1.exe: 0xC0000005: Access violation reading location 0x00000020.
Unhandled exception at 0x0F0649A2 (Trial.dll) in MFCApplication1.exe: 0xC000041D: Wystąpił nieoczekiwany wyjątek podczas wywołania zwrotnego użytkownika.
Visual Studio Disassembly window:

Code: Select all

0F064994  mov         eax,dword ptr [ebx+18h]  
0F064997  mov         eax,dword ptr [eax+edi*4]  
0F06499A  jmp         0F06498D  
0F06499C  push        ebx  
0F06499D  mov         ebx,ecx  
0F06499F  push        ebp  
0F0649A0  push        esi  
0F0649A1  push        edi  
0F0649A2  mov         esi,dword ptr [ebx+20h]     <<<<< this line generate an exeption; ebx is always 0
0F0649A5  xor         edi,edi  
0F0649A7  sub         esi,dword ptr [ebx+1Ch]  
0F0649AA  sar         esi,2  
0F0649AD  test        esi,esi  
0F0649AF  je          0F0649E5  
0F0649B1  mov         ebp,dword ptr [esp+14h]  
0F0649B5  cmp         dword ptr [ebp+14h],8  
0F0649B9  jb          0F0649C0  
0F0649BB  mov         ecx,dword ptr [ebp]  
0F0649BE  jmp         0F0649C2  
This problem is repeated 100/100.
What am I doing wrong?
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Exception from DisplayRegistrationStr in Trial.dll

Hello,

I'm not so sure why this happens, but can you please make sure you first initialize the trial module using the "ReadSettingsRetStr" function before calling the "DisplayRegistrationStr" function. If the issue still persists, would it be possible for you to send us a sample (AIP + its referenced files + the source code of your C++ app) to support at advancedinstaller dot com so we can fully build and test them on our side?

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Marek
Posts: 24
Joined: Mon Dec 28, 2009 9:25 am

Re: Exception from DisplayRegistrationStr in Trial.dll

Hello Daniel!
My mistake. Using the ReadSettingsRetStr() actually solves the problem.

My problem stems from insufficient understanding of the mechanisms.
A little guilty is not entirely clear description of it on your website.
If I may suggest.
It should be clearly written, the DLL must be available throughout the duration of the program, that you can not use FreeLibrary() until the program is working.
Or.
The beginning of the sample function DisplayRegistrationDlg() should use GetHandleModule() instead of LoadLibrary() which clearly suggest the correct way to use the library.

Code: Select all

int DisplayRegistrationDlg(LPCSTR aKeyCode, HWND aHWnd) 
{
  HMODULE hModule = ::GetHandleModule("Trial.dll");
  if(hModule == NULL)
    return -1; // Missing Trial DLL;
    
    ...
    
}
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Exception from DisplayRegistrationStr in Trial.dll

Hello Marek,

Yes, you are right. Our trial.dll module should be available for your application throughout all your application run time. Also, the "FreeLibrary()" and " LoadLibrary()" action calls are incorrect, respectively misleading. We will correct and update our article code in a future version of Advanced Installer. Thank you for bringing this to our attention.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”