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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dreate a dll program or something similar 2

Status
Not open for further replies.

benny7

Programmer
Oct 3, 2004
31
GB
Hi

Using VF 6, I want to write a simple program to search a table for certain contents. This I can do. However I want this program to be used in a different program written in different language. Can I write a dll or anything similar in Foxpro.

Thanks
 
Benny,

Certainly. You need to write a COM DLL. Essentially, this is a VFP class which as been flagged as OLEPUBLIC. You'll find more information about how to do that in the Help.

It's best to put this class in its own project file. When you are ready to build it, click the Build button in the project manager and select the COM Server DLL option. You will end up with a DLL that you can either use immediately or distribute (and register) on your users' systems.

In general, any COM-compliant program can call the methods of your DLL, passing parameters and receiving replies as necessary. It won't matter to the caller which language the original code was in.

I hope this helps. It is just a quick overview. There is more info in the Help.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Hi

thanks for that, I've tried this in the past and get the following error when compiling:

cannot build a dll without ole public classes

I can't seem to find out what I have to do to rectify this.
 
Benny,

If you are writing the class in a PRG, add the keyword OLEPUBLIC to the DEFINE CLASS.

If you are using the visual class designer, go into the Class Info dialogue (on the Class menu) and tick "OLE Public".

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Sorry, I'm going to sound really stupid here. But all I'm doing is opening a table, selecting some data, and creating a text file. I have now forms or anything like that, just dozen or so lines in a program. Do I have to define a classs??? I've never done this before, not too sure what you mean.
 
BENNY7

But all I'm doing is opening a table, selecting some data, and creating a text file.

Yes, but you want this in a dll, so a few extra steps are required.

Take a look at faq184-3381

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Benny,

Yes, you really do need to define a class. That's the only way you can get create a DLL in VFP.

There are two ways to go about it. You can write the class as a program, using DEFINE CLASS. Or you can use the visual class designer (type CREATE CLASS in the Command Window).

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Silly question, is somehting like below correct then:

Dll compiled OK.

Define Class MyClass as Form OLEPUBLIC

Procedure CreateData
LPARAMETERS SEARCHDESC

set safety off
use stock in 0
SELECT STOCK
select * from STOCK into cursor temp where upper(DESCR) like "%" + SEARCHDESC +"%"
COPY TO temp.txt TYPE DELIM
USE IN STOCK

EndDefine

Then in program where dll is being used I've put :

DECLARE INTEGER CreateData IN test.DLL String
a= CreateData("O")
messagebox(str(a))

The a= CreateData("O") creates an error. This is below:

cannot find entry point CreateData in the DLL

Sorry if I sound bit silly, just can't work this out

 

Take a look at thread184-940775 Olaf's comment in regards to creating cursors with a COM.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Benny,

Silly question, is somehting like below correct then:

This is not at all silly. The whole area is quite complicated, and asking these questions is a good way to understand it.

Define Class MyClass as Form OLEPUBLIC

etc. etc.

EndDefine


That part looks completely OK to me (except that you will need to USE the Stock table before you can reference it).


Then in program where dll is being used I've put :

DECLARE INTEGER CreateData IN test.DLL String
a= CreateData("O")
messagebox(str(a))

etc.


No. This is not correct. Because you are specifically creating a COM DLL, you will have to call it like this:

oSearch = CREATEOBJECT("MyProject.MyClass")
&& MyProject.DLL is the name of the DLL
oSearch.CreateData()

Of course, if you want to call it from another language, you can simply translate the above code to the appropriate syntax.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top