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 7871499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:55:27+00:00 2026-06-03T01:55:27+00:00

I am having trouble with a dll I am writing in C++. There is

  • 0

I am having trouble with a dll I am writing in C++. There is some very strange behavior going on that I have not been able to solve on my own.

It’s hard to describe exactly what’s going on, but I will try my best. Basically I have a class in my DLL with a single private property and a public constructor. When I initialize this class and then exit the program I get an error.

“Run-Time Check Failure #2 – Stack around the variable ‘test’ was
corrupted”

I have 2 projects here:

  1. The DLL named “testdll“.
  2. The console test program named “test“.

I have boiled this error down to its simplest reproducible form to try and narrow down the possible causes, below you will find my code.

Project “testdll”, file testdll.h:

#include <string>

class testdll
{
public:
__declspec(dllexport) testdll(); // Empty but same error if prams are used.

private:
std::string _var;
};

Project “testdll”, file testdll.cpp:

#include "testdll.h"

testdll::testdll()
{
}

Project “test”, file testdll.h:

#include <string>

class testdll
{
public:
    __declspec(dllimport) testdll();
};

Project “test”, file stdafx.h:

#pragma once

#include "targetver.h"

#include <tchar.h>

Project “test”, file test.cpp:

#include "stdafx.h"
#include "testdll.h"

int _tmain(int argc, _TCHAR* argv[])
{
testdll test;

return 0;
}

If you want I can send you the Visual C++ 2010 solution file, in the archive format of your choice. Please help! I have no idea what’s going on.

Optional Information:
Language (or Software): C++

Already Tried:
Deleting the constructor definition, which works but is not a usable solution, nor does it explain the problem. Also making all of my private properties into pointers works, however I should not have to do this.

  • 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-06-03T01:55:31+00:00Added an answer on June 3, 2026 at 1:55 am

    You are using two header files, they don’t declare the same class. One has a std::string member, the other doesn’t. That’s very very bad, the compiler doesn’t reserve enough space for the object on the stack frame. Which is what the runtime error is telling you. Very nice feature btw, this kind of mistake is incredibly hard to diagnose otherwise.

    You probably got into this pickle because you only applied __declspec(dllexport) to the constructor instead of the entire class. You’ll need to write the header file so it can be used by both your dll project and your exe project. That should look like this:

    #undef DLLEXPORT
    #ifdef BUILDING_MYDLL
    #  define DLLEXPORT __declspec(dllexport)
    #else
    #  define DLLEXPORT __declspec(dllimport)
    #endif
    
    class DLLEXPORT testdll
    {
    public:
        testdll();
    private:
        std::string _var;
    };
    

    Right-click your DLL project, Properties, C/C++, Preprocessor, Preprocessor Definitions. Append BUILDING_MYDLL

    And delete the testdll.h file in your exe project directory. Set the C/C++, General, Additional Include Directories setting so the compiler can find the header in the testdll project directory (like ..\testdll)

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

Sidebar

Related Questions

I'm having trouble setting the path to a DLL that is not in the
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
I am having some trouble with the interop.tapi3lib.dll (which can be DL here: dllLink
I am having trouble getting NCover to properly cover a .dll. I have several
I am having trouble converting some code from VB6 to VB.NET (I don't have
I am having trouble understanding wix documentation. I have created a simple installer that
I am writing a keylogger in C# but am having some trouble getting my
I'm having a little trouble overloading methods in C#. I have two methods that
I've been having trouble loading this DLL, so I opened it up in Dependency
Having trouble understanding. With the following css : .bloc .field:nth-last-child(2){ ...some values... } and

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.