Solved

GetUserName WinDDK

Posted on 2011-02-18
1
862 Views
Last Modified: 2013-12-14
There is an example in WinDDK called WatermakrUni. this example add watermark for pcl printer. watermark text is taken from user via user interface of printer proporties.

 i want to get username from windows so ican put it on page as watermark. When I try to compile source code with  GetUserName function,  compiler gives no error or warning.

But when I install plug in  it crash instantaly. program say acces vialotion.  when it comes to executeion of GetUserName functions. i am sending source code which I edit it

example in the this directory \WinDDK\7600.16385.1\src\print\oemdll\watermarkuni

error message =  0xC0000005: Access violation reading location 0x00000208.

GetUserName((LPWSTR)pOEMUIParam->pOEMOptItems[1].pSel,(LPDWORD)(MAX_PATH * sizeof(WCHAR))); // this is the part I added
0
Comment
Question by:Tungaalper
1 Comment
 
LVL 33

Accepted Solution

by:
sarabande earned 250 total points
ID: 34941182
access violation is cause the second argument of GetUserName is pointer to a long word that should take the length of the name. you made a cast of a constant to LPDWORD what crashes when the function assigns a value to the address the pointer is pointing to.

the statement also crashes if one of pOEMUIParam or pOEMUIParam->pOEMOptItems or pOEMUIParam->pOEMOptItems[1] or pOEMUIParam->pOEMOptItems[1].pSel  is invalid pointer or NULL.

i don't know why you use a so complicated variable for first argument of GetUserName which is simply a char or wchar_t buffer

so use

   TCHAR buffer[1024];
   DWORD len = sizeof(buffer) / sizeof(buffer[0]);
   BOOL ret = GetUserName(buffer, &len);

and it will work.

Sara
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SHA256 Code Signing 4 149
Breakpoint problem 8 83
Open a Text Editor from the Command Line Programatically using C# 3 75
Error E2158 compiling with Delphi XE10 Seattle 2 88
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now