cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

DLL in Visual Studio

Newbie

DLL in Visual Studio

hello people!

I've
written a user defined function(.dll function) as a Visual Studio Project, to access at the usb port of my computer in order to aquired image data by reading over the camera at a time rate of x seconds (x could be a variable defined by the user) and stored as a matrix.

The Visual Studio program works but isn't recognized as .dll by Mathcad. I'm not sure what I'm doing wrong, please can somebody give me a hint?

I've attached the Visual Studio project with the .dll archive.

10 REPLIES 10

Re: DLL in Visual Studio

Here's an example that works. It was written by Viacheslav Mezentsev, not me, I just saved it to my archive. Hopefully this will help.

VBNet+Mathcad+test+example.PNG

Bear in mind that Mathcad is not designed for real time applications such as reading from a USB port at regular intervals.

Re: DLL in Visual Studio

Thank you Richard,

I think that program make the calculations from reading a routine implemented in Mathcad.

What I want to do is in the opposite direction: I want to know if it is possible to call a function, previously builded in Visual Studio, from Mathcad and then be able to manipulate the data gathered from that visual Studio function in a mathcad worksheet.

Please, correct me if I misunderstood your post.

Diego.

Highlighted

Re: DLL in Visual Studio

I couldn't edit my original post.

The only thing I want to add to the previously exposed, is that I'm working based on the document "creating a user dll" that states that one can create a mathcad function from an external .dll archive.

I'm just not sure if this kind of function can be implemented in that way.

Re: DLL in Visual Studio

Oops! You are right. That's an example of an automation project, not a user DLL. Sorry!

Re: DLL in Visual Studio

I'm not sure of this thread will help. There is at least some more information

http://communities.ptc.com/message/216285#216285

Re: DLL in Visual Studio

I don't think that this is as simple a problem as it first appears.

Unfortunately Mathcad 'supports Visual C' & the DLL interface that is needed may not translate very easily to any other language.

First you will need the function description structure:

FUNCTIONINFO cmplxsum =

{

"cmplxsum", // Name by which mathcad will recognize the function

"a,b", // cmplxsum will be called as cmplxsum(a,b)

"complex sum of scalars a and b", // description of cmplxsum(a,b)

(LPCFUNCTION)cmplxsumFunction, // pointer to the executible code

COMPLEX_SCALAR,

2, // the return type is also a complex scalar

{ COMPLEX_SCALAR, COMPLEX_SCALAR} // both arguments are complex scalars

};

This is defining the name , parameters , return value(s) & a pointer to the function.

The DLL entry point that mathcad will call (at start-up?) references CreateUserFunction(...)

This will be one of the functions loaded from the mcaduser.lib library.

It takes the information from the FUNCTIONINFO structure & adds it (temporarily) into MathCad's function library.


BOOL WINAPI DllEntryPoint (HANDLE hDLL, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH: // DLL is attaching to the address space of the current process.

if (!_CRT_INIT(hDLL, dwReason, lpReserved))
return FALSE;

CreateUserFunction( hDLL, &cmplxsum );
break;

case DLL_THREAD_ATTACH: // A new thread is being created in the current process.
case DLL_THREAD_DETACH: // A thread is exiting cleanly.
case DLL_PROCESS_DETACH: // The calling process is detaching the DLL from its address space.

if (!_CRT_INIT(hDLL, dwReason, lpReserved))
return FALSE;
break;

}
return TRUE;
}

If they can be translated into Visual Basic & the library function linked then, it may be possible.

I suspect that the easier approach would be to create the entry point in a C wrapper

(Should be relatively straightforward to copy one of the examples & cut out core code)

And then create a link from that into the visual basic program that you have.

(Not so apparent)

If you have any thoughts (or success) please let us know

regards

Andy

Re: DLL in Visual Studio

Diego,

I don't have vs2010 set up to open your vb project, but the short answer is yes, Matchad can do what you ask. However, you need to create a dll interface to whatever funtions you want to call by linking to the Mathcad c library dll. That means creating a dll, as described by andy, that calls whatever language/function you want. In this case, it appears you've created a dll that Mathcad can't call, so the interface dll to Mathcad will also need to be linked to the exported functions in that dll by whatever library you've created. At that point, the c/c++ Mathcad interface code can then call the functions in the vb dll.

If you want Mathcad to respond to external events, that requires a bit more work through the automation interface rather than the userdll interface. That can cause a lot of headaches as Mathcad isn't really designed to work as a slave program for data collection. I'd typically put such a design in a watchdog program and have Mathcad poll the watchdog when it wants new data.

Robert

Re: DLL in Visual Studio

You must understand the difference between managed and unmanaged code. User library is in an unmanaged space, and your code - in managed. Combine them possible, but difficult. Special language created for this: C++/CLI.

Here you can see how it looks: https://smath.info/svn/public/plugins/mcadefi/mcaduser/

I recommend the use of automation, as indicated above. You can use it in VB.Net. To do this, add the Mathcad Automation API to your project and save the image as Mathcad.MatrixValue.

Re: DLL in Visual Studio

Try these examples: .Net User EFI interface