зеркало из https://github.com/github/ruby.git
WIN32OLE.codepage= accepts installed codepage.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
75ce70d353
Коммит
3b5dbc4b06
|
@ -1,3 +1,10 @@
|
|||
Sat Jan 20 21:05:18 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||
|
||||
* ext/win32ole/win32ole.c (fole_s_set_code_page): WIN32OLE.codepage=
|
||||
accepts installed codepage.
|
||||
|
||||
* test/win32ole/test_win32ole.rb (test_s_codepage_changed): ditto.
|
||||
|
||||
Sat Jan 20 11:18:49 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||
|
||||
* ext/win32ole/win32ole.c (ole_invoke, ole_invoke2, ole_propertyput):
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <ocidl.h>
|
||||
#include <olectl.h>
|
||||
#include <ole2.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_STDARG_PROTOTYPES
|
||||
#include <stdarg.h>
|
||||
#define va_init_list(a,b) va_start(a,b)
|
||||
|
@ -62,7 +63,7 @@
|
|||
#define OLE_RELEASE_TYPEATTR(X, Y) ((X)->lpVtbl->ReleaseTypeAttr((X), (Y)))
|
||||
|
||||
#define OLE_FREE(x) {\
|
||||
if(gOLEInitialized == Qtrue) {\
|
||||
if(gOLEInitialized == TRUE) {\
|
||||
if(x) {\
|
||||
OLE_RELEASE(x);\
|
||||
(x) = 0;\
|
||||
|
@ -79,13 +80,14 @@
|
|||
|
||||
#define WC2VSTR(x) ole_wc2vstr((x), TRUE)
|
||||
|
||||
#define WIN32OLE_VERSION "0.8.6"
|
||||
#define WIN32OLE_VERSION "0.8.7"
|
||||
|
||||
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
|
||||
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
|
||||
|
||||
typedef HWND (WINAPI FNHTMLHELP)(HWND hwndCaller, LPCSTR pszFile,
|
||||
UINT uCommand, DWORD dwData);
|
||||
typedef BOOL (FNENUMSYSEMCODEPAGES) (CODEPAGE_ENUMPROC, DWORD);
|
||||
typedef struct {
|
||||
struct IEventSinkVtbl * lpVtbl;
|
||||
} IEventSink, *PEVENTSINK;
|
||||
|
@ -152,13 +154,15 @@ VALUE cWIN32OLE_PROPERTY;
|
|||
|
||||
static VALUE ary_ole_event;
|
||||
static ID id_events;
|
||||
static BOOL gOLEInitialized = Qfalse;
|
||||
static BOOL gOLEInitialized = FALSE;
|
||||
static BOOL gCodePageInstalled = FALSE;
|
||||
static HINSTANCE ghhctrl = NULL;
|
||||
static HINSTANCE gole32 = NULL;
|
||||
static FNCOCREATEINSTANCEEX *gCoCreateInstanceEx = NULL;
|
||||
static VALUE com_hash;
|
||||
static IDispatchVtbl com_vtbl;
|
||||
static UINT cWIN32OLE_cp = CP_ACP;
|
||||
static UINT gTarget_cp = CP_ACP;
|
||||
static VARTYPE g_nil_to = VT_ERROR;
|
||||
|
||||
struct oledata {
|
||||
|
@ -583,7 +587,7 @@ void
|
|||
ole_uninitialize()
|
||||
{
|
||||
OleUninitialize();
|
||||
gOLEInitialized = Qfalse;
|
||||
gOLEInitialized = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -591,12 +595,12 @@ ole_initialize()
|
|||
{
|
||||
HRESULT hr;
|
||||
|
||||
if(gOLEInitialized == Qfalse) {
|
||||
if(gOLEInitialized == FALSE) {
|
||||
hr = OleInitialize(NULL);
|
||||
if(FAILED(hr)) {
|
||||
ole_raise(hr, rb_eRuntimeError, "fail: OLE initialize");
|
||||
}
|
||||
gOLEInitialized = Qtrue;
|
||||
gOLEInitialized = TRUE;
|
||||
/*
|
||||
* In some situation, OleUninitialize does not work fine. ;-<
|
||||
*/
|
||||
|
@ -2103,33 +2107,54 @@ fole_s_get_code_page(VALUE self)
|
|||
return INT2FIX(cWIN32OLE_cp);
|
||||
}
|
||||
|
||||
static BOOL CALLBACK
|
||||
installed_code_page_proc(LPTSTR str) {
|
||||
if (atol(str) == gTarget_cp) {
|
||||
gCodePageInstalled = TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
code_page_installed(UINT cp) {
|
||||
gCodePageInstalled = FALSE;
|
||||
gTarget_cp = cp;
|
||||
EnumSystemCodePages(installed_code_page_proc, CP_INSTALLED);
|
||||
return gCodePageInstalled;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* WIN32OLE.codepage = CP
|
||||
*
|
||||
* Sets current codepage.
|
||||
* WIN32OLE.codepage = WIN32OLE::CP_UTF8
|
||||
* WIN32OLE.codepage = 20932
|
||||
*/
|
||||
static VALUE
|
||||
fole_s_set_code_page(VALUE self, VALUE vcp)
|
||||
{
|
||||
UINT cp = FIX2INT(vcp);
|
||||
|
||||
switch(cp) {
|
||||
case CP_ACP:
|
||||
case CP_OEMCP:
|
||||
case CP_MACCP:
|
||||
case CP_THREAD_ACP:
|
||||
case CP_SYMBOL:
|
||||
case CP_UTF7:
|
||||
case CP_UTF8:
|
||||
if (code_page_installed(cp)) {
|
||||
cWIN32OLE_cp = cp;
|
||||
break;
|
||||
default:
|
||||
rb_raise(eWIN32OLE_RUNTIME_ERROR, "codepage should be WIN32OLE::CP_ACP, WIN32OLE::CP_OEMCP, WIN32OLE::CP_MACCP, WIN32OLE::CP_THREAD_ACP, WIN32OLE::CP_SYMBOL, WIN32OLE::CP_UTF7, WIN32OLE::CP_UTF8");
|
||||
break;
|
||||
} else {
|
||||
switch(cp) {
|
||||
case CP_ACP:
|
||||
case CP_OEMCP:
|
||||
case CP_MACCP:
|
||||
case CP_THREAD_ACP:
|
||||
case CP_SYMBOL:
|
||||
case CP_UTF7:
|
||||
case CP_UTF8:
|
||||
cWIN32OLE_cp = cp;
|
||||
break;
|
||||
default:
|
||||
rb_raise(eWIN32OLE_RUNTIME_ERROR, "codepage should be WIN32OLE::CP_ACP, WIN32OLE::CP_OEMCP, WIN32OLE::CP_MACCP, WIN32OLE::CP_THREAD_ACP, WIN32OLE::CP_SYMBOL, WIN32OLE::CP_UTF7, WIN32OLE::CP_UTF8, or installed codepage.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Should this method return old codepage?
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#
|
||||
#
|
||||
|
||||
begin
|
||||
require 'win32ole'
|
||||
|
@ -273,6 +272,22 @@ if defined?(WIN32OLE)
|
|||
str = ifs.read
|
||||
}
|
||||
assert_equal("\343\201", str)
|
||||
|
||||
# This test fail if codepage 20932 (euc) is not installed.
|
||||
begin
|
||||
WIN32OLE.codepage = 20932
|
||||
rescue WIN32OLERuntimeError
|
||||
end
|
||||
if (WIN32OLE.codepage == 20932)
|
||||
file = fso.opentextfile(fname, 2, true)
|
||||
file.write [164, 162].pack("c*")
|
||||
file.close
|
||||
open(fname) {|ifs|
|
||||
str = ifs.read
|
||||
}
|
||||
assert_equal("\202\240", str)
|
||||
end
|
||||
|
||||
ensure
|
||||
WIN32OLE.codepage = WIN32OLE::CP_ACP
|
||||
if (File.exist?(fname))
|
||||
|
|
Загрузка…
Ссылка в новой задаче