Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about accessing a .NET API

Status
Not open for further replies.

grewegreg

IS-IT--Management
Apr 1, 2007
23
0
0
I have been working on a project for sometime (VFP 9, SP1) where I have to create several objects that are in a .NET API. In order to access its methods and events, I need to instantiate an object for that class and then get at least one or two interfaces of that object. At any given moment, I will need to (minimally) have two separate objects instantiated and up to four interfaces.

After instantiating the objects and its interfaces, the computer runs fine. But as soon as I call any method (that returns a result), the processor is pegged at 100%. The code does not give up the CPU Utilization until you exit the application completely. Disconnecting or calling the Interfaces "Dispose" method does not release the CPU, not does storing a .NULL. to the object or releasing the form that instantiated the objects.

I guess I am just curious to see if anyone else has experienced anything similar to this. I have written a quick .NET application with C#, instantiate the objects and interfaces, but I cannot reproduce the CPU utilization problem when the application runs.

I have posted snippets of the code below, if that may help anyone see if I am doing anything badly... Thanks in advance.

Code:
THISFORM.roClass = CREATEOBJECT('namespace.class')
THISFORM.roClassInterFace = GETINTERFACE(THISFORM.roClass,'InterfaceName')
IF ... THEN
   Set Properties
   Call Methods
*!* Processor gets pegged here...
   etc...
ELSE
ENDIF

THISFORM.roClassInterFace.Dispose()
*!* No affect
STORE .NULL. TO THISFORM.roClassInterFace
STORE .NULL. TO THISFORM.roClass
THISFORM.Release()

I have tried creating these objects as public variables, but the same affect.


Greg Grewe
Diamond Consulting, LLC
 
Is there a reason you have to use GetInterface()? Can you simply do a CreateObject() and then just call the methods on the .Net object? Is the .Net object compiled as a COM component?

Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
Craig,

Thanks for the note. I have been unable to create an object directly to the Interface, without creating an object to the class first. I may be failing because of bad syntax too. Yes, the .NET API is a complied COM component.

I have tried the syntax below, with no success. I have the TLB, but have not been able to decipher it create an object to the interface.

Code:
roClass = CREATEOBJECT('namespace.class','Interface')

I have also tried GETOBJECT, but cannot make it work either. I woudl think the above code should have worked...


Greg Grewe
Diamond Consulting, LLC
 
Greg,
Craig meant that you don;t have to GETINTERFACE()
You could:
Code:
THISFORM.roClass = CREATEOBJECT('namespace.class')
IF ... THEN
   THISFORM.roClass. Set Properties
   THISFORM.roClass Call Methods
*!* Processor gets pegged here...
   etc...
ELSE
ENDIF

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Thanks Borislav,

I have tried what you listed here and I am able to set properties, but not call methods or subscribe to events.


Greg Grewe
Diamond Consulting, LLC
 
Hi grewegreg,

Are you sure that the COM-visible assembly has interfaces for the methods and events, or that the methods and events are public and thus exported to the tlb? Also, when registering the COM-visible assembly on the user's machine is the '/codebase' switch being employed?

boyd.gif

SweetPotato Software Website
My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top