Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Call to Windows API GetUserNameA from powerbuilder fails

Posted on 2010-11-23
7
Medium Priority
?
1,432 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
[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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
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.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses

610 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