Troubleshoot Excel XLL Memory Management and xlAutoFree12 for XLOPER12
Question details
The user needs to understand why two Excel XLL functions registered with Q and Q$ signatures behave differently when returning heap-allocated XLOPER12 values and how xlAutoFree12 should release them.

- Product
- Microsoft Excel XLL add-in
- Device & OS
- not provided
- Scenario
- Developer debugging Excel XLL add-in functions that return heap-allocated XLOPER12 values registered with Q and Q$ signatures.
- Observed behavior
- The Q$ registration appears to change memory behavior or ownership for returned XLOPER12 values, but the exact cause is unclear.
Confirm the XLL bitness matches your Excel installation and verify that xlAutoFree12 is exported with the WINAPI calling convention before changing any memory-management code.
Release heap-allocated XLOPER12 results directly in xlAutoFree12
Use this when xlAutoFree12 is calling xlFree before deleting an XLOPER12 that contains no Excel-managed memory, such as an xltypeInt result.
The Q and Q$ registration difference is only a thread-safety flag. The dollar sign does not change XLOPER12 ownership rules or make heap allocation inherently safer.
For an xltypeInt result, the XLOPER12 contains no Excel-allocated internal memory, so calling Excel12(xlFree, ...) is unnecessary and can cause inconsistent behavior.
Open the Excel SDK registration table for the XLL functions and confirm that Q and Q$ both return XLOPER12 with xlbitDLLFree set; the dollar sign only marks the function as thread-safe.
In the XLL source, change xlAutoFree12 to delete the structure directly: void WINAPI xlAutoFree12(LPXLOPER12 pxFree){ delete pxFree; }
Delete any Excel12(xlFree, nullptr, 1, pxFree) call inside xlAutoFree12 for xltypeInt results, because there is no Excel-managed memory to release.
Ensure xlAutoFree12 is exported with WINAPI or the correct calling convention and that the XLL is compiled for the same 32-bit or 64-bit architecture as Excel.

Use WPS Office as a Lightweight Alternative for Everyday Excel-Compatible Work
WPS Office is a free, lightweight Office suite that opens Excel workbooks with familiar formatting and features. While custom XLL add-in debugging remains an Excel SDK task, WPS Office handles day-to-day spreadsheets, documents, and presentations without the overhead of Microsoft Office.

Frequently Asked Questions
Does the Q$ registration change who owns the returned XLOPER12 memory?
No. The dollar sign only indicates that the function is thread-safe. It does not change XLOPER12 ownership rules or make heap allocation safer.
Why does xlAutoFree12 need to call Excel12(xlFree, ...)?
It only needs to call xlFree when the XLOPER12 contains Excel-managed memory. For an xltypeInt result, there is no Excel-managed memory inside the structure, so you can simply delete pxFree.
What calling convention should xlAutoFree12 use?
Export xlAutoFree12 with the WINAPI calling convention and compile the XLL for the same bitness as Excel, whether 32-bit or 64-bit.
Can WPS Office run Excel XLL add-ins?
Custom XLL add-in debugging is specific to the Excel SDK. WPS Office is better used as a free, lightweight alternative for opening and editing regular Excel-compatible workbooks.
How can I avoid memory-management issues in XLL functions?
Set xlbitDLLFree only when the XLOPER12 is allocated with a compatible allocator, keep xlAutoFree12 consistent with that allocation, and verify calling convention and bitness.




