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

    Using Global variable in one pgm into another

    Hi Gurus ,
    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 */

    Thanks in advance !


  2. #2
    Guest

    Re: Using Global variable in one pgm into another

    What error do you get? I'm guessing some kind of "memory access" error. What is "pFile" defined as? If it is "char* pfile", then possibly your problem is that this is not pointing to a buffer that is long enough.

    Why use malloc as you do in a C++ program?



  3. #3
    Join Date
    Apr 1999
    Posts
    12

    Re: Using Global variable in one pgm into another


    What error do you get? I'm guessing some kind of "memory access" error. What is
    "pFile" defined as? If it is "char* pfile", then possibly your problem is that
    this is not pointing to a buffer that is long enough.

    Why use malloc as you do in a C++ program?


    ANS Yes , Unhandled exception - access violation .
    I'm using malloc to allocate that much number of bytes in advanced .
    Because sometimes in between execution there might not be enough memory to handle
    this string .
    char *pFile = (char*)malloc(100);




  4. #4
    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 ,
    vikram


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