Click to See Complete Forum and Search --> : Using Global variable in one pgm into another


vikram deshmukh
May 12th, 1999, 10:36 PM
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 !

May 14th, 1999, 10:32 AM
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?

vikram deshmukh
May 14th, 1999, 10:53 PM
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);

vikram deshmukh
May 17th, 1999, 11:43 AM
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