CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: Static Link Lib problems

  1. #1
    Join Date
    Dec 2006

    Static Link Lib problems

    I have 36 hours to finish my semester long project and I have a ton more to do.

    And A little while ago i decided to split it up into 4 "projects". 3 of which compile down to static link libs, then the last links to the 3 libs and runs the main ect.

    All compiles now. And runs, BUT!!!! I have a class that I instantiate in the constructor of 1 of the classes in a static link lib (SLL from now on) and that class has member varriables that are set in the constructor.

    I print them out at the end of the constructor and its all good.

    But then in a subsequent function call to that class I attempt to use these member varriables and their addresses have changed! They're all efed! Even non-pointer vars like a simple int m_i; If i try to print it or use it some where or ANYTHING it crashes the prog. I've printed the addresses and they are definately changed.

    This code worked 100% b4 I put it into a SLL and I havent changed anything about it.

    This is the function call that actually crashes it, here it crashes just after printing "Test: " when it tries to use the int var 'test'
    void AutonomousActionService::processAutonomousActions() {
    LOG->appendActiveLog("Test: ");
    LOG->appendActiveLog( test );
        for( unsigned __int32 i = 0; i < ptrAutonomousElements->size(); ++i ) {
            ptrAutonomousElements->at( i ).ptrAutonomousElement->autonomousAction();
    This is the constructor, the print out of int var 'test' works jsut fine here:
    AutonomousActionService::AutonomousActionService( string strElementID, string strClassName, FrameworkContainer* frameworkContainer ) : Service( strElementID, strClassName, frameworkContainer ) {
        ptrAutonomousElements = new vector<AutonomousElementRegistryEntry>();
        test = 1;
    LOG->appendActiveLog("Test: ");
    LOG->appendActiveLog( test );
    Here is the header for the class:
    class AutonomousActionService : public Service {
        vector<AutonomousElementRegistryEntry> *ptrAutonomousElements;
        int test;
        AutonomousActionService( string strElementID, string strClassName, FrameworkContainer* frameworkContainer );
        void handleEvent( Event event );
        bool registerAsAutonomousElement( string strElementId, IAutonomousElement* ptrElement );
        bool removeAutonomousElement( string strElementId );
        void processAutonomousActions();
    Has any one heard of something like this before?

    Please help

  2. #2
    Join Date
    Jun 2002

    Re: Static Link Lib problems

    >> vector<AutonomousElementRegistryEntry> *ptrAutonomousElements;

    why is this a pointer to a vector? The size of a vector is pretty small, allocating it with new is pretty much waste of time and effort. Just declare an object in the .h file and you will remove the dynamic allocation and problems associated with it.
     vector<AutonomousElementRegistryEntry> AutonomousElements;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)