c++ simple conditional logging - c++

Disclaimer: I'm not a c++ developer, I can only do basic things. (I understand pointers, just my knowledge is so rusty, I haven't touch c/c++ for about 20 years :) )
The setup: I have an Outlook addin, written in C#/.Net 1.1. It uses a c++ shim to load.
Usually, this works pretty well, and I use in my c# code nlog for logging purposes. But sometimes, the addin fails to load, i.t. it does not hit the managed code at all for me to be able to investigate the problem from the log files.
So, I need to hook some basic logging into the c++ shim - just writing in a file. I need to make it as simple as possible for our users to enable. Actually I would prefer not to ship it by default.
I was thinking about something, which will check if a specific dll is present (the logging dll), and if so, to use it. Otherwise, it will just not log anything. That way, when I have a user with such a problems, I can send him only the logging dll, the user will save it in the runtime directory, and I'll have the file.
I guess this have to be done with some form a factory solution, which returns either a dummy logger, or if the dll is found, a real one.
Another option would be to make some simple logger, and rebuild the shim with or w/o using it, based on directives. This is not the desirable approach, because the shim needs to be signed, and I have to instruct the user to make a backup copy of the "real" one, then restore when done, etc., instead of just saving and deleting a dll.
I'd appreciate any good suggestion how to approach it, together with links or sample code how to go after this.
Cheers

The loading of the logging dll's seams like a complicated way of handling the configuration issue. Why not use the registry. If you use conditional loading on dlls you will be using LoadLibrary and GetProceAddress and as you said your not really a c++ coder so why introduce the complexity. Also there have to be n+1 c++ logging libraries available have you looked into any of those.
Some I found after a Google search
log4cpp
rlog

Why not have a registry key for that? The user opens regedit, adds a key and your library starts logging. The logging code will be in place all the time, just not invoked when the key is absent or set to "no logging".

Related

Why does Oracle recommend using model.setValue() method over setRecordValue() when setting multiple values?

I am using Apex 18.2. According to Apex' JSDoc, Oracle recommends one should use model.setValue() method over setRecordValue() when setting multiple values. But unfortunately, it does not mention the reason behind that. Does anyone know what it is?
I admire your curiosity. It will make you a great developer. :)
To really know the difference, I recommend learning to read the source. While difficult in the beginning, it will get easier with time and become an invaluable skill.
The APEX team makes this quite easy. Open your developer tools and then run the page in debug mode. This will load the unminified JavaScript source files into the DOM rather than the minified versions. Go to the Sources tab and locate the relevant file (it will take time to identify the right file in the beginning, but it gets easier too). You can open the file directly (better for debugging) or go right-click it and open it in another tab (better for scanning).
Then just search the code for the function you're after and read it...
As you can see, calls to setRecordValue, make a call to getRecord before proxying to the model's setValue method anyway. This is just a code path that you can avoid if you're making multiple setRecordValue calls. It's probably a bit of a micro-optimization, but they can add up.

Exe of School project requires admin to run properly

One of the requirements for this project is that it must be able to launch w/out admin. It is a massive project, so I can't really show you the source and a meaningful and helpful way
I've gone to some people for help, and they suggest that I look throughout my project for any times I write files. However, I can't think of anywhere else I still do this, and yet the exe will only run in admin mode. If you try and run it in non-admin mode, it crashes.
I understand that it's difficult to debug if you can't see project, but the project is hundreds of files. Mainly, I'm looking for advice on the kinds of things that would cause a program to crash in not admin mode but run perfectly fine in admin mode
Just as the many people suggested, the issue was opening a file with read/write privileges. Even though we were only reading from the file, we opened the file as an fstream instead of an ifstream.
I missed it because the problem was hiding in some string utils functions that were written by another team member who is no longer with the team. Pretty much no one was using those string functions or was aware they existed.
Thanks for yours guys' suggestions regardless!
For starters, I don't think you can run and install vcredist_x86.exe without admin privileges.
Other than that, in general to not ask for UAC, I think you need to setup the PrivilegesRequired properly.
EDIT: To work-around the need to install vcredist you could use static runtime linking. However, that has some disadvantages as well (for example, memory allocation/deallocation must then be always done in the same memory context, i.e. the same dll/executable - which is always the best policy anyway).

The lazy programmers way to wrapping the vbscript/hta file in a standalone statically linked c++ exe

