[Win32utils-devel] Wide strings and LPCTSTR types

win32utils-devel at rubyforge.org win32utils-devel at rubyforge.org
Fri Feb 27 09:55:47 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?

Dan



More information about the win32utils-devel mailing list