[Win32utils-devel] Wide strings and LPCTSTR types

win32utils-devel at rubyforge.org win32utils-devel at rubyforge.org
Sat Feb 28 09:01:57 EST 2004



> > > I tried this:
> > >
> > > LPCTSTR AllocWideLPCString(VALUE rbString){
> > >    char* szText = STR2CSTR(rbString);
> > >    int nLen = (strlen(szText) + 1) * sizeof(LPCTSTR);
> > should be
> >      int nLen = (strlen(szText) + 1) * sizeof(WCHAR);
>
> I tried both actually.  Didn't make any difference.  For testing, I'm
> using the Eventlog.backup method.
>
> in eventlog_backup:
>
> // original - this works
> lpBackupFileName = (LPCTSTR)STR2CSTR(rbFile);
>
> // proposed - this doesn't work
> lpBackupFileName = AllocWideLPCString(rbFile);
>
> I tried this simple test script:
>
> # test_backup.rb
> require "ftools"
> require "win32/eventlog"
> include Win32
>
> backup_file = "C:\\event_backup2"
> File.delete(backup_file) if File.exists?(backup_file)
>
> e2 = EventLog.open("Application")
> e2.backup(backup_file)
> e2.close
>
> test_backup.rb:20:in `backup': BackupEventLog() call failed: Cannot
> create a file when that file already exists. (Win32::EventLogError)
>         from test_backup.rb:20
>
> If I use the old code, it works fine.  What gives?
>
I mean you should use AllocWideLPCString when api require unicode string.
You don't need to use AllocWideLPCString  if it works without it. :)

Regards,

Park Heesob




More information about the win32utils-devel mailing list