0

We are contemplating changing from PCRE regular expressions to ICU regular expressions to take advantage of ICU's UTF-8 Unicode regular expressions. We have wriiten a test program to load the ICU pnames.icu file which is necessary to compile and exercise the ICU UTF-8 Regular expressions which appears to be functioning correctly. Is it possible to store the contents of pnames.icu in a Windows DLL global variable in order to avoid shipping the ICU pnames.icu to users? Thank you.

Frank
  • 1,406
  • 2
  • 16
  • 42
  • Yes. One way is to stuff them in the app's resources and use find/load resource to load them – Captain Obvlious Jun 11 '12 at 20:43
  • @Captain Oblivious, Which WinAPI functions should we use to read the contents of pnames.icu and stuff them in the app's resources? Thank you for your suggestion. – Frank Jun 11 '12 at 20:47
  • 1
    Hi Captain && All, We googled and found this Stack Overflow article. http://stackoverflow.com/questions/2933295/embed-text-file-in-a-resource-in-a-native-windows-application------Embed Text File in a Resource in a native Windows Application. Would it be applicable to pnames.icu? Thank you – Frank Jun 11 '12 at 21:58
  • Yes. The information in that post definitely applies. – Captain Obvlious Jun 11 '12 at 22:08

1 Answers1

1

You start by adding the files to the resource script in the same way you do an icon. The difference is you will specify the resource by name instead of an integer value and tell the resource compiler that the files are a custom resource type called "ICU"

pname1      ICU     "pname1.icu"
pname2      ICU     "pname2.icu"
pname3      ICU     "pname3.icu"

To load the resource you will first need to find it by name and by the type (in this case ICU). Once you have found it you can tell windows to load the resource data and then "lock" it to obtain a pointer to it.

//  Find the resource
HRSRC hRes = FindResource(NULL, L"pname1", L"ICU");

//  Load the resource 
HGLOBAL hResLoad = LoadResource(NULL, hRes);

void* icuData = LockResource(hResLoad);

// ... do something with the resource @ icuData


//  We're done so let it go.
UnlockResource(icuData);
Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74
  • CAPTAIN Oblivious, I just accepted your Stack Overflow answer. If we do the same thing on Solaris UNIX, how might we proceed? Thank you for your help. – Frank Jun 11 '12 at 22:49
  • @Frank Not sure what to recommend for Solaris. It's not likely to be a built in feature though. You might want to look at a simple resource packager. – Captain Obvlious Jun 12 '12 at 00:29
  • CAPTAIN Oblivious, We googled some more and found this Stack Overflow article about how to embed a file in gcc executable library. However, it says nothing about Solarix UNIX. Thank you for your help. http://stackoverflow.com/questions/4864866/c-c-with-gcc-statically-add-resource-files-to-executable-library – Frank Jun 12 '12 at 01:10
  • @Frank: GCC is a compiler; Oracle Solaris UNIX is an operating system. The two are not at odds; GCC can compile Solaris executables. – MSalters Jun 12 '12 at 10:40
  • @MSalters, Thank you for your advice on Oracle Solaris. On Windows XP Professional , we are getting a NULL pointer from HRSRC hRes = FindResource(NULL, L"pname1", L"ICU"). In addition, when we call GetModuleHandle(DLLFullyQualifiedPath) we get GetErrorCodes 126 or 2. Have you encoutered this problem before. Thank you. – Frank Jun 12 '12 at 11:27
  • @Frank: Use a tool like [Resource Hacker](http://en.wikipedia.org/wiki/Resource_Hacker) to check if the `pname1` reosurce was succesfully added. Note that `FindResource(NULL` checks the .EXE; you need a valid handle from `GetModuleHandle(DLLPath)` to load a resource from a DLL. – MSalters Jun 12 '12 at 11:38
  • @Msalters, We fixed the pname1 resource problem by following your advice. However. when we call HMODULE handle = GetModuleHandle(TEXT("C:\\WINDOWS\\system32\\mdRightFielder.dll"));, we GetLastError() of 126 still. We were wondering if our pathname argument is correctly formatted. THank you for your advice. – Frank Jun 12 '12 at 11:56
  • @Frank: The path looks like a bad choice, but well-formatted. Have you checked the actual directory? (* _It's a bad choice because your DLL is not a Microsoft DLL shipped as part of Windows; use_ \Program Files\ _instead._ *) – MSalters Jun 12 '12 at 13:03
  • @MSalters, Thank you for your help on the the path issue, – Frank Jun 12 '12 at 13:49
  • CAPTAIN Oblivious, I just applied your code to read and store the contents of ICU UNICODE regex pnames.icu in a global variable. Thank you. – Frank Jun 12 '12 at 14:31