Unlock Chilkat Per DLL

To properly unlock the Chilkat C++ library in a Windows application that includes multiple DLLs, each component (main EXE and each DLL) must call CkGlobal::UnlockBundle(...) independently, because:

> Chilkat unlock state is not global to the process — it is per-module (DLL or EXE).

> Each module must create its own CkGlobal instance and unlock it once at startup.


Why Unlock Per DLL?

  • Chilkat C++ is not a COM component or shared runtime — each DLL or EXE using Chilkat has its own static data.
  • Unlocking in the main application does not propagate to DLLs.
  • Each module must unlock its own Chilkat runtime instance.

How to Unlock in a DLL (via DllMain)

Here’s how you do it safely and correctly:

1. Add this to one of your .cpp files in the DLL:

#include <windows.h>
#include "CkGlobal.h"

BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
	if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
		// Unlock Chilkat for this DLL
		CkGlobal glob;
		bool success = glob.UnlockBundle("YOUR-CHILKAT-UNLOCK-CODE");
		if (!success) {
			// Consider logging or failing the DLL load (optional)
			return FALSE;
		}
	}
	
return TRUE;
}
  • Replace YOUR-CHILKAT-UNLOCK-CODE with your actual unlock code.
  • This call ensures Chilkat is initialized and licensed for use within the DLL.
  • You only need to unlock once at load time per DLL.

Notes on Unlocking

  • Does not connect to the internet
  • Can be safely called multiple times (but is only needed once per module)

Also Unlock in the Main EXE

In your main application, you should similarly unlock once during startup:

CkGlobal glob;
bool success = glob.UnlockBundle("YOUR-CHILKAT-UNLOCK-CODE");
if (!success) {
// handle failure
}

This ensures the Chilkat functionality is available in the main application logic as well.


Summary Table

Module Type Needs "UnlockBundle()"? Where to call it?
Main Application ✔ Yes Early in "main()" or init code
Each DLL ✔ Yes In "DllMain → DLL_PROCESS_ATTACH"