caliing MATLAB code from C++ (.net)

Greetings,
I have written some code in MATLAB that I have compiled to a dll. My problem 
is that I cannot access that function in C++. I am using the MATLAB engine 
but am gettings linkage errors when I try ot use engOpen, engEvalString and 
engClose. Any help would be sincerely appreciated.
thanks in advance
0
RM (25)
4/17/2006 6:05:22 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
677 Views

Similar Articles

[PageSpeed] 58

I dont know how MATLAB exports a function/class. You should use
depends.exe to see what all is exported in this DLL. Perhaps a MATLAB
related newsgroup would be more beneficial.

---
Ajay

0
ajaykalra (6841)
4/17/2006 6:13:57 PM
Define what you mean.  For example, what error messages do you get?

The most common failure mode under these conditions is caused when C code (e.g., the code
from MATLAB) generates a header file of the form

type functioname(bunch of arguments here);

the problem is that the DLL has the name "functionname", but when you try to call this
from C++, the actual name is
	functionname$%XYZZY
or some such nonsensical name, which generates linker errors.  The problem is something
called "name mangling", which C++ applies to the base name to handle overloading.  You
have to defeat this.  So what you have to do is modify the header file to read

#ifdef __cplusplus
extern "C" {
#endif
	
type functioname(buhch of arguments here);

#ifdef __cplusplus
}
#endif

which tells the C++ compiler to not apply the name mangling to the functions defined in
the scope of the extern "C" definition.  Then you will be able to link to them.

But when reporting errors like this, you actually have to say *PRECISELY* what your
problem is, not use vague and meaningless terms like "I cannot access that function".  The
compiler or linker issued a very specific message, and we need to see that.  Based on my
experience with code-generating programs (similar to, but not, MATLAB), this is an issue
that comes up fairly often, and I'm guessing, in the absence of a useful error report,
that this is what has happened.
					joe

On Mon, 17 Apr 2006 11:05:22 -0700, RM <RM@discussions.microsoft.com> wrote:

>Greetings,
>I have written some code in MATLAB that I have compiled to a dll. My problem 
>is that I cannot access that function in C++. I am using the MATLAB engine 
>but am gettings linkage errors when I try ot use engOpen, engEvalString and 
>engClose. Any help would be sincerely appreciated.
>thanks in advance
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-- 
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
0
newcomer (15974)
4/18/2006 3:28:03 PM
I am getting linkage errors when I try to use MATLAB engine functions like 
engOpen, engEvalString and engClose (error LNK2019)




"Joseph M. Newcomer" wrote:

> Define what you mean.  For example, what error messages do you get?
> 
> The most common failure mode under these conditions is caused when C code (e.g., the code
> from MATLAB) generates a header file of the form
> 
> type functioname(bunch of arguments here);
> 
> the problem is that the DLL has the name "functionname", but when you try to call this
> from C++, the actual name is
> 	functionname$%XYZZY
> or some such nonsensical name, which generates linker errors.  The problem is something
> called "name mangling", which C++ applies to the base name to handle overloading.  You
> have to defeat this.  So what you have to do is modify the header file to read
> 
> #ifdef __cplusplus
> extern "C" {
> #endif
> 	
> type functioname(buhch of arguments here);
> 
> #ifdef __cplusplus
> }
> #endif
> 
> which tells the C++ compiler to not apply the name mangling to the functions defined in
> the scope of the extern "C" definition.  Then you will be able to link to them.
> 
> But when reporting errors like this, you actually have to say *PRECISELY* what your
> problem is, not use vague and meaningless terms like "I cannot access that function".  The
> compiler or linker issued a very specific message, and we need to see that.  Based on my
> experience with code-generating programs (similar to, but not, MATLAB), this is an issue
> that comes up fairly often, and I'm guessing, in the absence of a useful error report,
> that this is what has happened.
> 					joe
> 
> On Mon, 17 Apr 2006 11:05:22 -0700, RM <RM@discussions.microsoft.com> wrote:
> 
> >Greetings,
> >I have written some code in MATLAB that I have compiled to a dll. My problem 
> >is that I cannot access that function in C++. I am using the MATLAB engine 
> >but am gettings linkage errors when I try ot use engOpen, engEvalString and 
> >engClose. Any help would be sincerely appreciated.
> >thanks in advance
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
> -- 
> NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
> 
0
RM (25)
4/18/2006 5:55:02 PM
These appear to be MATLAB specific methods. You need to look into
MATLAB documentation about which MATLAB library to link with. Are you
linking with any MATLAB library? Is it a static or dynamic link?