I have a few vbscript/javascript html applications that I will be distributing online( all for windows only). Just small apps, nothing fancy.
My main experience lies with .net and java.I really want the app to be standalone , requiring no installation, and everything in one file. But not letting my users be able to see the code is important too, which doesnt work with vbscript based hta
While I could spend some time doing it all over in c++ and then statically linking to create an independent and happy .exe file, but I will have to spend considerable time brushing up my c++ skills, which are intermediate-ish.
Can I "cheat" and still write the whole application in vbscript/javascript but do something like this in c++ ( pseudo-code below)
#include headerfiles etc
read the vbscript code stored in a variable perhaps?
create a .hta file, put the code in that and run it in Internet explorer
get window handle for internet explorer ,
disable right click( to hide view source option)
Then compile this c++ file and statically link it and distribute my super cool standalone .exe file.
Is this a naive approach? Does it make sense? Yes I *could*learn c++ but if this does the job, I can keep focus on my .net applications which are my main bread and butter. And I can simply use Html to do my user interface rather than using something like QT. Hiding the source would have been nice but it is not super-essential or a dealbreaker, as the app is not commercial anyway. My point is , is there a serious drawback to this approach?
Thank you :)
You're effectively trying to wrap the VBScript/JavaScript code in a native executable that would output the script to a file and then run it. This wouldn't prevent reverse engineering at all - it would only be a very slight hindrance to someone who wants to see your code.
If you reprogrammed your application in C++ completely, it would be somewhat more difficult to construct the source code that is equivalent to the original. However, hiding the source code completely is not possible: if it can be executed by the processor, it can also be reverse engineered.

To modify start-up behavior of an MFC app

This is my first substantial MFC application.
My out-of-the-wizard MFC app wants to open a blank, new file of the type I specified for my app, when it starts, but that's not meaningful for my application. I want my app to open some connections to some remote sites and get data from them.
Where should I consider interrupting or overriding MFC's default behavior? I could subclass CWinApp::ProcessShellCommand(). I could modify the CCommandLineInfo object it works on. I could excise the whole command line processing and just call my go-get-the-data functions. I probably should just altogether excise the whole document-as-a-file related processing. I'm not opening or saving any files, except debug files or logs that are outside of the UI's concern. The only saving or collecting of local information is via a database, to which and from which I handle the serialization myself, so no CArchive, either.
I've got all this code but it's hanging in front of me disjointed and disintegrated. I'm too new to this and there's too many alternatives. Some simple guidance for a simple beginner is what I'm asking for.
So, if you'll say, sure, lop off the document-as-file handling, tell me, please, where I need to go to do that bit of surgery, I can see it's not just one object that'd be affected. And so forth. Thanks.
You might consider generating a new application, but when you do, tell it that you want a database application without file handling. Even if you don't use its database capability, it'll produce an application whose basic layout is set up roughly for what you're trying to do, so you'll basically just substitute your database interface for what it provides, but won't get involved with trying to rip out file handling and such that's apparently irrelevant for your program.
I found an answer with respect to modifying default file opening. While I made the database app Coffin suggested, I saw the phrase "storing database objects in views" and I rather aimlessly searched MSDN with that. If I was going to try the database app approach and do my own serialization, I had to learn about this.
I thus found an MSDN page concerning handling the file menu in database apps, which discusses how to alter and even disable the OnFileOpen command. It's applicable to OnFile New and it is the approach I was hoping for.

Converting registry access to db calls from MFC Feature Pack

We may start converting an old VS2003 MFC project to use the fancy new features provided by the MFC Feature Pack and VS2008. Several of the new UI controls would be very nice except for one thing - they automatically save their information to the registry. I don't have a problem with the registry, but for the multiple environments the users use out program from, it's much easier to save user data to the database.
So, I'm hoping that there is one main "access the registry" function that could be overloaded to point the database. But brief investigation hasn't turned up anything. Has anyone else had any success doing something similar?
It seems like it should be possible to do what you're suggesting, according to the information on this page in MSDN. I haven't tried this myself, so I don't know how difficult it will be in practice.
According to the documentation, you should create a class that inherits CSettingsStore to read and write the settings, and call CSettingsStoreSP::SetRuntimeClass so that the framework uses your class instead of the default.
The MFC feature pack uses code supplied by BCGSoft and they added this feature (so you can save state to an XML file, database, etc.) way back in 2001. I don't have the feature pack on this PC but try looking for a class called something like CMFCRegistrySP.
I will check myself tomorrow.
Does the StateCollection sample do this?
http://msdn.microsoft.com/en-us/library/bb983406.aspx