Well, the fix was to use the Best Practices, which means:
1) Only call GetLastError for functions that actually SET it.
2) Only call GetLastError when the function RETURNS an error status.
3) Only call GetLastError immediately AFTER calling a function that returns an error status.
In my case I wasn't following #2 so the following fixed the problem:
if (lResult == ERROR_SUCCESS){
regFuncCreateKeyEx =
(REGFUNCCreateKeyEx)GetProcAddress(
hAvapi32,
(LPCSTR)"RegCreateKeyExA" );
regDyFunc::csLastCall = "GetProcAddress(Avapi32,RegCreateKeyExA)";
if (!regFuncCreateKeyEx)
lResult = GetLastError();
}
Thanks for you help, Codeproject rocks!