how to call a function in dll


chinphooi

Recommended Posts

Hell

I want to 'borrow' a mathematical function or equation compiled into a dll file. I need the equation but have no ideal how to open this dll file. Hence, is it possible to call this dll file inside the Daqfactory to perform the calculation? This dll file takes 7 input variables and calculate to give 1 output variable. That's all I know of.

Thanks a lot.

Toh

Link to comment
Share on other sites

Most likely yes. First you should read the help file on how to load a DLL into DAQFactory. Its in the help towards the end under the "Extending DAQFactory" chapter -> "Calling an external DLL". Review that, and then if you have problems, please post the C header file for the DLL that you want to link. With that we can likely tell you what to do.

Link to comment
Share on other sites

  • 1 month later...

I have read the help chapter. I have try but do not understand the part on the Prototype. Basically, I do not understand how to handle the dll's input/output inside the Prototype. I could need an example to begin with. Lets say my dll file is call "formula.dll". It takes seven variable input "A","B","C","D","E","F","G",and gives one result call "answer". All these are to be declared with double format. How do I put them all into the extern function in Daqfactory? How the code will looks like?

Thanks in advance for your advice.

Link to comment
Share on other sites

This is described in way more detail than I can here in the actual help, so I recommend reading that carefully. There is even some sample code. However, your sample would look something like this if you had a function named func() in your dll that had this C prototype: double func(double a, double b, double c, double e, double f, double g):

extern("formula.dll", "double func(double, double, double, double, double, double, double)","myfunc","stdcall")

you could change the "myfunc" to another name. This is what the function will be called in DAQFactory. The tricky part is making sure you get the prototype exactly right and getting the function call type stdcall correct. It could also be "cdecl".

To then call that function, just call it by the name you assigned:

private a = 0
private b = 0
private c = 0
private d = 0
private e = 0
private f = 0
private g = 0
private answer = myfunc(a,b,c,d,e,f,g)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.