?
Solved

Call to Windows API GetUserNameA from powerbuilder fails

Posted on 2010-11-23
7
Medium Priority
?
1,410 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
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!

 
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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. …
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…
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 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…
Suggested Courses

801 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