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
H

Henrik Stuart

@Henrik Stuart
About
Posts
24
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • It's official...
    H Henrik Stuart

    David Stone wrote: Henrik... ...get out more. Would you believe I'm engaged and have a large social circle? :~ David Stone wrote: I believe you though, it's great. I'm thinking of doing all my documents in LaTeX...forever. Word is just so restrictive. You don't notice it at first. LaTeX just has this really cool feel to it (the finished typeset document, not the source code although that is rather cool as well, but anyway!) and after a while you just kind of start to look at Word documents with disdain. What? No proper ligatures? What is that? Incorrect kerning in justified alignment? Inexcusable! If you want to do "just that extra thing" for your documents, invest in a Garamond font and set it up for your LaTeX distribution (MiKTeX really is awesome), makes a world of a difference. And like the geek I am, I always enjoy discussing LaTeX layout code and what packages to use for this and that and how to code your own and... right, right, outside, big shiny thing... right! (At least I didn't start with the maths jokes yet). -- Henrik Stuart (http://muer.njoerdba.com[^])

    The Lounge com tools question

  • It's official...
    H Henrik Stuart

    It's not just you get hooked to it, it's just so... great! I mean, when did you last use a typesetting utility that's Turing Complete? (yes, other than LaTeX). The subtle art that it is to define new document templates, coercing figures to stay put where they are meant to be and all. But most important of all, its rendering, its hyphenation, it's just all so... great. *sigh* Alright, who said I need to get out more? :~ But really, it's good for a lot else than just typesetting your thesis. Since I've been enamoured and used it extensively for much too many years already I do most things in it, business cards, letters, invitations, anything! When Turing is complete, recurse your way home. :rolleyes: -- Henrik Stuart (http://muer.njoerdba.com[^])

    The Lounge com tools question

  • Anyone heard of this - TOR?
    H Henrik Stuart

    There's an article on Tor on Whitedust[^] that illustrates a few of the concepts of Tor and how it can be used/possibly blocked. Now, the problem with Tor is that it isn't just used for privacy, it has found a popular use as a vehicle for anonymised attacks and threats. In particular many IRC networks are plagued by attacks launched by people behind Tor proxies to the point that the Tor project has had to include descriptions[^] for how to block Tor proxies. Yet another thing to limit access from in your service. Privacy-enabling software is a dual-edged sword... on one hand it allows people to express their opinion in anonymity, on the other hand it allows unscrupulous people to misuse this anonymity by attacking others. The conundrum of the digital age. -- Henrik Stuart (http://muer.njoerdba.com[^])

    The Lounge question

  • Depressed Web Server
    H Henrik Stuart

    Nothing like 404 error messages. There's a nice collection on http://www.plinko.net/404/area404.asp[^] if you feel inclined (there are a couple with some explicit language there, but most should be safe for all). And my own as a variation over the Raven (yes, I realise there's a bunch of these around already), here: http://muer.njoerdba.com/errors/404.html[^] -- Henrik Stuart (http://muer.njoerdba.com[^])

    The Lounge sysadmin

  • development futures...
    H Henrik Stuart

    l a u r e n wrote: there is no good reason why managed code and the clr was necessary to provide any new class library features etc bar garbage collection afaics (and anyone who acually _needs_ garbage collection shouldnt be writing software) There's a vital difference between needing and using. Using a platform with garbage collection can alleviate some obscure bugs (of course, so can writing rigorously correct c++, but I haven't found many that are able to do that yet), it can reduce development time and alleviate maintenance efforts. Of course, garbage collection can be a pillow for people who don't know what they are doing, but they are always there; they are abundant in the C++ world as well. As I see it, the importance is not whether or not you have garbage collection, it is whether you know why your tools work and how they work, not just how to use them. The big gain of .Net is, as I see it, the language agnosticism that it provides. You can try however much you want and argue that COM provides an ample amount of interoperability between languages, but I think the elegance in which .Net interoperates speaks for itself. -- Henrik Stuart (http://muer.njoerdba.com[^])

    The Lounge c++ dotnet com sales tools

  • Read long lines from cin?
    H Henrik Stuart

    #include <iostream>
    #include <string>

    int main() {
    std::string line;
    std::getline(std::cin, line);
    std::cout << line << '\n';
    }

    That should do it. std::getline is a mightily useful function that works on any and all input streams. It resides in <string>. If you want to use an alternate "line separator" there is an overloaded std::getline for this as well. Hope it helps. -- Henrik Stuart (http://www.unprompted.com/hstuart/[^])

    C / C++ / MFC question

  • what wrong with this function template?
    H Henrik Stuart

    As ilostmyid2 pointed out then TFun(5.4321, 1.2345) calls the template function with T = double, if you want to use the float TFun(float, float); function instead you should call it with TFun(5.4321f, 1.2345f);. In other words, you are trying to match the wrong types together, and naturally the template function will be chosen as the primitive float function is never being picked by your code. Hope that should clarify it. -- Henrik Stuart (http://www.unprompted.com/hstuart/[^])

    C / C++ / MFC help debugging question workspace

  • what wrong with this function template?
    H Henrik Stuart

    Read item 2 in my previous post again, it explains why they need to be commented out. In order to explain it a bit further: When you say: int max(int, int); you say there is a function, somewhere, that does this, but not how it does it. When you then type max(100, 200); it tries to use this function, not the template function. This results in it using an undefined function, and that is what it complains about. If you fill out the function, e.g. int max(int a, int b) { return a > b ? a : b; } it would work as well, but it wouldn't, obviously, be using the template function. Please, refer to the rest of my list about the issues in your code. And take a good, long look at Alexandrescu's article and preferably use his min/max functions instead. Hope this helps. -- Henrik Stuart (http://www.unprompted.com/hstuart/[^])

    C / C++ / MFC help debugging question workspace

  • what wrong with this function template?
    H Henrik Stuart

    There isn't per se anything wrong with the template function, rather with some other parts of the code.

    1. You are using iostream.h, this is a pre-standard header and should not be used. Instead use iostream, without a postfixed .h
    2. You defined two functions manually, float max(float, float); and int max(int, int);. These two functions do not refer to the templated function and will be used before the match to the template function. Hence, you should remove these and the error will go away.
    3. Lastly, have you considered what happens if you do something like this: short s = 37; int a = 2839; int b = max(s, a);? This will fail with an error message, because the compiler isn't able to deduce the type of T (your template parameter). Thus, you need to implement a more solid min/max function, as explained by Andrei Alexandrescu in his Generic< Programming >: Min and Max Redividus[^] article at http://www.cuj.com[^]
    4. Also, this is just a small detail, but you might want to consider using '\n' rather than std::endl, because std::endl also explicitly flushes the stream - can slow down performance unnecessarily (albeit not a lot in most cases).
    5. Lastly, the main signature is according to the standard either int main() or int main(int argc, char* argv[]). void main() is a Microsoft-specific extension, and unless necessary (I haven't yet seen any reason why) it should be avoided for the sake of portability.

    All in all, the code will look like this:

    #include <iostream>

    template<typename T>
    T max(T a, T b) {
    return a > b ? a : b;
    }

    int main() {
    std::cout << "The maximum of 100 and 200 is "
    << max(100, 200) << '\n';

    std::cout << "The maximum of 5.4321 and 1.2345 is "
    << max(5.4321, 1.2345) << '\n';

    return 0;
    }

    I hope this helps. -- Henrik Stuart (http://www.unprompted.com/hstuart/[^

    C / C++ / MFC help debugging question workspace

  • SQL query for Date field
    H Henrik Stuart

    You can query it like this (just replace GETDATE() with your column): SELECT DATENAME("dw", GETDATE()) + ', ' + DATENAME("m", GETDATE()) + ' ' + CAST(DAY(GETDATE()) AS VARCHAR) + ', ' + CAST(YEAR(GETDATE()) AS VARCHAR) I'd suggest you just query out the DATETIME field and process it in your platform of choice. The .NET framework has, amongst others, very good localisation support for this that you could use to get the proper string for the proper locale setting. The use of DATENAME is dependant on how SQL Server processes it and thus it cannot be formatted to the users' locale/preferences (at least not to my knowledge). Hope this helps. -- Henrik Stuart (http://www.unprompted.com/hstuart/[^])

    Database database question sql-server sysadmin

  • Windows 2K or Windows XP ?
    H Henrik Stuart

    BOOL GetVersionEx(LPOSVERSIONINFO lpVersionInfo); Declared in winbase.h, include windows.h to get it. MSDN has information on the OSVERSIONINFO struct (see below). GetVersionEx[^] Hope this helps. -- Henrik Stuart (http://www.unprompted.com/hstuart/[^])

    C / C++ / MFC question json announcement

  • SOAP over SSL with Certificate
    H Henrik Stuart

    This... is a long road with many a winding turn... took me quite some time to get everything working correctly. You fail to specify whether your C#-app is an ASP.NET web service client or a console/winforms web service client. I'll presume it's the latter as that's remarkably easier. At either length it's easiest to use Microsoft WSE 1.0 enhancements[^] to fetch the certificate from the certificate store. By default it is presumed that your client certificate is in the personal store of the current user (e.g. the one that is executing the application). If this is ASP.NET then as the user doesn't have a login profile the user doesn't have a personal store folder either and you need to carefully import the certificate to the personal store of the local machine. The following code will get the private certificate from the depths of the certificate store: byte[] certhash = { 50, 49, 239, 183, 249, 60, 36, 134, 129, 159, 39, 226, 197, 70, 76, 1, 147, 237, 43, 217 }; X509CertificateStore store = X509CertificateStore.CurrentUserStore(X509CertificateStore.MyStore); store.Open(); X509CertificateCollection certs = store.FindCertificateByHash(certhash); store.Close(); X509Certificate cert = certs[0]; There are other ways to find a certificate than by using its hash value, but you can refer to the WSE 1.0 documentation for these. Now, to add the certificate to the service call let's presume your web service object is Service1 then you add it fairly simply using: Service1.ClientCertificates.Add(cert); It doesn't seem so daunting when you look at it like this, but it can take a lot of time to figure out given the.... usefulness.... of most code examples around. I think that's all it takes, good luck fighting the certificate mmc snap-in. :) Hope this helps. -- Henrik Stuart (http://www.unprompted.com/hstuart/[^])

    C# csharp tutorial wcf security cryptography

  • Help: I cannot use getline(...)
    H Henrik Stuart

    Might I suggest something more like this:

    #include <iostream>
    #include <fstream>
    #include <string>

    int main() {
    std::ifstream file("filename");
    std::string line;

    while (std::getline(file, line)) {
    std::cout << line << '\n';
    }

    return 0;
    }

    Just a couple of points:

    • C++ defines main as: "int main()" or "int main(int argc, char* argv[])". There's nothing in the code that limits us to Visual C++ and its non-standard "void main()" extension.
    • Using std::getline (defined in "string") we avoid using a char* buffer as we have to with std::basic_istream<...>::getline.
    • Invoking s.c_str() on something we write out using iostreams anyway might incur the following overhead: a char* buffer that can contain the contents is allocated, the contents of s is copied over into it, a terminating null character is added and this buffer is returned. This is because the contents of std::string isn't guaranteed to be null terminated.

    Hope this helps. -- Henrik Stuart (http://www.unprompted.com/hstuart/[^])

    C / C++ / MFC help csharp ios

  • how to do write to a file with a std::string
    H Henrik Stuart

    #include <iostream>
    #include <fstream>
    #include <string>

    std::string s;

    std::ofstream arch("filename");
    std::cout << "enter your name: ";
    std::getline(std::cin, s);

    arch << s;

    Reading the name by using "cin >> s;" will stop at the first whitespace character, so if you want to read the entire line std::getline is just perfect. std::getline strips the newline characters from the end (both \r and \n). Personally find mixing C and C++ I/O a tad on the ugly side. I'm fully aware that it can be a necessity when incorporating C++ code in older apps, but for new code you might as well stick to the iostream library. I haven't included any error checking in the above code (those are the things we love to leave as an exercise for the reader, no?). All it needs more, really, is a check on whether the file was actually opened and good for writing. Hope this helps. -- Henrik Stuart (http://www.unprompted.com/hstuart/[^])

    C / C++ / MFC tutorial question

  • ??? avserve2.exe ???
    H Henrik Stuart

    Probably a W32/Sasser spin-off. http://msn.mcafee.com/virusInfo/default.asp?id=description&virus_k=125007[^] Hope that helps. -- Henrik Stuart (http://www.unprompted.com/hstuart/)

    The Lounge sysadmin question

  • sql statements
    H Henrik Stuart

    USE db;
    GO

    SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_TYPE = 'BASE TABLE';

    For instance. Presuming, of course, you're talking about MSSQL Server. -- Henrik Stuart (http://www.unprompted.com/hstuart/)

    Database database question

  • CVS experts
    H Henrik Stuart

    You can use:

    cvs -a -c -D since

    but as to my knowledge CVS doesn't support looking up commits in a date interval. At least I couldn't see it in the manual from a cursory overview. -a: all users -c: commits -D: should be obvious ;) -- Henrik Stuart (http://www.unprompted.com/hstuart/)

    The Lounge tutorial question

  • System.io.FileStream
    H Henrik Stuart

    while (fs.Position < fs.Length)

    for instance. -- Henrik Stuart (http://www.unprompted.com/hstuart/)

    C# question

  • using LIMIT within a SELECT statment
    H Henrik Stuart

    SELECT TOP 5 * FROM SomeWhere WHERE Something = 'SomeCondition'

    MSSQL doesn't support "LIMIT x, y" but it can be emulated through a somewhat... icky... nested subselection. -- Henrik Stuart (http://www.unprompted.com/hstuart/)

    Database csharp asp-net database mysql sql-server

  • vector&lt;CString&gt; *pvecString ?? :confused:
    H Henrik Stuart

    First line you're trying to assign a std::vector<T> to a std::vector<T>*, which obviously fails, and should fail unless something really fishy is at work here. Second line you're trying to assign a local variable to a global variable by using the address-of operator on the local variable. This will cause the g_pvecStrings variable to point to memory on an unwinded stack after the termination of the void CMyClass::MyFunction(void) method call. The correct approach would be to do: *g_pvecStrings = vecStrings; presuming g_pvecStrings != 0. An even more correct approach would be an application redesign, but that's probably just the C++ purist in me talking. ;) Hope that helps. -- Henrik Stuart (http://www.unprompted.com/hstuart/)

    C / C++ / MFC c++ graphics help tutorial question
  • Login

  • Don't have an account? Register

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