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;
}

Reply via email to