` Comment on an Icetips Article
Icetips - Templates, Tools & Utilities for Clarion Developers

Templates, Tools and Utilities
for Clarion Developers

Add a comment to an Icetips Article

Please add your comments to this article. Please note that you must provide both a name and a valid email address in order for us to publish your comment. Comments are moderated and are not visible until they have been approved. Spam is never approved!

Your Name:  
Email:  
Header text/Subject:  

Please enter your comment in the box below:

Back to article list   Search Articles     Add Comment     Printer friendly     Direct link  

Windows API: Connecting to NET dll from Clarion
2004-04-08 -- Jim Kane
 
Newsgroups: comp.lang.clarion,softvelocity.clarion.language > > no, I do it all the time. I just use com but the interfaces are poorly > > documented so there is a lot of guess work. > > I smell a Cmag article cookin':) Dont know if I'll get arround to that article in this life time so this will have to do. in any case, once the .net code in the GAC the steps are: Steps: 1. Initialize com on computer with .net installed 2. Create a CorRunTimeHost Object and get the ICorRunTimehost interface 3. Call the start method of ICorRunTimeHost to start dot net 4. Call ICorRunTimeHost.GetDefaultDomain to get in Idispatch interface for the app domain 5. call queryinterface on the IDispatch to get an _AppDomain 6. Call _AppDomain.CreateInstance("msCorlib", "System.Collections.ArrayList",lpInterface) where the class and dll is in the gac. The returns an _ObjectHandle interface 7. you call the unwrap method on Object handle to get an interface pointer for the .net class you want to call. 8. lpInterface is an Idispatch interface for System.Collections.Arraylist so you can call an method/property in that class. 9. cleanup 10. uninitializecom The nice thing is none of the code changes except the strings you use in step 6 so it's pretty reusable. Leave it to microsoft to make it that convoluted to be able to call the .net code using classes out of clarion mag is: This is the actual code: DotNetStarted=false stdcom2.initcom(1) ICorRunTimeHost &= stdcom2.getinterface(address(CLSID:CorRuntimeHost), address(IID:ICorRuntimeHost)) If ICorRunTimeHost&=NULL then StdCom2.TakeError('Cannot create an instance of the .NET runtime.','DotNet prj') return end if StdCom2.TakeHR(ICorRunTimeHost.StartIt(),'Start Runtime') then do procret Else DotNetStarted=true. !Message('DotNet is running') if stdcom2.takehr(ICorRunTimeHost.GetDefaultDomain(lpInterface),'GetDefaultDoma in') or ~lpInterface then do procret. Iunk &= (lpInterface) if stdcom2.TakeHR(Iunk.QueryInterface(address(iid:_AppDomain),lpInterface),'QI for appdomain') then Iunk.release();do procret. Iunk.release IAppDomain&=(lpInterface) if StdCom2.ToBstr('mscorlib',lpbstr1) or StdCom2.ToBstr('System.Collections.ArrayList',lpbstr2) then do procret. if StdCom2.takehr(IAppDomain.CreateInstance(lpbstr1,lpbstr2,lpInterface),'Creat eInstance') or ~lpInterface then do procret. StdCom2.strcl.BstrFree(lpbstr1);StdCom2.strcl.BstrFree(lpbstr2) _ObjectHandle&=(lpInterface) if StdCom2.takehr(_ObjectHandle.Unwrap(VarObj),'Unwrap') then do procret. if varobj.vt<>VT_Dispatch then variantclear(address(varobj)) StdCom2.TakeHR('unvalid dispatch pointer','') do procret end lpInterface=VarObj.value


Today is November 21, 2024, 6:34 am
This article has been viewed 35244 times.
Google search has resulted in 466 hits on this article since January 25, 2004.



Back to article list   Search Articles   Add Comment   Printer friendly

Login

User Name:

Password: