CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 1999
    Posts
    12

    Please its urgent ! How to deal these Global variables

    Hallo Everybody ,
    Thanks for replies on my CString post . I've successfully dealt with
    that problem by u'r help .
    I've copied the path into a character string called PathName which is
    pointer to string . This PathName is nothing but a path to a bitmap
    file .
    I want to use this path in the view class's .CPP file .
    Compilation & Linking is ok . It gives run-time error immediately when
    application is executed .

    Some of the key statements in this ->


    // Global declaration in Type.cpp
    char *PathName;
    .
    .
    .

    // definition in Type.cpp - function handler OnOk()
    PathName = (char*)malloc(100);

    // declaration in Sview.cpp
    extern char *PathName;

    // Usage in SView.cpp
    strcpy(pFile,PathName);


    // error at strcat.asm
    mov eax,dword ptr [ecx] ; read 4 bytes

    // usage of strcat in Type.cpp
    strcpy(PathName,"C:\\abc\\def\\");
    strcat(PathName,FileName); // FileName is char* taken by user

    /* even MessageBox after this was showing correct path in the
    PathName in previous version of program */





  2. #2
    Guest

    Re: Please its urgent ! How to deal these Global variables

    pFile and FileName; what are their declarations?


  3. #3
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Please its urgent ! How to deal these Global variables

    First, to try to find what's wrong with the code, can you guarantee that the malloc() occurs before the use in strcat()? If not, you would end up trying to copy from an undefined area of memory. The malloc appears to only occur if the OK button is clicked, so if the strcat occurs immediately, the PathName pointer is undefined as yet. Perhaps a fuller code sample from these two classes would help us to find the problem.

    Alternatively, why not use a CString to store the string - this can be externed like any normal variable, and maintains its own buffer - this should have no problems. To copy from it, use (const char *)PathName to access it. To put data into it, just use:

    ---

    PathName = "c:\\abc\\def";
    PathName += FileName ; // FileName can be CString, char *
    // or LPSTR, it doesn't matter -
    // they all work.



    ---



    --
    Jason Teagle
    [email protected]

  4. #4
    Join Date
    Apr 1999
    Posts
    12

    Re: Please its urgent ! How to deal these Global variables

    pFile and FileName; what are their declarations?

    ANS

    char *FileName = (char*)malloc(100); // in type.cpp

    char * pFile = (char*)malloc(100); // in sview.cpp



  5. #5
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Please its urgent ! How to deal these Global variables

    I think we need more details to work this one out...
    can you publixh mroe of your code, please?

    Sally


  6. #6
    Join Date
    Apr 1999
    Posts
    12

    Re: my problem is solved

    Hallo friends ,
    My prblem of handling those global variables is solved .

    I used PathName as class member (public) of CType class & pFile as class member (public) of
    CShowdibview class .

    Thanks a lot !

    bye!


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured