Click to See Complete Forum and Search --> : Please its urgent ! How to deal these Global variables


vikram deshmukh
May 14th, 1999, 02:03 AM
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 */

May 14th, 1999, 02:58 AM
pFile and FileName; what are their declarations?

Jason Teagle
May 14th, 1999, 03:38 AM
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.



---

vikram deshmukh
May 14th, 1999, 10:44 PM
pFile and FileName; what are their declarations?

ANS

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

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

sally
May 15th, 1999, 09:45 AM
I think we need more details to work this one out...
can you publixh mroe of your code, please?

Sally

Sally
May 15th, 1999, 09:45 AM
I think we need more details to work this one out...
can you publixh mroe of your code, please?

Sally

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