EnumResourceTypes Function & C#

Posted on 2004-03-25
Medium Priority
Last Modified: 2012-06-27
Background: trying to grab some resources from a file. Take a look below, I need to know how to setup a callback function:

private extern static long EnumResourceTypes(long hModule, long lpEnumFunc, long lParam);
private extern static long EnumResTypeProc(long hModule, string lpszType, long lParam);

m_hMod = LoadLibraryEx(Filename, 0, LOAD_LIBRARY_AS_DATAFILE);
EnumResourceTypes(hModule, EnumResTypeProc(),0);

What do I need to do to get EnumResourceTypes to call the second variable as a callback function?
Question by:rossryan
  • 3
LVL 48

Expert Comment

ID: 10684981
Functions with Callbacks

You don't need to import EnumResTypeProc. You should write it yourself and pass it's address to EnumResourceTypes.
LVL 48

Expert Comment

ID: 10685011
Right EnumResourceTypes definition is:

private extern static long EnumResourceTypes(IntPtr hModule, EnumResTypeProc callback, long lParam);

EnumResourceTypes is your delegate:

delegate bool EnumResourceTypes(
   IntPtr hModule,
   string lpszType,
   long lParam);
LVL 48

Accepted Solution

AlexFM earned 2000 total points
ID: 10685036
Now write callback function according to delegate type:

bool EnumResourceTypesCallback(IntPtr hModule, string lpszType, long lParam)

And call EnumResourceTypes:

long result = EnumResourceTypes(hModule, new EnumResourceTypes(EnumResourceTypesCallback), lParam);
// (set hModule and lParam to required values).

Inplement required logic in EnumResourceTypesCallback function. Return 0 to stop enumeration, 1 to continue enumeration.

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Watch the video to learn how one can deal with PST file corruption issue with an outstanding Kernel for Outlook PST Repair Tool easily. Using this tool, non-technical users can swiftly perform the repair process to restore their essential data witho…

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question