Path: news.cs.au.dk!not-for-mail From: "Sascha Kimmel" Newsgroups: comp.lang.beta Subject: RE: MB_YESNOCANCEL, MB_YESNO, MB_RETRYCANCEL ... Date: 1 Mar 1999 22:56:05 -0000 Organization: University of Aarhus, Department of Computer Science (DAIMI) Lines: 89 Approved: mailtonews@cs.au.dk Distribution: world Message-ID: <19990301225605.8751.qmail@noatun.mjolner.dk> Reply-To: "Sascha Kimmel" NNTP-Posting-Host: daimi.cs.au.dk X-Trace: xinwen.cs.au.dk 920328980 23903 255.255.255.255 (1 Mar 1999 22:56:20 GMT) X-Complaints-To: news@cs.au.dk NNTP-Posting-Date: 1 Mar 1999 22:56:20 GMT Xref: news.cs.au.dk comp.lang.beta:11854 > -----Ursprüngliche Nachricht----- > Von: Morten Grouleff [mailto:mg@mjolner.dk] > Gesendet am: Montag, 1. März 1999 13:19 > An: usergroup@mjolner.dk > Betreff: Re: MB_YESNOCANCEL, MB_YESNO, MB_RETRYCANCEL ... > > "Sascha Kimmel" writes: > > [...] > > > And could someone please explain how to implement certain > WINAPI functions > > like the following one in BETA? > > > > BOOL GetUserName( > > LPTSTR lpBuffer, // address of name buffer > > LPDWORD nSize // address of size of name buffer > > ); > > win32lib/winbase.bet: > > (* BOOL WINAPI GetUserNameA (LPSTR lpBuffer,LPDWORD nSize ); *) > GetUserName: external > (# name: @integer; > length: @integer; > result: @boolean; > enter (name, length) > do 'GetUserNameA' -> callStd; > exit result > #); > > > My problem is that I don't know how to get the address of a variable. > > Adresses and addresses.. well, yes, it's C :) > > You really should not get the address of an attribbute of a BETA object, > as it may be changes by the garbage collector. > > But there are other ways...: > > ORIGIN '~beta/basiclib/betaenv'; > INCLUDE '~beta/sysutils/cstring'; > INCLUDE '~beta/win32lib/winbase'; > --PROGRAM: descriptor-- > (# cs: @CString; > lgt, result: @Integer; > do 256->lgt; > lgt->cs.init; > (cs, @@lgt)->GetUserName->result; > (if result<>0 then > cs.get->screen.putLine; > if); > cs.free; > #) > > Here, CString is used to store the string. @@lgt is the address of the > integer lgt. Note that this code is safe, but only because the address > is only used in a call of an external function. Using @@lgt in any > other way leads to unpredictable errors. This is not a supported part > of the implementation and may change without notice. It's a comparison between an integer and a boolean value, I see. The compiler gives out a warning telling this. Thank you for your help. For someone who needs it (needed for eMail-programs!), here is the code to get the computer name. INCLUDE and ORIGIN are the same as above, but don't forget to put "v1.6" there. (* BOOL WINAPI GetComputerNameA (LPSTR lpBuffer, LPDWORD nSize ); *) GetComputerNameA: (# cs: @CString; t:^text; lgt, result: @Integer; do 256->lgt; &text[]->t[]; lgt->cs.init; (cs, @@lgt)->GetComputerName->result; (if result<>0 then cs.get->t[]; if); cs.free; exit t[] #); Regards, S. Kimmel