Solved

GetUserName WinDDK

Posted on 2011-02-18
1
868 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 34

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

733 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