拡張ライブラリにリソースを埋め込む

#include <windows.h>
#include "resource.h"

#include "ruby.h"

static HINSTANCE hDll;

static VALUE get_rc(VALUE self) {
  VALUE str;
  HRSRC hRc;
  HGLOBAL hGm;
  LPVOID p;
  long size;

  hRc = FindResourceA(hDll, MAKEINTRESOURCEA(IDR_TEXT1), "TEXT");

  if (hRc == NULL) {
    rb_raise(rb_eStandardError, "FindResourceA()");
  }

  size = SizeofResource(hDll, hRc);

  if (size == 0) {
    FreeResource(hRc);
    rb_raise(rb_eStandardError, "SizeofResource()");
  }

  hGm = LoadResource(hDll, hRc);

  if (hGm == NULL) {
    FreeResource(hRc);
    rb_raise(rb_eStandardError, "LoadResource()");
  }

  p = LockResource(hGm);

  str = rb_str_new(p, size);

  FreeResource(hRc);

  return str;
}

__declspec(dllexport)
void Init_test_rc() {
  VALUE m;
  m = rb_define_module("TestRC");
  rb_define_module_function(m, "rc", get_rc, 0);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
  switch(fdwReason) {
  case DLL_PROCESS_ATTACH:
    hDll = hinstDLL;
    break;
  case DLL_PROCESS_DETACH:
    break;
  case DLL_THREAD_ATTACH:
    break;
  case DLL_THREAD_DETACH:
    break;
  }

  return  TRUE;
}
$KCODE = 's'
require 'test_rc'
include TestRC
puts rc


じゅげむ じゅげむ
続行するには何かキーを押してください . . .

追記
Init_test_rcでリソース読んだ方がいいかも