Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6792193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:56:21+00:00 2026-05-26T17:56:21+00:00

Im creating an unmanaged DLL in Visual Studio 2010. In order to test my

  • 0

Im creating an unmanaged DLL in Visual Studio 2010.

In order to test my DLL I have created another project with Visual Basic and i’ve attached it to the solution.

VB code calls to my InstallHook function in the DLL, passing a delegate of the callback function at VB. Then the DLL creates a hook and everytime a key is pressed the VB callback is called receiving the key and some other params as argument.

Well, the problem is that after some keys has been pressed, and the buffer in the VB callback reaches a specific size, the program crash. To be more specific, when the callback is called by the last time and it writes into its buffer in VB, it’s like it overlaps in somewhere because the next time the callback is going to be called in the DLL, the program crash without reach the callback (the pointer in the dll is fine)

I dont understand well the architecture of .Net and i dont know exactly what could be wrong, but im very confident in the code i’ve done and the problem should be something technical with the memory management in .Net.

Edit: I forgot to say that if I call the callback from within the VB code, then it works fine. The callback is normally called from a WndProc installed in the same window.

Thanks….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:56:22+00:00Added an answer on May 26, 2026 at 5:56 pm

    the pointer in the dll is fine

    I suspect this is the problem. If you pass an address into a native routine, and then use it beyond the scope of the single method call, you run some risks.

    The problem is that .NET uses a compacting garbage collector. This means that the runtime may “move” the buffer to a completely different location between method calls. As such, at some point, when you write to it, it could be in a completely different location.

    You can work around this via allocating and managing the memory yourself via the Marshal class. Alternatively, you can use the GCHandle class to pin the memory and prevent it from being moved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I'm creating a new project in unmanaged C++, Visual Studio 2008 or greater,
I have a dotnet process that through calls to an unmanaged dll is communicating
I am creating an extension for Visual Studio 2008, and because I didn't want
My solution is primarily C#, but I have one C++ project that creates a
How to dynamically load a managed (.Net) DLL in unmanaged code? I'm creating a
Does anybody know of a method for creating custom Performance Counters using ordinary unmanaged
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
Creating an installer for possible remote systems so that if they do not have
Creating Trial .git -repo $ mkdir Test; cd Test; git init $ echo Just
I have been tasked with maintaining a legacy unmanaged c++ system. I do not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.