GetUserName returns 1114 error
-
segunda-feira, 5 de julho de 2010 13:50
Calling GetUserName() function for second time (and subsequent times) returns 1114 error on a Windows 7 64-bit, if the following sequence is followed:
1. Call GetUserName() function from a global C++ object constructor (similarly from DllMain) of a DLL. This call would actually succeed.
2. Create a simple "Hello World" app that links with the above DLL.
3. Call GetUserName() from app in 2. This would return 1114 error.
4. Set 'compatibility mode' of the app from 2. to Vista (or Vista with SP1 or SP2).
This problem shows up only on Windows 7 system, only when the app and DLL is 64-bit, only if the 'compatibility mode' is set to Vista. Runs fine on Windows 2008 R2 system, even when app/dll is 64-bit and compatibility is set to Vista. Works fine on XP too.
I know one should not be calling functions like GetUserName() from DllMain or global constructors etc. But, the fact that it gives problem only when stars are aligned in certain way is kind of unsettling.
Here is the code:
DllMain.cpp:
#include <windows.h>
#include <stdio.h>
__declspec(dllexport) int print_username(char *sFromWhere)
{
char userName[256];
int userNameLen = sizeof(userName);
memset(userName, NULL, userNameLen);
if (GetUserName(userName, (LPDWORD) &userNameLen) == FALSE)
{
int err = GetLastError();
printf("%s: Error getting username: %d\n",
(sFromWhere != NULL ? sFromWhere : "From NoWhereLand: "), err);
return 0;
}
else
printf("%s: In print_username(): Username: %s\n",
(sFromWhere != NULL ? sFromWhere : "From NoWhereLand"), userName);
return 0;
}
class HelloWorld
{
public:
HelloWorld() { print_username("From HelloWorldConstructor"); }
};
HelloWorld hw;
BOOL WINAPI DllMain(HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
WSADATA wsaData;
static HANDLE hThread;
DWORD threadId;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
printf("In DLL_PROCESS_ATTACH\n");
//print_username();
break;
case DLL_THREAD_ATTACH:
printf("In DLL_THREAD_ATTACH\n");
break;
case DLL_THREAD_DETACH:
printf("In DLL_THREAD_DETACH\n");
break;
case DLL_PROCESS_DETACH:
break;
default:
break;
}
return TRUE;
}========= END DllMain.cpp =========
main.cpp:
#include <stdio.h>
#include <stdlib.h>
extern int print_username(char *);
class Hello
{
public:
Hello(){
print_username("From HelloConstructor");
}
};
int main(int argc, char* argv[])
{
Hello hello1;
print_username("From main");
}======= END main.cpp ========
Compilation/run instructions (make sure to use 64-bit version of compiler, set the compatility mode before running the exe on Windows 7 system):
del *.dll *.manifest *.exp *.ilk *.lib *.obj *.pdb *.exe
cl /Zi /MDd /LD DllMain.cpp advapi32.lib
cl /Zi /MDd Main.cpp DllMain.libThanks in advance for any insights anyone might share.
P
Todas as Respostas
-
terça-feira, 6 de julho de 2010 08:20Moderador
Hi pjee,
I have used your code to build the test project but cannot reproduce the issue when compile under x64. I use VS 2010 to build the project (I only have VS 2010 with x64 compiler). Which version of Visual Studio do you use?
Here is my test project (VS 2010). If you want to test it, please download here.
Sincerely,
Kira Qian
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! -
terça-feira, 6 de julho de 2010 12:11
Hello Kira,
Thanks for putting efforts into testing the code I put out. I hope you have tested it on Windows 7.
I tested it using Visual Studio 2008 only. Currently I don't have VS 2010 installed. So, when I get a chance, I will test it using Visual Studio 2010.
Thanks
P
-
sexta-feira, 16 de julho de 2010 14:56
Hello,
I've got the same problem on one of my projects under Windows 7 64 and Visual Studio 2010.
My project is a MFC unicode application which uses 2 DLL (AVCommon.dll and AVAdvanced.dll ) and each of them uses GetUserName.
In my solution, my application have a reference on AVCommon.dll and AVAdvanced.dll and AVCommon.dll have a reference to AVAdvanced.dll too.
The facts in detail : Launch of the app, AVCommon.dll is loading -> GetUserName is called several times without problems.
When I call a function of AVAdvanced, AVAdvanced is loading and GetUserName return ERROR_DLL_INIT_FAILED (1114).
Maybe I do something wrong, but the same project works on Windows XP and 7 32 bits.
I can't test on others OS for the moment, but next week I will be able to test it under XP 64.
Sorry for my "not very good" english ;-)
Thanks
Edit: I've forgot : I've test your application, and it's working well on 7 64 (I've got not problem with compatibility mode on my project so I've not tested it).
-
segunda-feira, 19 de julho de 2010 09:30
Hello,
After few tests it's seems that this function doesn't work only in debug mode under Windows 7 64. I have to make several tests under Xp 64 during this week.
I continue to work on it :-)
Lionel M.
-
terça-feira, 24 de janeiro de 2012 05:42
Hi,
I am seeing this problem on Windows 7 64-bit machine with 64-bit application compiled with VS2010. If I call GetUserName() function from my app, then I get an error code 1114 returned by GetLastError(). In my application, this function is called only once and it is not being called via global objects. Any idea whats going on?? A simple test program does not show this problem and it is not reproducible on all Windows 7 64-bit machines.
I will appreciate if someone can suggest a solution for this.
-Vipin -
quarta-feira, 25 de janeiro de 2012 22:48
I believe this only occurs in debug builds (which shouldn't be deployed to machines without Visual Studio installed) But here are some clues:
1) Enable Application Verifier http://www.microsoft.com/download/en/details.aspx?id=20028 then run your program in a debugger
2) Using example code above & app-verifier when running in Vista compatibility mode I got the following stop error:
VERIFIER STOP 0000000000000210: pid 0x18F8: Critical section not initialized.
000007FEFDF0F190 : Critical section address.
000007FEFDF0F1C0 : Critical section debug info address.
0000000000000000 : Not used.
0000000000000000 : Not used.
=======================================
This verifier stop is continuable.
After debugging it use `go' to continue.=======================================
(18f8.14a4): Break instruction exception - code 80000003 (first chance)
ntdll!DbgBreakPoint:
00000000`77c40530 cc int 3
0:000> kv
Child-SP RetAddr : Args to Child : Call Site
00000000`0013e388 000007fe`e1c637ee : 00000000`00000000 ffffffff`fffffffe 000007fe`e1c615a8 000007fe`e1c720b0 : ntdll!DbgBreakPoint
00000000`0013e390 000007fe`e1b997bf : 000007fe`fdf0f190 00000000`00000210 000007fe`fdf0f190 000007fe`fdf0f1c0 : vrfcore!VerifierStopMessageEx+0x772 [d:\avrf\source\base\avrf\avrf30\vrfcore\sdk.cpp @ 551]
00000000`0013e690 000007fe`e1b9a85c : 00000000`000014a4 000007ff`fffde000 00000000`0013e8d0 00000000`77c43518 : vfbasics!AVrfpVerifyInitializedCriticalSection+0xf3 [d:\avrf\source\base\avrf\vrfcommon\critsect.c @ 897]
00000000`0013e6e0 000007fe`e1b9a94e : 000007fe`fdf0f190 00000000`0013e8d0 00000000`0013e8d0 00000000`00000000 : vfbasics!AVrfpRtlEnterCriticalSection2+0x40 [d:\avrf\source\base\avrf\vrfcommon\critsect.c @ 3092]
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Windows\system32\SspiCli.dll -
00000000`0013e710 000007fe`fdef1582 : 00000000`00520050 000007fe`fdf0f9c0 00000000`00000030 00000000`00000000 : vfbasics!AVrfpRtlEnterCriticalSection+0x2a [d:\avrf\source\base\avrf\vrfcommon\critsect.c @ 3176]
00000000`0013e740 000007fe`fdef1533 : 00000000`000005f4 00000000`00000000 000007fe`fe4c8160 000007fe`fe4bbf40 : SspiCli!GetUserNameExW+0x46a
00000000`0013e790 000007fe`fdef10ab : 00000000`0013e8c0 00000000`00000000 00000000`00000000 00000000`024b3e00 : SspiCli!GetUserNameExW+0x41b
00000000`0013e7c0 000007fe`fdef1202 : 00000000`0013f5a0 000007fe`e9c40000 00000000`01960000 000007fe`e1ba3d11 : SspiCli+0x10ab
00000000`0013e7f0 000007fe`fdef1158 : 00000000`0013e9a0 00000000`0013e8d0 00000000`00000000 00000000`00010002 : SspiCli!GetUserNameExW+0xea
00000000`0013e8b0 000007fe`fdef16af : 00000000`0013e9a0 00000000`00000000 00000000`00010002 00000000`00000000 : SspiCli!GetUserNameExW+0x40
00000000`0013e900 000007fe`fe42dc34 : 00000000`037f6fb0 00000000`77cf5468 00000000`00000001 000007fe`e1a00df0 : SspiCli!GetUserNameExA+0x6f
*** WARNING: Unable to verify checksum for D:\DllMain.dll
*** ERROR: Symbol file could not be found. Defaulted to export symbols for D:\DllMain.dll -
00000000`0013e950 000007fe`e9c4107a : 00000000`00000000 000007fe`e1b99ebb 00000000`037f6fb0 000007fe`e1b9a5e9 : ADVAPI32!GetUserNameA+0x14
00000000`0013e980 000007fe`e9c41235 : 000007fe`e9c46768 000007fe`e9c4144e 000007fe`e9c41b40 00000000`36ac2bce : DllMain!print_username+0x6b
00000000`0013eae0 000007fe`e9c444f0 : 000007fe`e9c48120 00000000`650514d3 00000000`651aeac0 00000000`650552bb : DllMain!print_username+0x226
00000000`0013eb10 00000000`6505525c : 00000000`651aeac0 00000000`00000000 01ccdb6b`00000000 a1b40d67`00000001 : DllMain!print_username+0x34e1
00000000`0013eb40 000007fe`e9c41570 : 000007fe`e9c46110 000007fe`e9c46220 00000000`651aeac0 00000000`65164eb1 : MSVCR100D!initterm+0x2c
00000000`0013eb70 000007fe`e9c418fb : 000007fe`e9c40000 00000000`00000001 00000000`0013f5a0 000007fe`fe44089f : DllMain!print_username+0x561
00000000`0013ec20 000007fe`e9c41861 : 000007fe`e9c40000 000007fe`00000001 00000000`0013f5a0 000007fe`e1a00df0 : DllMain!print_username+0x8ec
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Windows\system32\verifier.dll -
00000000`0013ec70 000007fe`e19d3eb8 : 000007fe`e9c40000 00000000`00000001 00000000`0013f5a0 00000000`00000000 : DllMain!print_username+0x852
00000000`0013eca0 000007fe`e1c6b4cb : 00000000`00000001 00000000`00000001 000007fe`e1c7ed68 00000000`0013ee20 : verifier!VerifierGetProviderHelper+0x63c0
0:000> !cs -s 000007FEFDF0F1C0
-----------------------------------------
Critical section = 0x000007fefdf0f1c0 (SspiCli!SaslIdentifyPackageW+0x7EBC)
Uninitialized or deleted.
LOCKED
LockCount = 0x83C39B
WaiterWoken = Yes
OwningThread = 0x0000000000000000
RecursionCount = 0x7FE
LockSemaphore = 0x0
SpinCount = 0x00000000000000003) Regarding Vista SHIMs...they apply the following settings (maybe this gives clues?)
- EmulateSortingVista
- Vista sorting behaviour for CompareString, LCMapString, FindNLSString and IsNLSDefinedString APIs
- FaultTolerantHeap (http://msdn.microsoft.com/en-us/library/dd744764(v=vs.85).aspx)
- No Ghost
- No Window Ghosting for this application
- VirtualRegistry
- Hooks all registry functions to allow virtual keys, redirection and expansion values
- VistaRTMVersionLie
- App will see OS version as Vista
- WRPMitigation
- Access Check will return success on WRP protected file
By the way - I narrowed it down to the fact that this only occurs when WRPMitigation SHIM is applied. You can apply all others without any issue.
- Editado Malcolm McCaffery quinta-feira, 26 de janeiro de 2012 07:45
- Sugerido como Resposta Ivan Flek quinta-feira, 12 de abril de 2012 11:05
- Não Sugerido como Resposta Ivan Flek quinta-feira, 12 de abril de 2012 11:19
- EmulateSortingVista
-
quinta-feira, 12 de abril de 2012 11:16
I have similar problem. But in application created in VB. Today I compile my application and suddanly problem apeared. There is no matter to send block of code because there was not such error before. Instead I will try to send message from debuger.
VerifierStopMessageEx(_AVRF_LAYER_DESCRIPTOR *, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, _AVRF_STOP_EXTRA *, <no type>) line 570
Locating source for 'd:\avrf\source\base\avrf\avrf30\vrfcore\sdk.cpp'. Checksum: MD5 {db c3 ab fd 77 82 33 dd bd 67 6f ec c0 2a a 96}
The file 'd:\avrf\source\base\avrf\avrf30\vrfcore\sdk.cpp' does not exist.
Looking in script documents for 'd:\avrf\source\base\avrf\avrf30\vrfcore\sdk.cpp'...
Looking in the projects for 'd:\avrf\source\base\avrf\avrf30\vrfcore\sdk.cpp'.
The file was not found in a project.
Looking in directory 'C:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\'...
Looking in directory 'C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\src\mfc\'...
Looking in directory 'C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\src\atl\'...
Looking in directory 'C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\'...
The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: d:\avrf\source\base\avrf\avrf30\vrfcore\sdk.cpp.
The debugger could not locate the source file 'd:\avrf\source\base\avrf\avrf30\vrfcore\sdk.cpp'.Problem not apeared when application is tested directly in VS 2010 but when is started as finished stand alone application. Application was created in VB 2010 and .Net Framework 2.0.
Please help me to solve this trouble.
Thanks a lot.

