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

  • Home
  • SEARCH
  • 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 5848039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:48:13+00:00 2026-05-22T12:48:13+00:00

I encountered a strange issue while coding a .dll file in C with gcc

  • 0

I encountered a strange issue while coding a .dll file in C with gcc compiler and then tried to use it through MSVC and visual studio. The .dll compiles correctly and is correctly used by test programs compiled and linked with gcc.
But when I try to do use the .dll in Visual studio I get a strange runtime crush. I have identified the issue and would appreciate your input as to why is this happening.

In the test program we have a function which allocates a buffer, populates it in some way (depending on the user) and then returns the buffer. The user has to implement it on his own. Something like below:

float* decode(void* data, int dataSize, int par1, int par2,int par3)
{ 

    //allocate the memory for the data
    float* d =  (float*)malloc(sizeof(float)*dataSize);

    //do something to populate the data here

    //return data
     return d;
}

The dll has two functions which actually take a function pointer to that use-rmade function and use it to get that float* buffer. Then the .dll uses this function to create and use the data and after the usage it frees them.

Something like below:

void DLL_Func(void* data,unsigned int inputPN,float* (*decode)(void*,int,int,int,int))
{

    //use the user-made decode function
    float* nData = (*decode)(data,inputPN,par1,par2,par3);

    //do stuff here

    //before returning free the data buffer since it is no longer needed
    free(nData) //<--- Crushes the program only in Visual Studio
 }

Well I isolated the problem in that free(). Works fine if I use my dll from a gcc compiled program but MSVC compiled program crushes at that point and gives this:

 Unhandled exception at 0x7714e1fe in vstudiotest.exe: 0xC0000005: Access violation reading location 0x1e6dca5e.

Which I guess means that for the MSVC compiler what my dll does is forbidden. Is this just some MSVC quirk or should GCC also crush but does not and will come back in the future and torture me with this problem?

Of course the solution is to change it somehow so that the buffer is also freed by the user and not the .dll but I would like to understand the reason this is happening first.

  • 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-22T12:48:14+00:00Added an answer on May 22, 2026 at 12:48 pm

    memory must be allocated and freed with the same CRT. This means in general that you should try to free memory in the same module it was allocated in to avoid these types of issues. If this isn’t possible you must link to the same version of the CRT.

    MSVC will complain if you try to link to different versions of the MS CRT, but I’m guessing that you are linking to some other version that MSVC doesn’t know about.

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

Sidebar

Related Questions

I encountered a problem some days ago while working with Generic TList in the
I've been playing with blocks and encountered a weird behavior. This is the interface/implementation,
I've been doing an Android tutorial and encountered a class with the following: public
Hey guys, I have a raidan style 2d flying/fighter game that im working on.
I've got a set of regex's within a function that are working rather well
I'm having a hard time figuring out why lseek doesn't work properly. Basically all
I'm trying to find a way to split a String into an array of
Hei, i think order by is ordering things wrongly. Example code: static void Main()
I added PHPUnit to a project via git submodule add per the instructions in

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.