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 !
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?
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);