Generating DLL out of Simulink model - visual-studio

I'd be interested in knowing if any of you has direct experience in porting Simulink models into working DLL (Dynamic Linking Library).
I am aware of this document:
From Simulink to DLL
but it is a rather outdated documentation. Perhaps there exist faster ways to accomplish this task successfully.
EDIT
As far as I understood, I just proceed this way:
Derive a custom TLC from the grt.tlc file using the "Custom Target" example in the RTW Embedded Coder documentation, which does NOT require RTWEC, only RTW.
Derive a custom TMF from the grt_vc.tmf file.
Finally derive a C file.
Does it make sense or not?

If you have Embedded Coder, you can use the ert_shrlib.tlc target, see for example How can I create a DLL target for RTW so I can create a DLL from my Simulink model that can be called from other C/Fortran programs?.
Failing that, you'll have to manually create the DLL from the generated C code using Visual Studio or other IDE.

Related

VS 2010 C++ creating library

I would like to develop a game. Now i just want to make the engine. Im considering using SFML and C++ to do this, but this question is not about it.
I want to separate game from engine.
So at first, I made solution with C++ project into it. So far so good.
Then i added new project to this solution. HERE my question begins.
What settings do i need to change in engine project, so it compiles as library ? (.dll i guess ?)
And what settings do i need to change in game project (.exe) so i can access classes from engine library ?
School didn't taught me, how to do this. In C# its easy.
If you are using MFC then ,you need to create a DLL for your game engine by using the Wizard Vc++->MFC->MFC DLL.
if it is win32 dll or simply a c++ dll you need to create win32 project. Please read the following posts to understand each one of it
http://www.codeproject.com/Articles/6351/Regular-DLL-Tutor-For-Beginners
http://www.codeproject.com/Articles/2516/Creating-and-consuming-MFC-DLLs-for-Beginners
http://www.codeproject.com/Articles/8341/DLLs-are-simple-Part-2
http://www.codeproject.com/Articles/8417/DLLs-are-Simple-Part-3

OpenCV Deploying a partial project as static or dynamic library or something else?

