Solved

Call to Windows API GetUserNameA from powerbuilder fails

Posted on 2010-11-23
7
1,334 Views
Last Modified: 2013-12-26
I am debuggin my application in PB 11.5. I have used windows api GetUserNameA. But during debugging, when it comes to this API, applcation fails.. It s unable to find refrence to this API. How do i get Powerbuilder to identify this API? The declaration is fine. Is there any other thing that I have missed ? I have declared this functions as Global External Function and I am calling this function from Application Open event. Am I missing anything? Pls help.
0
Comment
Question by:adithya
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Expert Comment

by:stanner
ID: 34200405
I just tested it in a small app with global external declaration and a call to it in the application open event.

I have it declared as:
function boolean GetUserNameA(ref string  lpBuffer, ref ulong nSize) library "ADVAPI32.DLL"

Open in new window


You have to initialize the reference variables when calling it. Here is a sample call to it that works:
string	ls_username
ulong	lu_size
boolean	lb_rtn

lu_size = 255
ls_username = Space(255)

lb_rtn = GetUserNameA(ls_username, lu_size)

Messagebox("GetUserNameA", "Username = " + string(ls_username))

Open in new window

0
 
LVL 1

Expert Comment

by:stanner
ID: 34200551
I don't know if this will help any, but when you migrate the declaration you listed from PB9 to PB10.5 or above, you get the following:

public function boolean GetUserNameA(ref string  lpBuffer, ref ulong nSize) library "ADVAPI32.DLL"
     alias for "GetUserNameA;Ansi"

Open in new window

0
 

Author Comment

by:adithya
ID: 34202544
Thanks for your respose stanner...
I had tried with the initializations and with aliasingtoo... but no luck.. I wil try to include the screen shot... Isanythng different in PB 11.5 ? Or, other than the declaration, initiazationof variables and calling the function...Is there anthing lse to be done that I am missig I am wondering....
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Expert Comment

by:kmanoharnaik
ID: 34202995
Hi,

The below code shoud work.

string      ls_username
ulong      lu_size
boolean      lb_rtn

lu_size = 255
ls_username = Space(255)

lb_rtn = GetUserNameA(ls_username, lu_size)

Messagebox("GetUserNameA", "Username = " + string(ls_username))

if it does not work, let me know whats the error you get when you debug.

thanks
msn
 
0
 
LVL 2

Expert Comment

by:kmanoharnaik
ID: 34202997
check the return value of GetUserNameA(ls_username, lu_size)

it should return TRUE
0
 

Author Comment

by:adithya
ID: 34204132
Hi kmanoharnaik,
I am getting Application execution error (R0021) while calling GetUsernameW or GetUsernameA frm PB 11.5
Tried declararing the function as
Public Function boolean GetUsernameW( ref string userID, ref ulong len ) library "ADVAPI32.DLL" Alias for "GetUsernameW"

Then called the function like the one below.

string  ls_temp
ulong   lul_value
boolean lb_rc
lul_value = 255
ls_temp = Space( 255 )
lb_rc = GetUserNameW( ls_temp, lul_value )

I get Application execution error (R0021).  Enclosing the screen shot.
Tried for GetUsernameA as well. The other external functions example GetModuleFileName in Kernel32.dll doesn't give any such errors. Please suggest what could be wrong.
Do we need to have Win SDK installed or something related to SDK? Currently advapi32.dll is in C:\WINDOWS\system32 and My PB source is in E drive. However its able to reference kernel32.dll or shell32.dll. Should  I set the path of dll anywhere? Pls suggest.

error.JPG
0
 
LVL 2

Accepted Solution

by:
kmanoharnaik earned 500 total points
ID: 34204182
Hi,

please find the doc attached.
please clear the variables in watch window and close the debug mode.
now regenerate the application libraries and try once.

this occurs mailny due to reference mismatch..

thanks
msn
debug.doc
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
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.

705 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