string vs. w/char*

Tyro[a.c.edwards] nospam at home.com
Mon Feb 28 04:34:39 PST 2011


The bellow code attempts to use LoadStringA() to initialize _buf. 
However, regardless of what form _buf takes, the body of the if 
statement is always executed. I've attempted to use every type of string 
available in D to include char* _buf[MAX_RESSTRING+1] and setting 
_buf[MAX_RESSTRING] = '\0'; What am I doing incorrectly?
Any assistance is greatly appreciated.

class ResString
{
   enum { MAX_RESSTRING = 255 }
	
   alias getBuffer this;
   @property string getBuffer() { return _buf; }

   this(HINSTANCE hInst, int resId)
   {
     _buf.length = MAX_RESSTRING;
	
     SetLastError(0);
		
     if(!LoadStringA(hInst, resId, cast(char*)toStringz(_buf), 
_buf.length + 1))
     {
       throw new WinException("Load String failed");
     }
   }

private:
   string _buf;
}


More information about the Digitalmars-d-learn mailing list