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
K

Kuniva

@Kuniva
About
Posts
319
Topics
174
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • ATL MFC shell extension DLL LoadImage fails with 1813
    K Kuniva

    Eureka! : ) No it was nothing like that. Seems all this time I've been looking in the wrong place. I didn't know that for your resources to have string identifiers, you need to remove the define in whatever your numeric resource header file is maintained by visual studio. I just deleted IDI_TORTU in resource.h and now it works like a charm (doh :) ). Thanks for your help, if I hadn't simply tested with MAKEINTRESOURCE I'd still be debugging for instance handles ;)

    Kuniva --------------------------------------------

    C / C++ / MFC c++ graphics help com linux

  • ATL MFC shell extension DLL LoadImage fails with 1813
    K Kuniva

    Code-o-mat, The LoadImage call looks like this:

    HICON hIcon = (HICON) LoadImageA(handle, sIcon.c_str(), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);

    So it is loaded as type IMAGE_ICON, which it is in the resource file (I just copied the tortoise icon). Hmm I just tried it with a numeric identifier with MAKEINTRESOURCE and that does work however.. I want to use string identifiers like tortoise does because I'll be loading which icon to use from a configuration file (and I don't want to use numbers to indicate icons in that). I must be doing something wrong with the resources.. :/

    Kuniva --------------------------------------------

    C / C++ / MFC c++ graphics help com linux

  • ATL MFC shell extension DLL LoadImage fails with 1813
    K Kuniva

    Not sure if this is the right forum since it also has to do with ATL but.. I'm programming a shell extension dll (context menu) based off the article "The Complete Idiot's Guide to Writing Shell Extensions" by Michael Dunn. So I made an ATL project with MFC and COM support. At first I started by using SetMenuItemBitmaps() to set the menu item icons, but then I found out that this method doesn't support transparency. Because achieving transparency for menu icons is apparently far from straightforward, I had the marvelous idea of looking at the Tortoise CVS shell code. I incorporated some of the ideas like using LoadImage() and GDI plus on Vista to blit the icons to a bitmap and make them look good that way, but I also noticed that they didn't use ATL and did reference counting themselves (and as such are also easily able to access the DLL's instance handle). My problem now is that each LoadImage() call fails with error code 1813 which according to MSDN means "The specified resource type cannot be found in the image file.". Now my best bet is that I'm somehow using the wrong module handle (the one of the EXE perhaps instead of the DLL), but I've tried everything I can think of to get the correct handle including: 1. Use the m_hInstance member of the global CWinApp instance. 2. Just pass in NULL for LoadImage(). 3. Use GetModuleHandle() with the dll name passed in. This returns a handle but it still fails with 1813. 4. Use MFC's AfxFindResourceHandle() to get a handle to the dll instance. This fails with an assertion error in some MFC file saying the current resource handle is not set (so i tried setting it with AfxSetResourceHandle() to the theApp.m_hInstance handle, but that just crashed). I'm starting to wonder if the people from tortoise intentionally decided not to use ATL so they could get the instance handle from DllMain(). Either way, it seems to me that I've bumped into some internal MFC/ATL funkyness and I can't figure it out. So if anyone knows more about this or has any suggestions, do tell :) Oh yea, note: For the resource I'm testing with I'm simply using a string id such as "IDI_TORTU" which I then pass to LoadImage(). greets

    Kuniva --------------------------------------------

    C / C++ / MFC c++ graphics help com linux

  • Good OOP practice?
    K Kuniva

    I'm trying to write a small and simple GUI library in C++. Kind of like CDialog in MFC and all.. The problem is, I learnt C, and I've always had problems getting into the C++ part. I know the syntax and all, but it's rather the concept I can't always grasp. Now this may seem trivial, but it matters to me. My problem is this: Let's say I want to encapsulate a Window class into its own class, and also a normal overlapped window. Now my reasoning would be something like this: A window is based on a window class, so to make a window we'll need to pass our window object a windowclass object when we create it. Now I have several questions. First of all, look at two different approaches to implement the WindowClass class:

    // Implementation nr.1
    // _wcex is a member variable of WindowClass of type WNDCLASSEX
    WindowClass::WindowClass(HINSTANCE hInstance)
    {
    // Fill in all parts of _wcex structure with default values
    if(!RegisterClassEx(&_wcex))
    // throw exception
    }

    As u can see we call api function RegisterClassEx() to register the class in the constructor, so this class would only have a constructor and a destructor, and perhaps some additional constructors to allow more parameters to be passed to the WNDCLASSEX structure for greater customisation. Great idea, u just pick the constructor u need and ur window class is registered just by creating the object. Now the other approach:

    // Implementation nr.2
    WindowClass::WindowClass(HINSTANCE hInstance)
    {
    // Fill in _wcex fields
    _wcex.hInstance = hInstance; // ...
    }

    void WindowClass::Register()
    {
    if(!RegisterClassEx(&_wcex))
    // throw exception
    }

    In this implementation the only difference is we put the actual api call in a seperate method, so we can add Set() methods to the class for any field of the WNDCLASSEX structure, so we can customize the entire class. The only downside is it will result in more method calls depending on how much we want to customize. Now I realize this probably doesn't make much difference in practice, it both works, but I was wondering what you feel is the right way to do it. Personally I feel the right thing to do is to actually avoid API calls in constructors/destructors. I suppose it's more of a OO philosophical question though. If you could share your opinions on it, or direct me to some articles about this I'd be very grateful. I have another problem, but seeings this post is already kind of longwinded, I think i'll hold it back until i've ha

    C / C++ / MFC c++ question agentic-ai json help

  • Keyboard Hook in MFC -- Minor Syntax
    K Kuniva

    That's not true. You can export the function in your EXE just as well, a DLL and EXE are basically the same, they just have different entry points and are treated differently by Windows' PE loader. I tried the exact same thing with the keyboardhook once this guy is trying and it worked fine, in one EXE. The problem is, when I tried it without MFC for some reason it didn't work, but it did work with MFC. The hook function was simply in my EXE's export table, so windows just loaded the same EXE that made the call for the hooking registration in memory (or used the same copy i dunno what it does exactly) and used that function as the hook procedure. Kuniva --------------------------------------------

    C / C++ / MFC c++ regex help tutorial question

  • Winsock 2 10004 error code
    K Kuniva

    I wrote this little tool a while back that creates a raw socket and sends a custom UDP packet on it and it always worked great. But I tried it again, compiled it, and now when I run it I keep getting an error on my sendto() call and WSAGetLastError() returns error code 10004 which is supposed to be this:

    WSAEINTR
    (10004)
    Interrupted function call.
    A blocking operation was interrupted by a call to WSACancelBlockingCall.

    Whatever that means.. I'm not using WSACancelBlockingCall anywhere, and my program isn't ending prematurely or anything. So I don't get it, why is it doing this all of a sudden? Kuniva --------------------------------------------

    C / C++ / MFC help question

  • Platform SDK Environment variables - puzzled
    K Kuniva

    I've encountered a few rather annoying problems when trying to use the new platform SDK, which I apparently, really need. So when I found myself in what seemed to be an unoverseeable mess, I decided to uninstall the sdk and reinstall and see if that helped any. Obviously it didn't. The installer said theres a SetEnv.cmd file included to set my environment variables so Visual Studio would be able to use the sdk properly. So after the install, I run SetEnv. I check my Environment variables via System->ENvironment variables (Include, Path, Lib etc..), both user and system variables, what do I see, nothing, a single entry to some older SDK or something. I open visual studio (I have .NET 2003 aka 7.1) and go to Tools->Options->Projects->Visual C++ Build directories and as expected see my entire list of include directories, lib directories and executable directories. The funny thing is, at the bottom of the dialog it says, and I quote:

    Path to use when searching for include files while building a VC++ project. Corresponds to environment variable INCLUDE.

    Corresponds to environment variable INCLUDE... then why is it that when I check it there's only one lousy entry not much to do with anything even..? Is Visual Studio storing them somewhere else? Cause I'd hardly suspect my System control panel of cheating. Then I have another annoying problem. Whats with the 'new' iostream and standard C library routines? Apparently they rewrote some of them? And decided it was better to go and start cluttering them around some, as to make our lives even a bit more troublesome? First I had a problem cause I was trying to compile a project that was using the old iostream.h include file and msdn says to use the new library u need to include iostream, without .h part. Now when I did that it worked fine. But what I dont get is why it didnt work fine with the iostream.h one, cause then I got a linker error for libcimtd.lib. but when I looked in my platform SDK folder I didnt find any file like that. actually there was a whole bunch of libcp, libcmt, libctd etc files but none with an aditional 'i' in it.. So what the hell are they trying to pull. But whatever, I wasn't that bothered yet cause it worked with iostream. Its only now that it started to really piss me off, when I tried to compile another project, which didnt use MFC or anything, and I got loads of linker errors:

    Linking...
    libcpmtd.lib(locale0.obj) : error LNK2005: "public: __thiscall std::locale::locale(void)" (??0locale@std@@QAE@XZ) already defined in

    C / C++ / MFC c++ csharp help visual-studio algorithms

  • Hooking RegisterClassEx and dll question
    K Kuniva

    Hmm ok.. First of all, I just checked and the progress control is the normal one registered through InitCommonControlsEx(). Now, I did some testing and came up with some stuff I really can't explain: First I made a test app that simply consists of a window and it does the following on startup:

    INITCOMMONCONTROLSEX icc;
    
    icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
    icc.dwICC = ICC\_PROGRESS\_CLASS;
    
    InitCommonControlsEx(&icc);
    

    Now my hooking app logs both InitCommonControlsEx() and RegisterClassEx(). When I run my test app, I get a log for InitCommonControlsEx() just as I should PLUS a call to RegisterClassEx() (for the progress control). Now the weird thing is, in my hooking app I also log the lpszClassName member of the WNDCLASSEX structure for the RegisterClassEx() function. For my test app I get "PROGRESS"... ???? :wtf: I mean.. wth is going on, isn't it supposed to be "msctls_progress32" or something? Now, another weird thing. As I've said I checked the class of the IE progress bar by using Spy++ and it's msctls_progress32. Now the thing is, when I have my hooking app running, then start IE, I DO log two RegisterClassEx() calls but NO InitCommonControlsEx() calls? The ones I do log are the following: RegisterClassExA() - CicMarshalWndClass RegisterClassExA() - IMMIF UI Now, am I right to conclude from this that the "Common progressbar" control IS NOT of class msctls_progress32 but just.. PROGRESS? However, that's impossible because I checked commctrl.h and there it's declared as follows:

    //====== PROGRESS CONTROL =====================================================

    #ifndef NOPROGRESS

    #ifdef _WIN32

    #define PROGRESS_CLASSA "msctls_progress32"
    #define PROGRESS_CLASSW L"msctls_progress32"

    #ifdef UNICODE
    #define PROGRESS_CLASS PROGRESS_CLASSW
    #else
    #define PROGRESS_CLASS PROGRESS_CLASSA
    #endif

    #else
    #define PROGRESS_CLASS "msctls_progress"
    #endif

    I am seriously confused about all this and any clarification would be wonderful. Thanks. Kuniva --------------------------------------------

    C / C++ / MFC question performance help tutorial lounge

  • Hooking RegisterClassEx and dll question
    K Kuniva

    Ok, what I'm trying to do here is change the default WindowProc of a common control by hooking RegisterClassEx using a hooking library. I figured InitCommonControls() does nothing but register the common control classes using RegisterClass(). BUT.. I managed to hook the functions, but I noticed that when I start apps like IE and others, I usually get a few RegisterClassEx calls but for really anomalous classes. To make myself clear, its the progress bar I want to change ("msctls_progress32" or something). So I don't get why I'm not logging the RegisterClassEx() calls for those controls when IE starts. My logical explanation would be that the registering of these classes is somehow global for the system and that its only done once at startup or whenever an app first uses them, but that seems kinda weird, cause then why would an app need to call InitCommonControls() each time before it can use them? :/ Then I have a second issue which has more to do with Windows in general really. I was wondering: When an application is loaded, is a new copy of the dlls it uses always loaded in memory, or does Windows keep like a pool of loaded dll's and if its already loaded the app will just use that dll? Like kernel32.dll or user32.dll for example. Does each app get a fresh copy or do they all use a shared instance? My guess would be they all get their own copy, but then I would think applications would consume more memory than they appear to do. Thanks in advance for any clarifications. Kuniva --------------------------------------------

    C / C++ / MFC question performance help tutorial lounge

  • Changing the appearance of a common control system wide
    K Kuniva

    I was wondering how to change the look (or even behaviour) of a windows common control so it will reflect throughout the entire platform. For example I'd like to change the progress control to be a fluent bar instead of the normal block-ish one. I found an article on MSDN about this but it was for Win CE, couldn't find anything for 2K/XP. Does anyone have an idea as where to start? Kuniva --------------------------------------------

    C / C++ / MFC tutorial question

  • Help with ASCII conversion
    K Kuniva

    Maybe not the shortest way, but should work:

    __int64 test;
    char buf[128];
    const char dt[] = "0x01c5556a92792c8c";

    memset(buf, 0, sizeof(buf));

    for(int i=0;i<8;i++)
    {
    int n = strlen(dt) - ((i+1)*2);
    sprintf(&buf[i*2], "%c%c", dt[n], dt[n+1]);
    }

    sscanf(buf, "%16I64x", &test);

    Kuniva --------------------------------------------

    C / C++ / MFC tutorial data-structures help question

  • Need help with reversing an algorithm
    K Kuniva

    You can't reverse the process, cause here:

    unsigned PullTerminalId(unsigned long id)
    {
    return ((unsigned)(id >> 20));
    }

    You potentially loose information, u can't just automagically make it reappear. id >> 20 makes the 20 rightmost bits of the unsigned long integer go down a black hole. Kuniva --------------------------------------------

    C / C++ / MFC tutorial algorithms help question

  • How to get output of console program?
    K Kuniva

    This may seem like a stupid question, but i simply don't know where to look. How can I execute a console program from another console program and catch the output so i can display it in my own program. Thing is I want to have a file compiled but i want to catch the output from the compiler binary in case of errors. The only functions I know to execute something are system() and ShellExecute() but I don't know how to catch the output after that. Kuniva --------------------------------------------

    C / C++ / MFC question tutorial

  • run-time dll linking - getting a variable
    K Kuniva

    Heh, damn, I was kinda hoping for an explanation, I hate having to have to avoid the problem. But I guess I don't have much choice so thank you for your reply anyway. And as for the global variables are evil thing, so they keep telling me.. I don't see any reason why they should be evil in very small programs though :P And generally I believe it to be said by people who can't make sense of their own programs after a while ;) Also, no stack operations means more speed, weee. So, in short, global variables are evil, but fun! lol.. just messing. Kuniva --------------------------------------------

    C / C++ / MFC question

  • run-time dll linking - getting a variable
    K Kuniva

    Hi, my scenario is like this: I link a dll at run-time by calling LoadLibrary() and then I call GetProcAddress to get the location of a function within that DLL so i can call it. This works fine. But now I wanted to get the location of a variable, and address that, but it doesn't work. In my DLL I have a declaration as follows:

    extern "C" { char * szLogFile = "C:\\log.txt"; }

    So I try to address the variable from my program as follows:

    char * test = (char*)GetProcAddress(hinstDLL, "szLogFile");

    But when I then try to show the variable test using a messagebox I just get garbage so the pointer must be wrong. Any ideas whats wrong? Kuniva --------------------------------------------

    C / C++ / MFC question

  • HIMETRIC_INCH undeclared??! wth?
    K Kuniva

    Oh.. Sorry about that.. mm odd, I did a search using the windows find utility, guess that doesn't work right.. Thx for the program. Kuniva --------------------------------------------

    C / C++ / MFC csharp visual-studio com question

  • HIMETRIC_INCH undeclared??! wth?
    K Kuniva

    How odd :wtf: I don't have a file WinGDIX.h... neither in my vc6 include directory, nor my ms sdk include directory.. weird.. guess it's update time. But thank you both for the replies :) Kuniva --------------------------------------------

    C / C++ / MFC csharp visual-studio com question

  • HIMETRIC_INCH undeclared??! wth?
    K Kuniva

    Well i got the functions from http://www.codeproject.com/bitmap/render.asp[^]. But i've also seen it used in various other articles that use the Ole way to load pictures. So yea.. it probably exists.. but seeings it's just a constant, maybe someone could just supply me with the value? Kuniva --------------------------------------------

    C / C++ / MFC csharp visual-studio com question

  • HIMETRIC_INCH undeclared??! wth?
    K Kuniva

    I was trying to display a jpeg picture in a window so i tried the Ole approach, but in all functions they use a constant HIMETRIC_INCH, which is apparently not declared in my header files.. which I think is very odd seeings i never saw anyone else complain about it in the comments.. I have Visual Studio 6.0 and I also have an up-to-date SDK installation. What's going on? Kuniva --------------------------------------------

    C / C++ / MFC csharp visual-studio com question

  • 8 byte long integer? how?
    K Kuniva

    I need to work with an 8 byte integer... but when i do a sizeof long int it gives me a size of 4 bytes.. how do i get it to work with 8 bytes? Kuniva --------------------------------------------

    C / C++ / MFC 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