---
Ajay

0
ajaykalra (6841)
4/18/2006 6:07:42 PM
I wish to thank you and Joseph Newcomer for all your help. I was able to get 
my questions answered by MATLAB technical support.
thanks once again


"Ajay Kalra" wrote:

> These appear to be MATLAB specific methods. You need to look into
> MATLAB documentation about which MATLAB library to link with. Are you
> linking with any MATLAB library? Is it a static or dynamic link?
> 
> ---
> Ajay
> 
> 
0
RM (25)
4/18/2006 6:33:02 PM
Good. I am guessing there must be some MATLAB specific newsgroups as
well.

---
Ajay

0
ajaykalra (6841)
4/18/2006 6:39:25 PM
Reply:

Similar Artilces:

Hide code execution
I am trying to find out a way to hide the procedures a macro goes through. In other words, I want the macro to run without the user seeing the screen flicker and jump from cell to cell. Thanks. Hi Ys, > I want the macro to > run without the user seeing the screen flicker and jump > from cell to cell. > Add Application.ScreenUpdating=False at the beginning and add Application.ScreenUpdating=True at the end of your macro. Regards, Jan Karel Pieterse Excel MVP www.jkp-ads.com Try typing the following at the start of the macro application.screenupdating = false >-...

why does my code loop?
I have the following code that's meant to calculate average times between open and close dates. But for some reason that I can't figure out its looping where I don't expect it to loop. I've added MsgBoxes throughout to try to help but I'm stuck. Does anyone know why this appears to be looping outside of the for loop? Function LagAverage(OpenDates As Range, PNum As Range) As Single MsgBox "starting now" EOPeriod = Sheets("Hub").Range("B8").Value - 1 + PNum * 28 TimeSum = 0 Counter = 0 For Each ODate In ...

Conditional Footer Code
I have a text box (Text586) in the Detail Section that is based upon a dlookup command and shows either a 1 or 0. I would like the text box in the Report Footer (txt589) to be visible if the value count of Text586 >0. This report can be run with different parameters that could show the detail section as one record or 20 records. My code works just only when there is one record in the report. If Me.Text586 > 0 Then Me.Text589.Visible = True Else End If You use DLookup() or DCount() or just count() or something in the report footer. I generally conside...

Help with code #2
What I am trying to do is have a macro lookup cell b1 from sheets21 to sheet120 and when it finds the first sheet that this cell is blank to execute a macro. I used to use the code below but it is way to long over this many sheets. If Sheet21.Range("AV3") = "" Then Sheet21.Select Else If Sheet22.Range("AV3") = "" Then Sheet22.Select Else If Sheet23.Range("AV3") = "" Then Sheet23.Select Else etc. Thanks Greg Greg, You can do the following, although it has a problem that I'll describe: dim s as worksheet for each s in ...

Is there code to toggle "show column headers and row headers"
Normally, to do this manually, it's Tools --> Options ---> 'View tab' and then you click on the appropriate tick-box Can this be done using a macro? Thanks Undoubtedly it can, but this forum is for Word not Excel. -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<&g...

faq mfc use c# code
Hi, I find a very nice control , and it was wraped in the dll use c#. How can I use it in my application based on mfc? Thank you all. fcvcnet wrote: > Hi, > I find a very nice control , and it was wraped in the dll use c#. How can > I use it in my application based on mfc? > Thank you all. You will need to make your application managed along with supporting MFC. That means using CLI if your using VS2005 or MC++ if you are using VS2003. If you are using vc6, you will not be able to consume that control. Essentially you are now converting your unmanged MFC app to a managed...

How can I make this code work?
Hide rows 32:33 if E30 is NO. Hide rows 36:38 if E35 is "NO"...etc. I intend to have about 4 or 5 of these variables. The code I have below is currently not working. code is currently placed in the workbook. Please help! Thanks! Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) Select Case Target.Address Case "$E$30" If Target.Address <> "$E$30" Then Exit Sub Rows.Hidden = False If UCase(Target) = "NO" Then Rows("32:33").Hidden = True Exit Sub Case "$E$35" If Target.Address <> "$...

MultiLine Code Builder, Need Help to Clean Code:
My end goal is to create multi-line code that I can paste into VBE. Currently I'm pasting code like this... If Worksheets("vessel").Cells(CurVesl,8).Value Then Else frmVesselLog.DTPICKER1.value = Worksheets("vessel").Cells(CurVesl,11).Value End IF For example Column D is:If Worksheets("vessel").Cells(CurVesl,8).Value Then Column E is : Else Column F is: frmVesselLog.DTPICKER1.value = Worksheets("vessel").Cells(CurVesl,11).Value Column G: End IF Column H is row1 If Worksheets("vessel").Cells(CurVesl,8).Value Then row2 E...

