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!

Problem creating an Object from a .NET DLL 2

Status
Not open for further replies.

grewegreg

IS-IT--Management
Apr 1, 2007
23
0
0
I have been given a task of writing an application that interfaces with another application written in .NET. (The version is unknown, but the Framework looks like 1.1) This application has an exposed COM interface (DLL) that I am attempting to access. The DLL has a help document that lists all its Interfaces, Classes, Methods, etc.

I am using VFP9, SP1. I have not been unable to successfully instantiate an object using SET Library or DECLARE DLL.

I have read their documentation, they have not listed any direct reference of how to truly access their classes, except for the code snippet I have listed below. If anyone can help me decipher this (which appears to be a VB6 reference), I would appreciate it. If I can get an object instantiated, I know I can access the rest of the COM classes and methods.

I have listed one class below, with two of its properties, if that might help. Thanks in advance.


Code:
Private sub mMonitorAdd(ByVal r As Info)
Dim Listener as New clsListener
     Listener.GetSettings = r 'OR Listener.WriteSettings r
End Sub


Code:
Public Instance Constructor
Info - Overloaded. Initializes a new instance of the Info class.

Public Instance Properties
IPAddress - Sets / Gets string with IP Address.  
Name - Get / Sets string with name.


Greg Grewe
Diamond Consulting, LLC
 
Can you look the class up in the Object Browser?

pamela
 
Thanks Pamela, but no. When I declare the DLL, it does appear to be registered (DISPLAY STATUS), but the Object and Class Browsers do not see anything. When I try to access the method or properties, I received the "No Entry Point in DLL" message, so I am close, but I just do not have the syntax correct yet.


Greg Grewe
Diamond Consulting, LLC
 
I hate it when I hit "Submit" instead of "Preview".

Anyway, with the Object Browser, I can view the Classes, Methods, etc when I open the "TLB". I have tried

Code:
greg=newobject('Info','Listener.tlb')

but the response is "Class Definition INFO is not found", even though I can see it in the Object Browser. If I try the same with the DLL, the response is "Listener.dll is not a Foxpro exe".


Greg Grewe
Diamond Consulting, LLC
 
Greg,

You said:

When I declare the DLL, it does appear to be registered (DISPLAY STATUS)

I'm a bit confused about whether this is a normal DLL or a COM DLL.

You say you "declare" it (presumably with the VFP DECLARE statement). But you wouldn't do that if it was a COM object. You would need to instantiate it instead (for example, with NEWOBJECT()).

I'm sorry ... I'm sure you know all this.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks Mike,

This is a COM DLL, so it says... I have tried to instantiate it with CREATEOBJECT AND NEWOBJECT. When I try with NEWOBJECT, the response is something like "Class Definition INFO not defined", though when I am in the Object browser, I can see all the classes, interfaces, etc.

The problem, I think, is boiling down to Syntax. I can issue SET LIBRARY TO the TLB, but I cannot to the DLL. Just at a total loss right now what else to try. I can take a screen shot of the Object Browser and post that, if we can attach files to our posting.

Thanks again for any help, have a good Easter.


Greg Grewe
Diamond Consulting, LLC
 
Greg,

You said that you were using this code to instantiate the object:

greg=newobject('Info','Listener.tlb')

I wasn't aware that you can pass a TLB file as the second parameter to NEWOBJECT(). If the class is a properly registered COM server, you only need to pass the class name:

greg=newobject('Info')

Have you tried that?

Also:

I can take a screen shot of the Object Browser and post that, if we can attach files to our posting.

Actually, you can display files in your postings. You put the screen shot on your web server, and then embed a link in your message. But I don't recommend you do that. It's unlikely that the shot of the object browser will reveal any new information, and displaying graphics in that way tends to overwhelm the thread.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks Again Mike,

See if this helps make any sense. When I open the "TLB" in the Object browser, it does show me the Details and the GUID, so I am assuming the COM DLL is registered correctly. Then I do the following;

Code:
SET LIBRARY TO Path+"Listener.tlb'

This appears to work, as a Listener.fxp files is created. Then when I do the following;

Code:
greg=CREATEOBJECT('Info')

I receive the response;


Class Definition INFO is not found.


Does this make any sense to you?


Greg Grewe
Diamond Consulting, LLC
 
There are some basics missing here. A TLB is nothing more than the file that holds information about the COM DLL. You don't need to do anything specific with it in your code.

First, make sure the DLL is registered on your system. Then, once you know the class name, you can use CREATEOBJECT() to instantiate it. You'll need to use something like:

ox = CREATEOBJECT("namespace.classname")

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

I have tried this as well. I manually registered the DLL with RegSvr32 and the response is;

Listener.dll was loaded, but the DllRegisterServer entry point was not found

So this is when I tried to DECLARE the DLL.

I open the TLB in the Object Browser and see all classes, etc. That is why I think this is a Syntax problem. I have tried with NEWOBJECT as well and I keep getting a Class Definition not found error.

Any other ideas are greatly apprecaited!


Greg Grewe
Diamond Consulting, LLC
 
Craig,

You gave me an idea. I searched the Registry for the GUID and the name space is not Listener, it is nsListener. As soon as I used the correct Syntax greg=CREATEOBECT('nsListener.Info'), it instantiated.

Thanks much!


Greg Grewe
Diamond Consulting, LLC
 
Me too. I have been fighting with this for a couple days and was just about ready to give up. Thanks for pointing me in the right direction. Lent is almost over, it must be lack of alcohol...




Greg Grewe
Diamond Consulting, LLC
 
Greg,

Good to see you got it working. This .Net/COM interop stuff is not as straight forward as it could be. Rick Strahl has an article about it on his web site.

Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
the name space is not Listener, it is nsListener

That was where I was going with having you examine it in the Object Browser. The class wasn't listed as 'nsListener' in the Object Browser?

pamela
 
Hi Pamela,

No, in the Object Browser, it is just Listener. but in the Registry, it is nsListener, thus my confusion too!!


Greg Grewe
Diamond Consulting, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top