View Single Post
  #2 (permalink)  
Old July 17th, 2003, 11:38 AM
evanb evanb is offline
Registered User
 
Join Date: Jul 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem is that you are storing pointers to memory over which you have no control in CORBASERVERNAME and CORBAPORTNUMBER. The value received by SET_CORBA_SERVER() points to the contents of a VB string that is probably re/deallocated very soon after the function returns.

You must store a copy of what this function receives. The simplest solution is to change CORBASERVERNAME and CORBAPORTNUMBER to fixed length buffers
char CORBASERVERNAME[xx]; //'xx' and 'yy' are suitably generous sizes
char CORBAPORTNUMBER[yy];
and do
lstrcpyn(CORBASERVERNAME, newPort, sizeof(CORBASERVERNAME) - 1);
in SET_CORBA_SERVER(). (Use lstrcpyn(), not strncpy() for this. lstrcpyn() always null-terminates the string it copies, strncpy() doesn't.)

I also recommend that you declare newPort to be const char* to clarify that it is not written through by SET_CORBA_SERVER(). For a similar reason the return value of GET_CORBA_SERVER() should be const char* too.

-Evan Burkitt
Reply With Quote