Solved

EnumResourceTypes Function & C#

Posted on 2004-03-25
3
825 Views
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:

[DllImport("kernel32")]
private extern static long EnumResourceTypes(long hModule, long lpEnumFunc, long lParam);
[DllImport("kernel32")]
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?
0
Comment
Question by:rossryan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 10684981
See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp09192002.asp
Functions with Callbacks

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

Expert Comment

by:AlexFM
ID: 10685011
Right EnumResourceTypes definition is:

[DllImport("kernel32")]
private extern static long EnumResourceTypes(IntPtr hModule, EnumResTypeProc callback, long lParam);

EnumResourceTypes is your delegate:

delegate bool EnumResourceTypes(
   IntPtr hModule,
   [MarshalAs(UnmanagedType.LPTStr)]
   string lpszType,
   long lParam);
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

632 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