# \[Bug #3296\] windows $B$G(B iconv.dll $B$N;HMQ$9$k(B MSVC runtime DLL $B$N%P!\<%8%g%s$,!"(Bruby

**URL:** <https://www.ruby-forum.com/t/bug-3296-windows-b-g-b-iconv-dll-b-n-hmq-9-k-b-msvc-runtime-dll-b-n-p-8-g-s-bruby/188610>\
**Category:** Development\
**Created:** [May 14, 2010, 6:25pm UTC](https://www.ruby-forum.com/t/bug-3296-windows-b-g-b-iconv-dll-b-n-hmq-9-k-b-msvc-runtime-dll-b-n-p-8-g-s-bruby/188610 "2010-05-14T18:25:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 14, 2010, 6:25pm UTC](https://www.ruby-forum.com/t/bug-3296-windows-b-g-b-iconv-dll-b-n-hmq-9-k-b-msvc-runtime-dll-b-n-p-8-g-s-bruby/188610/1 "2010-05-14T18:25:14Z")

</div>

Bug #3296: windows e$B$Ge(B iconv.dll e$B$N;HMQ$9$ke(B MSVC runtime DLL  
e$B$N%P!\<%8%g%s$,!"e(Bruby  
e$BK\BN$,;HMQ$9$k$b$N$H0lCW$7$F$$$J$$\>l9g$Ke(B[BUG]e$B$,=P$k!#e(B  
[http://redmine.ruby-lang.org/issues/show/3296](http://redmine.ruby-lang.org/issues/show/3296)

e$B5/I\<\<Te(B: masaya tarui  
e$B%9%F!\<%?%9e(B: Open, e$BM%@hEYe(B: Low  
Target version: 1.9.2  
ruby -v: ruby 1.9.2dev (2010-05-14 revision 27797) [i386-mswin32\_90]

e$BC.2H$G$9!#e(B

e$B%i%s%?%$%`$,0lCW$7$F$$$J$$e(Biconv.dlle$B$r%m!\<%I$9$k4D6-$G!"0J2\<$N%=!\<%9e(B

require ‘iconv’

Iconv.iconv(“utf-8”, “SJIS”, “heh”)  
Iconv.iconv(“utf-8”, “X-UKNOWN”, “heh”)

e$B$r\<B9T$9$k$H!"e(B  
/soft/iconv.rb:4: [BUG] rb\_sys\_fail(iconv(“utf-8”, “X-UKNOWN”)) - errno  
== 0  
e$B$H8@$o$l$^$9!#e(B  
e$B%i%s%?%$%`$,0lCW$7$F$$$J$$\>l9g!"e(Berrnoe$B$r$&$^$/99?7$G$-$J$$$?$a$K!"e(B  
iconve$B$G\<:GT$7$?\>l9g$K!"e(BIconv::BrokenLibrarye$BNc30e(B  
e$B$r=PNO$9$k$N$,@5$7$$$O$:$G$9!#e(B

e$B=j$G!":,K\E\*$K$Oe(Berrnoe$B$,$&$^$/\<h$l$l$P$$$$$?$a!"0J2\<$N$h$&$Je(BPatche$B$r=q$$$F$\_$^$7$?!#e(B  
iconv.dlle$B$G;HMQ$7$F$$$ke(B \_errno()  
e$B$rD4$Y$F$=$l$r;2\>H$9$k$h$&$K$7$^$9!#e(B  
e$B\<h$j9~$\_2DG=$G$7$g$&$+!)e(B

# Index: include/ruby/win32.h

# — include/ruby/win32.h (e$B%j%S%8%g%se(B 27790) +++ include/ruby/win32.h (e$B:n6H%3%T!\<e(B) @@ -274,6 +274,9 @@ extern int fcntl(int, int, …); extern rb\_pid\_t rb\_w32\_getpid(void); extern rb\_pid\_t rb\_w32\_getppid(void); + +extern void \*rb\_w32\_GetImportFunctionPtr(const char \*,const char \*); + #if !defined( **BORLANDC** ) extern int rb\_w32\_isatty(int); #endif Index: win32/win32.c

— win32/win32.c (e$B%j%S%8%g%se(B 27790)  
+++ win32/win32.c (e$B:n6H%3%T!\<e(B)  
@@ -29,6 +29,8 @@  
#include \<share.h\>  
#include \<shlobj.h\>  
#include \<mbstring.h\>  
+#include \<imagehlp.h\>  
+  
#if \_MSC\_VER \>= 1400  
#include \<crtdbg.h\>  
#include \<rtcapi.h\>  
@@ -5641,3 +5643,32 @@

```
 return *ip < 0;

```

}  
#endif  
+  
+void \*  
+rb\_w32\_GetImportFunctionPtr(const char \*modname,const char \*funcname){

- HMODULE hmod;
- ULONG size;
- const IMAGE\_IMPORT\_DESCRIPTOR\* desc;
- hmod = GetModuleHandle(modname);
- if(!hmod)return NULL;
- desc =  
ImageDirectoryEntryToData(hmod,TRUE,IMAGE\_DIRECTORY\_ENTRY\_IMPORT,&size);
- if(!desc)return NULL;
- while(desc-\>Name){
- PIMAGE\_THUNK\_DATA piat,pint;
- PIMAGE\_IMPORT\_BY\_NAME pii;
- pint = (PIMAGE\_THUNK\_DATA)((char \*)hmod + desc-\>Characteristics);
- piat = (PIMAGE\_THUNK\_DATA)((char \*)hmod + desc-\>FirstThunk);
- while(piat-\>u1.Function){
- 

```
 pii = (PIMAGE_IMPORT_BY_NAME)((char *)hmod+ 

```

pint-\>u1.AddressOfData);

- 

```
 if(strcmp(pii->Name,funcname)==0){

```

- return (void \*)piat-\>u1.Function;
- 

```
 }

```

- 

```
 piat++;

```

- 

```
 pint++;

```

- }
- desc++;
- }
- return NULL;  
+}
- 
- 

# Index: win32/Makefile.sub

# — win32/Makefile.sub (e$B%j%S%8%g%se(B 27790) +++ win32/Makefile.sub (e$B:n6H%3%T!\<e(B) @@ -212,7 +212,7 @@ EXTLIBS = !endif !if !defined(LIBS) -LIBS = oldnames.lib user32.lib advapi32.lib shell32.lib ws2\_32.lib $(EXTLIBS) +LIBS = oldnames.lib user32.lib advapi32.lib shell32.lib ws2\_32.lib imagehlp.lib $(EXTLIBS) !endif !if “$(ENABLE\_WIN95)” == “yes” LIBS = unicows.lib $(LIBS) Index: ext/iconv/iconv.c

— ext/iconv/iconv.c (e$B%j%S%8%g%se(B 27790)  
+++ ext/iconv/iconv.c (e$B:n6H%3%T!\<e(B)  
@@ -130,6 +130,14 @@

static VALUE charset\_map;

- 

+#ifdef \_WIN32  
+static int\* (\* \_iconv\_errno)(void);  
+#undef errno  
+#define errno (_\_iconv\_errno())  
+#endif  
+  
+  
/_

- Document-method: charset\_map

- call-seq: Iconv.charset\_map  
@@ -1212,5 +1220,12 @@

- 

+#ifdef \_WIN32

- \_iconv\_errno = rb\_w32\_GetImportFunctionPtr(“iconv.dll”,“\_errno”);
- if(!\_iconv\_errno)
- \_iconv\_errno = \_errno;  
+#endif
- 

}

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 15, 2010, 10:55am UTC](https://www.ruby-forum.com/t/bug-3296-windows-b-g-b-iconv-dll-b-n-hmq-9-k-b-msvc-runtime-dll-b-n-p-8-g-s-bruby/188610/2 "2010-05-15T10:55:07Z")

</div>

e$B$J$+$@$G$9!#e(B

At Sat, 15 May 2010 01:24:56 +0900,  
masaya tarui wrote in [ruby-dev:41317]:

> e$B=j$G!":,K\E\*$K$Oe(Berrnoe$B$,$&$^$/\<h$l$l$P$$$$$?$a!"0J2\<$N$h$&$Je(BPatche$B$r=q$$$F$\_$^$7$?!#e(B  
> iconv.dlle$B$G;HMQ$7$F$$$ke(B \_errno() e$B$rD4$Y$F$=$l$r;2\>H$9$k$h$&$K$7$^$9!#e(B  
> e$B\<h$j9~$\_2DG=$G$7$g$&$+!)e(B

e$B$3$l$@$1$N$?$a$K$=$3$^$G$9$kI,MW$"$k$+$J$!!"$H$$$&$N$,@5D\>$J46A[e(B  
e$B$G$9$,!"$=$l$OCV$$$F$\*$/$K$7$F$b$3$l$@$1$G$O8z2L$,$J$$$H;W$$$^$9!#e(B  
e$B$J$\<$J$i!"e(Biconv.soe$B$+$i8+$($ke(Berrnoe$B$rJQ$($?$H$3$m$Ge(Brb\_sys\_fail()e$B$+e(B  
e$B$i8+$($ke(Berrnoe$B$K$O$^$C$?$/JQ$o$j$,L5$$$+$i$G$9!#e(B

e$B$3$NLdBj$Oe(Biconve$B$K8B$i$J$$$N$G!"$G$-$k$3$H$J$i3HD%%i%$%V%i%j$r$“e(B  
e$B$^$j$$$8$i$:$K\<+F0E\*$K2r7h$G$-$kJ}K!$,$”$k$H$$$$$N$G$9$,!“Cf$K$Oe(B  
e$BJ#?t$N30It%i%$%V%i%j$r%j%s%/$9$k$b$N$b$”$C$?$j$9$k$N$G!"$A$g$C$He(B  
e$BFq$7$=$&$K;W$($^$9!#e(B