I'm fairly new to OpenCV and Visual Studio as well. My question is not so much technical but theoretically anyways:
I'm working on a bigger project but do not have access to all its subcomponents etc. I wrote a few classes and functions that other members want to use. However, I'm using some OpenCV specific things (because I'm lazy and dont want to implement everything all by myself) but the other members dont use it and they want to keep the project size relatively small.
My question is: How can I provide my code as a library or something similar that includes all my opencv dependencies? Can I create a dll of my code and just ship the opencv dlls with it? Is there a way to bundle everything into one file with only one header?
How would you solve this problem?
Summarizing: I want my functions in a library and shipped as small as possible (with opencv dependencies)
KR
Put all your code in a DLL, and then ship OpenCV DLLs along with yours.
Or: put all your code in a DLL, and perform static linking with OpenCV.

How to use Windows Forms in a C/C++ application?

I have an existing project created using C/C++ under a development environment.
Currently we want to facelift the existing form using a Window Forms application but the problem is the existing project is using Common Runtime Library = No /CLR and Runtime Library = /MTd.
But the a Windows Forms application is using Common Runtime Library = /CLR and Runtime Library = /MDd.
Please advise if it possible to use a Windows Forms application to create a form in the existing project?
Is there any tutorial regarding this?
The comment from MSDN was:-
Caution Do not mix static and
dynamic versions of the run-time
libraries. Having more than one copy
of the run-time libraries in a process
can cause problems, because static
data in one copy is not shared with
the other copy. The linker prevents
you from linking with both static and
dynamic versions within one .exe file,
but you can still end up with two (or
more) copies of the run-time
libraries. For example, a dynamic-link
library linked with the static
(non-DLL) versions of the run-time
libraries can cause problems when used
with an .exe file that was linked with
the dynamic (DLL) version of the
run-time libraries. (You should also
avoid mixing the debug and non-debug
versions of the libraries in one
process.)
http://msdn.microsoft.com/en-us/library/2kzt1wy3(VS.71).aspx..
The simple answer is no. A more accurate answer is kind of, but you probably wouldn't want to.
It is possible to use Windows Forms (i.e. managed code) for your user interface and something else (e.g. non .NET/unmanaged code) for your domain logic. However I'd guess that if you're asking this question then that is going to be a bit much for you to do at the moment.
I suggest that you create a user interface with Windows Forms and then have that user interface call a native C/C++ DLL. Google for PInvoke on how to call an unmanaged dll (C/C++) from managed (.NET) code.
If you did that then you would be much better positioned to answer this question.
My company software often has to have modules which mix managed and unmanaged code and user interfaces. What we do is to separate the modules into their own executables and expose the functionality as COM localserver objects. This way, the unmanaged code can have a user interface written in managed code.
However, you need to do alot of plumbing to get it to work. We do it this way because our applications have been deployed in the field for years and it will take years to give the entire program a makeover into .NET

setup mfc project

A word or two about project I have to make.
I have a list of products (XML formatted), and I have to make a bar code of that list.
Here are the requirements:
Technology has to be MFC, VS 2005 or VS2008
All functionality must be in one dll
Same solution should have a simple tester for the dll
I will use pdf417. http://en.wikipedia.org/wiki/PDF417 http://sourceforge.net/projects/pdf417lib/
Also, I would like to provide an interface, so that different bar codes can be implemented in future.
For example, my dll has "Write" method which is implemented in a separate file for pdf417 and in a separate file for some other bar code, so that user can choose which bar code to use.
Since I have no knowledge of mfc, I really don't know how to even start. I read some tutorials, created the dll with some dummy method, and then tried to use it in tester application, but no luck.
I know that this is a "needle in a haystack" type of a question, but if someone could help me how to setup/architect this project I would be very grateful.
Thanks,
Marko
I don't see how you benefit from using MFC if your DLL's client is not an MFC app. You are better off using a standard C interface in your exported functions if you want to support non-MFC clients. Just create a Win32 project and choose the project type as DLL, then the wizard will generate some example exported function for you. Follow the examples to create your own export functions.

Strange VB6 build problems (related to nlog)

This I think is related to my use of the nlog C++ API (and my question on the nlog forum is here); the purpose of my asking this question here is to get a wider audience to my problem and perhaps to also get some more general ideas behind the VB6 IDE's failure to build in my particular scenario.
Briefly, the problem that I am having is that I am having trouble building VB6 components which reference unmanaged C++ components which have calls to nlog's C\C++ API (which is defined in NLogC.DLL). The build problems are not occurring during compile time, they are occurring when the binary is being built which suggests to me that it's some kind of linker type problem? Don't know enough about how VB6 binaries are produced to tell. The VB6 binary is produced, but it is corrupted and crashes shortly after it is invoked.
Has anyone had any similar experiences with VB6 (doesn't have to be related to nlog or C++)?
edit: Thanks for all the responses to this rather obscure problem. Still no headway unfortunately; my findings since I posted this:
'Tweaking' the compile options doesn't appear to help in this problem.
Adding a reference to the nlog-enabled C++ component from a 'blank' VB6 project doesn't crash it or cause weird build problems. So it isn't a 'native' VB6 issue, possibly an issue with the interaction between nlog and the various components and 3rd party libraries used by other referenced components?
As for C++ calling conventions: the nlog-enabled C++ component is - as far as I can see - compliant to these conventions and indeed works fine when referenced by VB6 as long as it is not making any nlog API calls. Not sure if the nlogc.DLL itself is VB6 compliant but I would have thought that that is immaterial since the API calls are being made from the C++ component; VB6 shouldn't know or care about what the C++ component is referencing (that's as far as my understanding on this goes...)
edit2: I should also note that the error message obtained during build is: "Errors during load. Please refer to "xxx" for details". When I bring up the log file, all that there is in there is: "Cannot load control xxx". Interestingly, all references to that particular control disappears from that particular project resulting in compile errors if I were to try to build again.
Got around the problem by using NLog's COM interface (NLog.ComInterop.DLL) from my unmanaged C++ code. Not as easy to do as the C\C++ API but at least it doesn't crash my VB6 components.
I would try tweaking some of the Compile options found in the Project, Properties menu, Compile panel to see if they yield any additional hints as to what is going wrong.
For example if you compile the executable to p-code rather than native code does it still crash on startup.
What error message do you get when you run your compiled binary?
I doubt the compiler/linker is the problem: project references in a VB6 project are not linked into the final executable. A project reference in VB6 is actually a reference to a COM type library (which may or may not be embedded in a .dll or other binary file type). Project references primarily serve two purposes:
The IDE extracts type information from the referenced type libraries which it then displays in the Object Browser (and in the Intellisense drop-down)
At compile-time, the compiler extracts the type information stored in the referenced libraries, including the CLSID of each class that you instantiate, and embeds this data into the executable. This allows your executable to create instances of classes contained in the libraries that you referenced.
Note that the compiled binary doesn't link to any code in the referenced libraries, and it doesn't even contain the filenames of the referenced libraries. The final executable only contains the CLSID's and other type information that it needs to instantiate COM objects at run-time.
It is much more likely that the issue is with NLog, or with how you are calling it from your code, rather than something gone awry in the VB6 compile process.
If you think it might be a linker problem, this should crash it the same way:
create a new standard project (of any kind)
add a new module and copy the "declare"-statements into it
compile
If it doesn't crash it is something else.
It would help an exact description of the error or a screenshot of what going on.
One thing to check is wherever NLogC.DLL or the C++ DLL you built have the correct calling convention defined. Basically you can't have the DLL function names mangled or use anything but the STDCALL calling convention. If the C++ DLL has not been created with those two things in mind then it will fail to work with VB6.
MSDN Article on Calling convention.
"Cannot load control xxx" errors can be caused by .oca files which were created from a different version of an .ocx than currently used. If that is the case, deleting the .oca files helps.

Resources