Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
I

imagiro

@imagiro
About
Posts
37
Topics
10
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Of Code and Comments
    I imagiro

    We had lots of discussion about this at work too, about how extensively code should be commented, and if at all. First there is a difference between commenting and documenting code. The latter you probably need to do anyway, at least for public APIs. Besides that, imho some visual indicator on top of each function / class etc makes it easier to navigate through code. So a short block on top of each function can act as kind of a separator (like headlines in normal texts), that allows to quickly see where a function starts. So (meanwhile) I add at least a single line with dashes on top of each function, and find that quite useful. As for comments, I agree with those people, who say code should be written in a way that comments are not necessary. Means: Use names that say what it is about rather than comments, split complicated constructs into multiple steps, even if it appears less "cool" (functional programming!) etc. However, there are cases, where comments are a good idea. Not just to explain some parts of the code that are hard to understand, but also to indicate that something might look like a bug or a wired construct, but is actually intended. Like this JS:

    const a = parseInt(someString, 10);
    if (!(a > 0))...

    One might think "Wtf? Why not if (a <= 0)...?", and forget, that the former also takes care of NaN. So my personal guideline: - Write code that doesn't need comments. - Comment to avoid misunderstandings. - Document your code.

    Work Issues question discussion career

  • Not Even Going To Try To Catch Up
    I imagiro

    My deepest sympathies. I lived in Stuttgart for 12 years. If one day hell freezes over, I imagine it to be like Stuttgart in the winter without a car.

    The Lounge csharp com question

  • Let the user know you care - say something nice
    I imagiro

    ...
    catch(e) {
    console.warn(e);
    const niceMessage = 'An error occurred';
    throw new Error(niceMessage);
    };

    The Weird and The Wonderful help

  • Early candidate for most useless comment of 2016 (with optional useless variable name award)
    I imagiro

    He/she forgot to mention that this is about setting the baudrate.

    The Weird and The Wonderful

  • Wtf JS?
    I imagiro

    That's probably part of the reason why Allman style is not very popular in JS. And I agree: The optional semicolon is just terrible.

    The Weird and The Wonderful javascript help java sales tools

  • Bug of the Day
    I imagiro

    Looks like the Y2K bug will still haunt us for at least the next 00 years...

    The Lounge database debugging json help

  • 2 o'clock and all's well
    I imagiro

    These things are not meant to be read, it's just ergotherapy for people who don't have a real job.

    The Soapbox sales question

  • What position is the letter A? Let's use a lookup table!
    I imagiro

    ... the map is static...

    The Weird and The Wonderful ruby question

  • What would you do?
    I imagiro

    My advice: - Document everything properly: Your actions, the (missing) actions of your directors etc, so no one can pi** your leg. - Keep doing your job: Invesigate, report, and make sure it reaches the directors - When it comes to "why did this or that fail?" and they ask you - say thing like "As I already said in my report from ..." - See if you find a new job And maybe I can comfort you a bit: You are not alone. This situation is quite usual.

    The Soapbox javascript database sysadmin business collaboration

  • PQOTD
    I imagiro

    Eddy Vluggen wrote:

    Duncan Edwards Jones wrote:

    4. In chess, how many squares is the most any piece can travel in one move?

    That'd be the length of the entire board. 8 fields.

    The length is 8 fields, right - but the piece occupies already one, so 7.

    The Lounge question regex

  • Over-documentation
    I imagiro

    Probably he had a boss who complained about insufficient comments - like my boss often does when reviewing my code complains about missing annotations (just review annotations, the code was already commented properly). So I did more or less the same like our guy here - and my boss was happy. He didn't get that it was supposed to be ironic...

    The Weird and The Wonderful performance

  • I, Moron
    I imagiro

    Well, for me the case is clear: This class translates insults from german to english.. Well, only one, but hey! You can always add some derived classes! :)

    The Weird and The Wonderful ruby

  • When things to more than you think
    I imagiro

    I just spent nearly two days debugging an COM exe server using ATL and boost. There is a boost thread, acting as an asynchronous task manager that gets task queued which do callbacks into COM objects (into JScript objects). The thread was hanging in join(), even though a breakpoint set at the end of the thread function was hit. The code was written by a collegue, who is a god with boost, but rather new to ATL - and he hates it. Me in turn did not use a lot of boost (yet), but with COM/ATL I have quite some experience, and I like it. So first I suspected boost to be somehow buggy, although I could not really imagine that such a widely used thing like boost::thread would have such a serious bug or a somehow screwed functionality. Here is (shortened) how the thread looks:

    void operator()()
    {
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    BOOST_SCOPE_EXIT_ALL(&) { CoUninitialize(); };
    try {
    // lots of code here...
    // e.g. running a task from a task queue calling back into javascript
    // and creating a few js-objects...
    // and more...
    // and more...
    } catch (boost::thread_interrupted &) {
    ATLTRACE(L"Thread interrupted\n");
    }
    }

    As I said: A breakpoint set at the last closing curly brace got hit, but the join() call from the main thread that triggered the thread interruption never finished. After a while (quite a while!) of playing around, debugging (a release version btw, since the problem happened only in a release build) and staring at the code I noticed the neat little line near the top of the thread:

    BOOST_SCOPE_EXIT_ALL(&) { CoUninitialize(); };

    "Wait a sec! What's that?" "BOOST_SCOPE_EXIT_ALL - Maybe this means, it executes some code when the current scope exits? Maybe CoUninitialize()?. And doesn't CoUninitialize() block, when the current thread still holds some COM object references?" So I started to dig into the code of the actual tasks that were executed here, and one of them in deed creates some objects. But since my colleague learned COM from me and I slap his fingers everytime I see a raw pointer somewhere, and also from what I found in the code there should not be a problem. The object was created nicely via

    CComPtr<IDispatch> createJSObjectInstance()
    {
    CComPtr<IDispatchEx> creatorObject = threadMarshaller->get();
    DISPPARAMS params = {0};
    _variant_t result;

    The Weird and The Wonderful javascript help announcement c++ com

  • COM Apartment
    I imagiro

    First of all an apartment is an abstract concept, means, there is no physical thing behind. When a thread starts it decides in which apartment it wants to "live". It does so by calling CoInitialize or CoInitializeEx. An apartment is a kind of a convention how to handle things. A thread that initializes a single-threaded apartment states, that it does not allow any other threads to enter the same apartment. COM knows then, that all objects living in this apartment can be accessed only from this same thread and makes sure that these objects are used only from within this thread. A thread that initializes a multi-threaded apartment allows other threads. COM knows then, that multiple threads might access the objects in this apartment and relies on these objects to handle thread synchronization by themselfs. So how do other threads enter the same apartment? Simply also via CoInitializeEx. By requesting a multi-threaded apartment they will automatically resist in the same apartment as the other MTA threads since there can only be one MTA. So in the end each thread that initializes a STA creates its own apartment, while threads initializing MTA enter the one and only MTA. And the same is of course valid for all COM objects created from this thread.

    ATL / WTL / STL com question

  • COM or DCOM?
    I imagiro

    You can use COM objects if you make sure they are automation compatible (have the [oleautomation] attribute and use only automation compatible types in their methods). This will assure that all required marshalling code exists - it will be just like DCOM. There might be other ways (like writing your own marshalling code), but this is a way that will work. You can, of course, also use DCOM. However, it depends very much on the details of your project, is this is the right way. The advantages are, that COM takes care of everything, like marshalling your data correctly (even between 32/64 bit processes). But also you might run into a lot of things that will be not so easy to solve for unexperienced COM programmers. There are quite some articles here on CP about IPC, might be worth to take a look there. In case you want to experiment a bit (and I would strongly suggest that before you decide for a certain solution!) I would suggest WTL (check out http://www.codeproject.com/kb/wtl/ [^]. A series of some very good articles is Michael Dunn's WTL for MFC Programmers). Create a project with the option "Create as COM Server" (will appear in the Application wizard). It will give you an exe project with a UI, that also acts as a COM server. Create two such projects in your solution, add some COM objects and start to play around a bit.

    ATL / WTL / STL com help question

  • Chakra: IActiveScript::GetScriptDispatch() fails with E_OUTOFMEMORY
    I imagiro

    Hi all, When using jscipt9 (Chakra) from C++ with the AddNamedItem() / GetScriptDispatch() functionality to create a module-like behaviour (context separation) I get E_OUTOFMEMORY from GetScriptDispatch(). This happens only when omitting the SCRIPTITEM_GLOBALMEMBERS flag with AddNamedItem(), no matter what other flags are given. I tried already everything, including different flags (all possible flags, not only the known ones), changing the order of calls to IActiveScript, calling it in different states of the script engine, invoking different versions via SCRIPTPROP_INVOKEVERSIONING, implementing all requested interfaces in my IActiveScriptSite etc - no result. For older versions (means: not using jscript9) of jscript everything works as expected. But as soon as I switch the CLSID to Chakra it breaks. I posted already on msdn: "AddNamedItem() / GetScriptDispatch() broken in jscript9?" [^] and filed a bug report [^]. You can reproduce with a most simple sample I put on github: https://github.com/IUnknown68/ascptest [^] My main questions is: Am I doing something wrong? Is there something undocumented I have to do? Or is it really a bug? Thanks, imagiro Edit: Run the sample from the command line with 9 as argument to invoke chakra. Otherwise the old jscript engine will be used.

    ATL / WTL / STL c++ com beta-testing tools help

  • How To Use Session Variables
    I imagiro

    He's a manager now? Well, that explains a lot. I know quite some managers who also write (or wrote) code, and that was among the most horrible code I've ever seen. Think you still might find examples here in TWATW.

    The Weird and The Wonderful database tutorial

  • How To Use Session Variables
    I imagiro

    Cool, who ever wrote the code invented the write-only variable.. What shall we call it? "Wrariable"?

    The Weird and The Wonderful database tutorial

  • ATL and exceptions
    I imagiro

    I personally never used exceptions for ATL projects. Now a colleague votes strongly for throwing exceptions instead of returning HRESULTs. I did some research, and even here on codeproject I don't find much about ATL and exceptions. To me it appears that exceptions in ATL are not very popular. So I would like to know from you ATL guys: Do you use exceptions? Or you simply return an HRESULT? And most imporant: Why? Cheers Imagiro

    ATL / WTL / STL c++ question

  • Secure enrcyption function
    I imagiro

    Question: I use another keyboard layout. Will it still work? However, this is a good encryption function - only the first 130 chars will be encrypted with a known key...

    The Weird and The Wonderful security
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups