VC++ DLL (Non MFC): What are the different reliable ways to log information - visual-c++

I am working on a VC++ DLL that uses SWIG (Simplified Wrapper and Interface Generator) for C#. The DLL does not use ATL or MFC, it is set to use only the Standard Windows Libraries. Now because of some memory issues, I want to output formatted messages from functions to a log file. What are the different way to do that? Is there a pre-existing trace class that I can use?

I know just 3 different ways to do it:
Use one of the existing log libraries for C++. This is the most flexible approach since you can profit from many nice features like formatting, different appenders etc
Use OutputDebugString function. This function sends message to the debugger, but does not put it to any file by default.
Implement your own simple logger
I hope this helps.

Related

VB.Net FileSystem.Rename on non-Windows platforms

When using the FileSystem.Rename function in VB.Net Core, warning CA1416 pops up, saying this function is only supported on Windows. However, none of my research has gleaned what alternative there is for other OSes.
I was wondering what a workaround that works on all platforms might look like.
You shouldn't be using VB6 holdovers like that in the first place, whether on Windows or not, .NET Core or .NET Framework. Pretty much any function that is a member of a module in the Microsoft.VisualBasic namespace should be avoided unless it provides specific value over the alternative(s).
At the very least, if you're going to use something VB-specific then use My.Computer.FileSystem.RenameFile. Even that may be Windows-specific though, because I think that it uses the Windows shell.
If you stick to straight-up, standard .NET stuff then you'd be using the System.IO namespace and, in this case, File.Move.

Combining c++ and c# projects in Visual Studio express 2012 for Windows desktop (windows 7)

Been using VS2010 express. Writing in C# which i figured was a good middle step towards object oriented languages. One thing that has made my code somewhat repetitive is the inability to use multiple class inheritance in C#. I.e. I can't say class A inherits from class B and class C.
c# is great because you can quickly and easily get windows with buttons textboxes and dials up and running. This is not available in C++ in the express version since the MFC libraries are not included.
Now, I have thought of just desinging a C# front end which saves parameters to a file then execute a c++ which reads the file, runs and then saves a file which i open with another(or the same) c# backend exec to read and play ard with the results. But this would make it cumbersome always executing the whole sequence again if you want to change something. Not to mention debugging, will probably need to have to instances running.
Reading on of the Visual studio 2012 Express for desktop announcment, it stated that "You can also combine C++, C#, and Visual Basic projects into a single solution, making it easy to write a single application using any of the available languages." http://blogs.msdn.com/b/visualstudio/archive/2012/09/12/visual-studio-express-2012-for-windows-desktop-is-here.aspx?PageIndex=3
Now I would be happy with that, after all I dont expect and dont need at this stage to do any wizbank stuff i.e special button functionality/design which is easier and provided with the MFC in C++.
My question is: Has anyone tried this in Visual Studio 2012 in the Express for windows desktop version in Windows 7''? I.e can you combine a c++ and a c# projects which interact, trace the code form one project to another when debugging for example? Are there any special restrictions? I mean if its combining executables only its not much use, but i expect its more than that, but how much more? For example, can an object designed in C# instanciate an object designed in c++ pass it a reference to other objects like classes which hold inputs and outputs or data which are proccessed in the c++ class and still accesible in the c# code to display results etc?
I am asking this before downloading the new express version because I expect it will set me back a couple of months since going from C# to C++ i would think is like going from Visual Basic to C. I wouldnt want to get into all the trouble (i dont mind really but it would be huge step back) to find out i cant "seemlesly" integrate a c# front end with a C++ proccesing solution.
You have three options for interfacing C++ with C#:
pinvoke: You specify function signatures in C# and give them an attribute specifying what DLL they reside in. This is fairly painful to do if you need to pass around any complex types at all.
COM: A C++ DLL would implement a COM object called by the C# code.
C++/CLI: Allows mixing of managed and unmanaged C++ code in a single C++ project. It is very nice for interfacing with other libraries but, in VS 2010 at least, lacks helpful features such as intellisense. If you really wanted to go this route, I would write three projects: Your core C++ code as a static library, your C++/CLI DLL to wrap it, and your C# application.

Wrapper for converting Winapi and MFC code to equivalent linux versions

I'm working on a wrapper to compile c++ code having MFC and windows API calls into their linux versions.
The c++ code has the following characteristics:
No GUI component present.
Has a maximum of about 10 MFC classes used mostly for string parsing.
It has lots of windows specific constants used such as HINSTANCE, LPCTSTR and so on.
I'm not allowed to compile using wine in linux. Till now i've come across wxwidgets, it seems quite vast, i doubt if i'll be needing all it's components.
Please share your ideas in creating the wrapper, is there any specific code that is already available which does this task or part of this task ?
There is no automatic or even semi-automatic way to convert an MFC application to wxWidgets. It is, of course, perfectly possible to do it and many, many projects have gone through this transformation but you just need to do it.
See MFC page of wxWiki for some starting points.

How to call a method in a jar file from Visual C++?

In my project i have a requirement to call methods in a Jar file using VC++. Is there any way to call the methods inside the jar file from VC++. If sample code is there then it will help a lot.
Thanks in Advance!
Arun
IKVM.Net ( http://www.ikvm.net ) is a .Net implementation of the Java libraries, which is not really what you want, but it includes a command-line tool called ikvmc (see http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=Ikvmc) which will translate the java byte-code to .Net IL code, and produces a .Net assembly DLL. I've used this successfully to translate a Java library to an assembly that I then included in a C# project.
If you are using C++ as your target language then you must use JNI ( http://java.sun.com/docs/books/jni/). JNI defines an interface to exchange data and call methods from/to Java and native code. It is pretty straightforward to write a JNI wrapper to a class that contains methods returning and taking in input simple parameters ( that is native types, no collection , no arrays). When methods involves classes, collections, arrays and so on it can become quickly cumbersome to write the JNI wrapper by hand. This article provides a good overview: http://java.sys-con.com/node/45840. In this case you may evaluate a wrapper generator such as GIWS: http://www.scilab.org/products/other/giws.
If you are using the .NET environment as your target platform then IKVM is one option. However when we had to do this for a real project we preferred JNBridge and we had been quite successful with this (commercial) tool. We didn't evaluate IKVM for a business reason: our customer wanted only officially supported middleware.

VC++ merge multiple COM DLLs into one

Let's say we have multiple libraries (DLLs) whose features one wants to use in an application, and wants to use them as a single DLL.
Is it possible to merge the DLLs into a single one, with all the features packed into it? I am not looking at the option to write a wrapper.
EDIT:
I've revisited the problem. Now all I want to do is bring all the projects under one solution and get a single DLL as the output instead of each project having it's independant output. Is this possible?
You can't literally merge several compiled .dll files into one. Your best bet is to put all files into a single project and recompile as a single library. You will likely have conflicts you'll have to resolve manually.
If you really have several COM in-proc servers you will also have to merge the data that facilitates class factories and COM registration - you will have to do that manually.

Resources