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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
C

Conor Hunt

@Conor Hunt
About
Posts
5
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • DLL memory Allocation
    C Conor Hunt

    That seemed like a good solution to me too and I tried it, but it gave me an access violation. There may have been some bugs in my code (not allocating a large enough buffer and overflowing it), I'll try it again. Thanks!

    C / C++ / MFC question debugging performance help announcement

  • DLL memory Allocation
    C Conor Hunt

    That is a good idea. I'm not sure that I want to use it in this case though? The function in the DLL is called many times and returns many character buffers. That means that I have to keep track of all of these allocated character buffers in the dll, so that wehn DestroyXXX is called I free them all. I also can't have a DestroyLastAllocatedBuffer() function that frees the most recently allocated character buffer because the function in the DLL can be called by many different threads. (caveat: you probably could do both of the above with some extra work, but it might be more work than it is worth?) I'd prefer for the calling application to be able to call the DLL function to get a characted buffer and then free it right after it is done with the buffer. I think I have another solution though. You can create a C++ object with a destructor that does the memory freeing. It seems to work, anyone see any problems? // Text holder class CTextHolder { public: CTextHolder() ~CTextHolder() { delete text; }; char *text; }; // This is the exported function in the dll extern "C" { CTextHolder * getText() { CTextHolder *blah = new CTextHolder(); blah->text = new char[20]; return blah; } } // This is the function in the application that calls the exported function in the DLL void testCall(void) { HMODULE mod = LoadLibrary("d:\\plugin.dll"); if(mod == NULL) return; // Test function is typdefed as.. typedef CTextHolder * (*aFunc)(void); testFunction getText = (testFunction) GetProcAddress(mod, "getText"); if(getText == NULL) return; CTextHolder *blah = getText(); // Yay.. this seems to work fine delete blah; FreeLibrary(mod); }

    C / C++ / MFC question debugging performance help announcement

  • DLL memory Allocation
    C Conor Hunt

    Thanks! It works now. I linked both with 'MultiThreaded DLL' so that the dll and application both use the same heap manager.

    C / C++ / MFC question debugging performance help announcement

  • DLL memory Allocation
    C Conor Hunt

    Hi, I am using LoadLibrary() and GetProcAddress() to get an exported function from a dll. The exported function looks like this: extern "C" { char *getStuff() { return new char[10]; } } When I call this function everything works fine until I try and 'delete' the memory that was allocated in this function. I get this error in the debug version - "HEAP[GenericTester.exe]: Invalid Address specified to RtlValidateHeap( 2f0000, 7b27a0 )". From what I guess that means that the application is trying to free memory from a different heap than the memory was allocated from? My question then is: how do I allocate memory inside of the GetProcAddress() function that can be freed by the calling application? Thanks!

    C / C++ / MFC question debugging performance help announcement

  • SetWindowsHookEx
    C Conor Hunt

    I'm having problems withm a global windows hook created with SetWindowsHookEx. The hook procedure is contained in a dll and the installation procedure for the hook is also contained in the same dll. I also have an application that links to the dll and calls the installation procedure. When the application is running the hook works fine, but as soon as I quit the application the hook dissapears. I have not unhooked the hook, but it seems to uninstall it anyway. I wanted to install the hook using the application and then have the application quit while the hook is still running, can I do this? Thanks.

    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