Solved

EnumResourceTypes Function & C#

Posted on 2004-03-25
3
788 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
  • 3
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now