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

Create Dll

Status
Not open for further replies.

lukager

Programmer
Oct 26, 2009
8
IT
I'd like to create a .dll in vfp9 and use it in a program in vb.net.
In my dll i'd like have 2 parameters : location of database and command to run.
example :

c:\db\database.dbc
select * from customers

and i'd like that my dll return the datatable with data.

Is it possible ?
ty
Luca
 
and i'd like that my dll return the datatable with data.

Why not just do :
Code:
select * from customers into dbf c:\mydbf.dbf
And have vb.net pick up the table.

Or make your output XML, and have vb.net pick up the XML.





Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
In this example i'd like to have in .net a datatable and not a dbf or xml to import.


 
Is possible to return the cursor ?

i'd be able to change the command with :

my_Command="select * from customers into cursor My_cursor"

 
I need vfp for other reasons...
I do a program : cmd_dll.prg

DEFINE CLASS MYPRGDLL AS SESSION OLEPUBLIC
PROCEDURE MYFUNC
PARAMETERS wdb,wcmd
open database &wdbd
wreturn=&wcmd
CLOSE DATABASES all
RETURN wreturn
ENDPROC
ENDDEFINE

I build Dll ...
i register it...
I add reference to this in my project in VB.Net 2005.
But when i write :
cmd_dll. ( i see MYPRGDLL )
so i write
cmd_dll.MYPRGDLL.
after don't appare myfunc

What can i control / change ?

If correct use e procedure or it should be a function ?
I try to change it but the problem remain.
TY

 
Make the class name the same as your DLL name.

In other words, call your VFP project MyPrgDLL. Keep the class name as MyPrgDLL. Use the project to build the DLL, which will (by default) be named MyPrgDLL.dll.

Then, in VB, you should be able to see MyPrgDLL.MyFunc.

(By the way, you don't need to register the DLL on your development machine. VFP will do that for you automatically when you build the project.)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
i change the project name and the class name with

cmd_sql

the prg is :

DEFINE CLASS cmd_sql AS SESSION OLEPUBLIC
FUNCTION MY_FUNC
PARAMETERS wdb , wcmd
wopen = "open database " + wdb
&wopen
wreturn=&wcmd
CLOSE DATABASES all
RETURN wreturn
ENDFUNC
ENDDEFINE

and in vb.net 2005 now i have :

Dim wdir As String = "c:\arc\private.dbc"
Dim wcom As String = "select * from anagrafe"

Dim wris As New cmd_sql.cmd_sql()
Dim wobj As Object = wris.MY_FUNC(wdir, wcom)

Now the problem is the the variable wdir ( the database ) don't pass in the class of vfp because i have an a error
"Error in line 4 Operator/operand type mismatch. 107"
where i try to do :
wopen = "open database " + wdb

TY

 
Hmm. At first glance, it looks OK to me.

Wdir is a string. You pass that into Wdb, so that's also a string. You then concatenate that with "OPEN DATABASE ", so that should be OK.

Are you sure it is that line that is causing the problem? Is it possible it's something different that's causing the error?

However, I'm wondering about this line in your VB:

Code:
Dim wobj As Object = wris.MY_FUNC(wdir, wcom)

You are returning wReturn from the DLL, but wReturn isn't an object. I don't know VB very well, but could that be causing the problem?

Another suggestion. In general, it's best to test your classes within VFP before you make them into DLLs. You can do that within the VFP command windows, something like this:

Code:
oSQL = CREATEOBJECT("cmd_sql")
oDir = "c:\arc\private.dbc"
oWcom =  "select * from anagrafe"
? oSQL.MyFunc(oDir, oWcom)

That way, you'll have all the benefit of the VFP development environment to help you find the problem.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Your function won't help you, as you can't access the resulting cursor anayway. And to pass it back to .net you'
ll end up converting it to XML for example anyway. So why not go the normal route and use OLEDB Provider to access foxpro data in .NET?

Besides using the DDEX Provider for VS2005 is an alternative:
Bye, Olaf.
 

I changed a little things...
The variable/parameter wdb ( in my opinion )
was the problem ... perhaps was empty...
so i changed :

func MY_FUNC ( wdb , wcmd )

and now i can open the db and excexute the select.

Now i'd like that the results of the select
will be returned in vb.net.

how can i do ?

TY
Luca

 
Luca,

To return the results of your query, you first need to create a cursor within the VFP function. To do that, add "INTO CURSOR " plus a cursor name to your query:

Code:
Dim wcom As String = 
"select * from anagrafe INTO CURSOR MyCursor"
]

Then, in the VFP function, convert the cursor to an XML string, which you then return:

Code:
CURSORTOXML("MyCursor", "MyXML")
RETURN MyXML

However, I have to agree with Olaf and Craig. This is not the best way to go about it. It's much easier to use OLE DB to perform the query directly. That way, you won't need any VFP code.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Yes,

you can't return a cursor. It's bound to the foxpro runtime. More general in COM you can only return simple types like int, string or objects. But a foxpro cursor is no object. The cursor's alias is a string, but that cursor alias only helps adressing a cursor inside foxpro.

What you can do despite of returning XML of the cursor data is a) define your own string based format, you might even return a CSV string of the data. Or process the data within the COM serer to have the net result you really want, eg a snippet of an html string as part of your overall html generation.

Regaring passing back objects from a COM server to .net (or any other com capable programming language) you can convert to an adodb.recordset, pass that on and then convert that to a .net dataset. But that's not the way to go.

Bye, Olaf.
 
Ok thank you.
I pass a XML and all it is ok.
The last one question ( i hope ) ..
if i register the dll on my pc ( where i have also installed vfp9 ) it's ok.
If i try to register the .dll on another pc i have an arror 0x8004005.
what can i control on the other pc ?
Ty

 
yes.. i'm trying to register with REGSVR32 :-(
and that is the error.
 
VFP EXEs and DLLs are not standalone, in fact no DLL is standalone but needs a runtime. It's just many runtimes like eg the C runtime are available everywhere allready.

Depending if you create a Multi-threaded (MTDLL) or a Single-threaded (STDLL) COM Server DLL you need several runtime files.

See here:

Provide vfp9r.dll for STDLLs and vfp9t.dll for MTDLLs and in both cases: msvcr71.dll and vfp9renu.dll plus any additional resource DLLs for other languages/codepages.

Also in your case, as you do CursorToXML the XML dlls msxml3.dll, msxml3r.dll and msxml3a.dll or redistribute MSXML3 with this redistributable:

Use msxml3msms.exe to download the redistributable merge modules (*.msm) to distribute with your application setup.

Especially if you decide to create a setup aith COM registration the msm module is the best choice in my oppinion.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top