Hi All, The ADSI and Delphi problem has an answer.
The problem: Tried the ADsGetObject (from 'activeds.dll') function on Delphi 4 Pro, Delphi 5 Pro, Delphi 5 Ent Service Pack 1. Any sort of call to this function results in an access violation outside of the project but expected to be handled by the project. The solution: Roll your own GetObject. Below are two examples. One we found, the other was sent to us. Both achieve the same result without any problems. function TAddW2kUser.GetObject1(const Name: string): IDispatch; var Dispatch: IDispatch; begin OleCheck(CoGetObject(PWideString(WideString(Name)), nil, IDispatch, @Dispatch)); Result := Dispatch; end; function TAddW2kUser.GetObject2(const Name: string): IDispatch; var Moniker: IMoniker; Eaten: integer; BindContext: IBindCtx; Dispatch: IDispatch; begin OleCheck(CreateBindCtx(0, BindContext)); OleCheck(MkParseDisplayName(BindContext, PWideChar(WideString(Name)), Eaten, Moniker)); OleCheck(Moniker.BindToObject(BindContext, NIL, IDispatch, Dispatch)); Result := Dispatch; end; Thanks, David. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of David Smith Sent: Tuesday, 13 November 2001 17:53 PM To: Multiple recipients of list delphi Subject: RE: [DUG]: ADSI and Delphi Hi, (Stacy) Thank you very much for the code example. This is the snippet of code that is causing all the problems: procedure TForm1.Button1Click(Sender: TObject); var Container: IADsContainer; begin OleCheck(ADsGetObject('WinNT://bne1-test1', IADsContainer, Container)); {bne1-test1 being the name of the computer to connect to} end; Basically, if it's run in the debugger it results in a never ending loop of access violations. If run outside of the debugger the application just terminates. I think it terminates with a Privileged instruction exception. The application is an executable with a button that runs the code above. I am running Delphi 5 Enterprise 6.18 Service Pack 1, Win2000 SP2. We have tried it on 3 computers (all same config) with all the same result. If there is anyone out there with 2 minutes spare and either the same or different configuration to run the code it would be greatly appreciated. I have attached the adshlp.pas file. You also need to import the Active DS Type Library. The above code will do nothing at all to your computer. Thanks in advance, David. -----Original Message----- From: Stacey Verner [mailto:[EMAIL PROTECTED]] Sent: Tuesday, 13 November 2001 13:24 PM To: '[EMAIL PROTECTED]' Subject: RE: [DUG]: ADSI and Delphi Here is the general unit that we use to do ADSI stuff. Hope it helps. > -----Original Message----- > From: David Smith [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, 13 November 2001 4:18 p.m. > To: Multiple recipients of list delphi > Subject: RE: [DUG]: ADSI and Delphi > > > Hi Stacy, > > Thanks for your response. We're using Delphi 5 and also the > helper routines > you mention. > > Very bizarre error. If we remove some very basic logging > routines the error > goes away, which seems to indicate that it is a timing issue. > Almost 100% > certain it's not the logging code as all it does is write > TStringList log > file to disk. > > Are you doing anything special with _addRef, _release, > coinitialize and > counintialize? Playing with these functions seems to move > the error around. > > Any info would be greatly appreciated. > > Thanks, > David. > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On > Behalf Of Stacey Verner > Sent: Tuesday, 13 November 2001 13:01 PM > To: Multiple recipients of list delphi > Subject: RE: [DUG]: ADSI and Delphi > > > We use ADSI with delphi and don't have the problems you > mentioned. It works > with Delphi 4 and Delphi 6. > We have created a DLL (in Delphi) that is used by Delphi, > Access and VB and > it uses ADSI. > > We use some ADSI helper routines > (http://www.agnisoft.com/adsi/Conf2000/3132.htm) which may help. > > Stacey > > > -----Original Message----- > > From: David Smith [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, 13 November 2001 3:51 p.m. > > To: Multiple recipients of list delphi > > Subject: [DUG]: ADSI and Delphi > > > > > > Hi All, > > > > Has anyone had any experience with using ADSI from Delphi. We are > > successfully creating a user but then a EAccessViolation\EPrivilege > > exception is raised. The exception does not correspond to > > any line of code > > and comes up in the CPU debugger. We have tried all sorts of > > things but > > have had no luck. We are calling the ADSI interface from a > > dll as it's > > going to form part of an install. > > > > Will be quite happy to send over code examples if anyone is > > interested. > > > > Thanks, > > David. --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/