Solved

Call to Windows API GetUserNameA from powerbuilder fails

Posted on 2010-11-23
7
1,352 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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…
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 synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

772 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