Code number
When using drop down boxes under the Data:Validation menu, is there a way of having 2 columns; one that has a description and one that has a code number ? So you are prompted by the description but only the code number ends up in the cell You could use a formula that returns the number based on the description chosen. If your descriptions/numbers were in Sheet2!$a$1:$b$99, you could use this formula: =if(a1="","Please select your choice",vlookup(a1,sheet2!$a$1:$b$99,2,false)) Then use that cell with the codes in them in other formulas???? Linda wrote: > > ...

Adding macro code to Personal Macro Workbook
Greetings, I have a .bas file and would like to insert this code directly into my personal macro workbook. However, I can't find a way to DIRECTLY insert the code. The only thing close is to record a dummy macro, then step into that macro and insert the *.bas code that I really want. Can someone tell me of a better way to do this? I'd just open the .bas in notepad and copy|paste to my favorite module. but if you right click on the project (when you're in the VBE), there's an "Import File" option that may work the way you want. mika wrote: > > Gree...

usb host controller error code 43
On my Windows 7 laptop at home, I'm getting usb host controller error code 43. My usb printer works and my usb flash drive works but my external 250gb usb drive does not work. Any ideas on how to fix this? BY the way why is there no newsgroup for Windows 7 at communities.microsoft.com??? "mcp111" <mcp111@discussions.microsoft.com> wrote in message news:6DDF2DC1-3A0A-4C40-9AA4-47CCF9E80154@microsoft.com... > On my Windows 7 laptop at home, I'm getting usb host controller error code > 43. My usb printer works and my usb flash drive works but my exte...

Hiding macro code
I'm sure there's a simple way to do this but I've not been able to find it. I can hide/protect Excel sheets/formulas, etc. but how do you prevent users accessing the VB Editor and seeing your macro code? I don't have digital signatures, etc and I want users to be able to run the macros without hassle, just not visualize the code. Many thanks Seamus McMillan In the VB Editor: Tools/VBAProject Properties/Protection/Lock for editing (and add password) This is NOT secure, by the way. Crackers for these passwords are ten a penny. A more secure way would be to...

VB 6.0 to Access 2000 code conversion
I everybody, i'm trying to convert my Visual Basic 6.0 code, forms, etc. to an Access 2000 database. Is there a automatic converter ? Anyone knows ? Thanks ! Not really. Tony Toews lists some products that purport to be able to do this at http://www.granite.ab.ca/access/accesstovb.htm but the general consensus is that they do an incomplete job at best. There are simply too many differences in the controls available for VB forms vs. those available for Access forms. In general, you're going to be better off recreating the forms manually. (You can, of course, simply copy-and-paste ...

Task Manager Matlab error XP PRO SP3
Hello, I have scheduled some Matlab Jobs on Windows Task Manager. Sometimes this job doesn't start (without return any error) and i have to start them manually. I'm using Windows XP PRO SP3. How can i resolve this error? Thanks in advance Cheers Seiya wrote: > Hello, > > I have scheduled some Matlab Jobs on Windows Task Manager. > Sometimes this job doesn't start (without return any error) and i have to > start them manually. > I'm using Windows XP PRO SP3. > How can i resolve this error? http://www.mathworks.com/support/ ...

Bar Code Readers for POS
A client is interested in bar code readers for use with the Compass point of sale application. They have six registers. They are primarily interested in guns as opposed to wands. Does anybody have experience with bar code readers in a POS environment? Thank you. Charles you can contact www.tstek.com for this. "Charles Allen" wrote: > A client is interested in bar code readers for use with the Compass point of > sale application. They have six registers. They are primarily interested in > guns as opposed to wands. > > Does anybody have experience with bar...

Error code 0x800CCC00F
Occasionally when sending or receiving email, I get a message that displays the following error and says "the server responed '+ok' or '?k'" I looked this issue up on the Knowledge Base and they say that the problem lies with Norton Antivirus 2003. The best solution that either company can come up with, however, is to turn off e-mail virus protection. And here I thought that Microsoft was committed to security. Has anyone dealt with this problem, and if so, have the come up with a less idiotic solution than the one in the knowledge base? ...

code to hide a worksheet?
Can VBA code be written to hide a worksheet? I can't seem to find any help in the help about this... Thank you much, Paula Hi Paula, Yes, you can change the Visible property of the Worksheet object: Worksheets("Sheet1").Visible = xlVeryHidden '/ or Worksheets("Sheet1").Visible = xlHidden xlVeryHidden will hide the sheet so that it may not be unhidden via Format | Sheet from Excel. xlHidden will hide it just as if you had hidden it via Format | Sheet --> Hide. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in t...

forms, tables, codes, and their relations --HELP!
i'm developping a database to help advise students at university and keep track of their progress. in the table, i have each row committed to a particular student, with their requiremens in the columns. each requirement has a drop-down box with codes in it. each code has a particularl meaning. i want to save the codes in the table. the code AB means "not yet completed" (and yes, i do have a table of codes) HOWEVER, on the form associated with this, i also have dropdown boxes, but in them, i want the meaning of the code to appear, but not the code. Here's the p...

COM communicate with managed code(.NET)
Hi! When I have a communication from COM to managed code(.NET) a type library(TLB) is necessary in between to handle the communication from COM to ..NET. I tried to use Red Gats's reflector to look into the type library that have extension tlb but it's not possible. So why is it not possible ? //Tony "Tony Johansson" <johansson.andersson@telia.com> wrote in message news:O%23lutgv5KHA.5464@TK2MSFTNGP05.phx.gbl... > I tried to use Red Gats's reflector to look into the type library that > have extension tlb but it's not possible. ...

Money 02 standard/wages&salary:net not shown in reg income
When preparing my budget in money 2002 standard v10, I entered my monthly income under Regular Income. Since then I've added a sub category under Reg Income (wages and salary: Net) and customized all of my monthly income there. Now money only shows the intitial income amount which is incorrect and says my budget does not balance. How can I edit the regular income to sow the correct amount? ...

Changing case in code
I've added a line of code to the event below that will uppercase the data in the last-edited cell but the update takes a few seconds on my PC (probably longer on the production pc it will eventually run on). Is there a way i can better place the Ucase code? I've tried, unsuccessfully, to move it outside the For/Next loop. I won't pretend to understand the Set statement. Any help would be gratefully appreciated Terry Private Sub Worksheet_Change(ByVal Target As Range) 'David McRitchie, 2000-08-08 rev. 2000-08-14 'http://www.mvps.org/dmcritchie/excel/event.htm ...

matlab and power point
Good morning all! I have created a graph in MATLAB and want to use that as a background for my Powerpoint slides. Could someone please tell me how that is done. Any help wil be sincerely appreciated. Regards This is the wrong group.. why don't you google it? :) "RM" <RM@discussions.microsoft.com> wrote in message news:F5F40F65-E330-4189-BE14-597FE71B07B4@microsoft.com... > Good morning all! > I have created a graph in MATLAB and want to use that as a background for my > Powerpoint slides. Could someone please tell me how that is done. Any help > wil be since...

Reverse C++ to UML
When reversing a C++ project into Visio from Visual Studio 2003, the class diagram has NO associations between classes, except for inheritance. Is this all that I can expect or is there something else I should do to get association links displayed? Associations are not reverse-engineered. Only inheritance and interface realization links are shown. -- -ronnie [MS] This posting is provided "AS IS" with no warranties, and confers no rights. "Nigel Aston" <nwaston@taylor-hobson.com> wrote in message news:08fb01c35b45$f0120650$a501280a@phx.gbl... > When reversin...

Suppress warning when Merging Cells by Code
Hello, While writing in Excel through Code I have also merged the cells. _objRange = _objWorkSheet.Range(_objWorkSheet.Cells(_intCurrentRow, 17), _objWorkSheet.Cells(_intCurrentRow, 18)) _objRange.Merge() _objRange.Value = intTotalTax But, when I merge the cells from code then too a warning is shown to user on UI “Merging Cell will keep only contents of top left cell”. How can I suppress these warnings? This is happening in Excel 2000 (10.0 Object Library) on WindowsXP. Thanks and Regards, Ashish Hi try _objRange = _objWorkSheet...

Simple MFC/C++ development question
I want to develop a simple GUI utiliy using C++/MFC. I mostly develop for Linux using Java/C and I am used to used Sun's JDK and GNU's C compiler running under Linux. My question is where can I get a minimum set tools I need to develop a MFC application. I don't really want an IDE (i.e. VC++6) - what I'm after is a compiler and the header/libraries to link my MFC based utility against. I will use my favourite editor to enter the code. TIA Paul. anonymous@discussions.microsoft.com wrote: > I want to develop a simple GUI utiliy using C++/MFC. > > I mostly d...